Hello Guest it is April 26, 2024, 12:11:50 PM

Author Topic: Getting an output to blink? (Lathe Tool Change indicator)  (Read 797 times)

0 Members and 1 Guest are viewing this topic.

Getting an output to blink? (Lathe Tool Change indicator)
« on: June 28, 2021, 10:36:09 AM »
I have built a manual control panel for my lathe with some LED outputs.

When I do a tool change, the portion of the screen set that displays the current tool and offset has a "virtual light" that "blinks" as in indicator that the tool must be changed, with "Cycle Start" acting as the acknowledgement.

What I would like to happen is for the Feed Hold LED on my panel to blink too.

As I doubt there is a blink() command in the API, what I probably need to do is find where the script in the screen set lives that responds to tool changes, and insert into the loop that it uses to "blink" the screen graphic, have it flip the light output as well.

Where does that script live? Anybody know?

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Getting an output to blink? (Lathe Tool Change indicator)
« Reply #1 on: June 28, 2021, 12:05:16 PM »
You might experiment with mc.OSIG_TOOL_CHANGE. I think that output signal is active during an M6, which using the signal library could start a continuous timer to blink the LED on your panel.
Re: Getting an output to blink? (Lathe Tool Change indicator)
« Reply #2 on: June 29, 2021, 09:36:04 AM »
Looking at the screen last night, it turns out that the "virtual LED" has a BLINK type and just looks at the tool change signal. So no script I can easily patch in the light.

I can pretty easily turn a light ON (or off) using the signal library, but it won't get called again unless the signal state changes - so I guess this has to live in the PLC script.

The second problem is that I have the light I want to blink attached to the built-in FEED HOLD signal, not a numbered output. How can I reach it through the API? Is that even possible?
Re: Getting an output to blink? (Lathe Tool Change indicator)
« Reply #3 on: June 29, 2021, 02:36:56 PM »
I have written this example below which will blink output 5 when the tool change output is active as suggested by jbuehn. This should automatically turn on when running M6. Instead of using the feed hold output for your LED, I think it is better to map it to a normal output so that we are not overriding the state of the feed hold output which is controlled by Mach when going into/coming out of feed hold.

Drop this code into your screen load script. It is the timer that will 'blink' the output. Remember to change the output number where stated (currently set to output 5)

Code: [Select]
FeedHoldTimerPanel = wx.wxPanel (wx.NULL, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxSize( 0,0 ) )
FeedHoldTimer = wx.wxTimer(FeedHoldTimerPanel)
FeedHoldTimerPanel:Connect(wx.wxEVT_TIMER,
function (event)
    local inst = mc.mcGetInstance()
local hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5) --SET OUTPUT NUMBER
local sSig = mc.mcSignalGetState(hSig)
if sSig == mc.MC_ON then
mc.mcSignalSetState(hSig, mc.MC_OFF)
else
mc.mcSignalSetState(hSig, mc.MC_ON)
end
end)

Put this into your signal library. Remember to change the output number where stated (currently set to output 5)

Code: [Select]
[mc.OSIG_FEEDHOLD] = function (state)
--Use mach controlled feed hold output to activate the feed hold LED
local inst = mc.mcGetInstance()     
local hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5) --SET OUTPUT NUMBER
    if( state == 1) then
mc.mcSignalSetState(hSig, mc.MC_ON)
else
mc.mcSignalSetState(hSig, mc.MC_OFF)
    end
end,

[mc.OSIG_TOOL_CHANGE] = function (state)
    local inst = mc.mcGetInstance()   
    if( state == 1) then
--Start timer to flash feed hold LED 500ms interval
        FeedHoldTimer:Start(500, false)
else
--Stop timer and turn off feed hold LED in case it's still on.
FeedHoldTimer:Stop()
local hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5) --SET OUTPUT NUMBER
mc.mcSignalSetState(hSig, mc.MC_OFF)
    end
end
Re: Getting an output to blink? (Lathe Tool Change indicator)
« Reply #4 on: June 29, 2021, 07:49:31 PM »
I see what you've done with the signal library.

Clever.

Thanks!
Re: Getting an output to blink? (Lathe Tool Change indicator)
« Reply #5 on: July 02, 2021, 01:32:54 PM »
This worked!

Thanks!