Weird setup but it works. It requires some setup... so be prepared.
We make our PLC handle all the flashing, but I figured out how to let Mach4 handle it all internally.
This example will make the Yellow Light flash when the code reaches the end and reads M30. (Adjust as you see fit.)
This requires you to make a register: Go to Config --> Plugins --> and make a new register called Timer.
This also uses Output 30 as an M30 output. So you will need to create an m30 macro as well.
Here is the code for it: Create a new macro m30 (save it in Mach4Folder --> Profiles --> YOUR PROFILE --> Macros --> m30.mcs)
function m30()
local inst = mc.mcGetInstance()
local M30Output = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT30)
local Coolant = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON)
mc.mcSpindleSetDirection(inst, 0)
mc.mcSignalSetState(M30Output, 1)
mc.mcSignalSetState(Coolant, 0)
mc.mcCntlMdiExecute(inst, "G40")
end --m30()
if (mc.mcInEditor() == 1) then
m30()
end
Next you will need a way to turn of the m30 output (output 30). I handle this by pressing the Reset button or by hitting cycle start.
Change the script on your reset button on your screen to this: Reset()
Next in the screen load script make a new Reset Function. Here is the code for it: Add it anywhere after the SigLib()
---------------------------------------------------------------
--Reset Function
function Reset()
local inst = mc.mcGetInstance()
local M30Output = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT30)
local M30Flasher = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
mc.mcSignalSetState(M30Output, 0)
mc.mcSignalSetState(M30Flasher, 0)
mc.mcCntlReset(inst)
mc.mcSpindleSetDirection(inst, 0)
mc.mcCntlSetLastError(inst, '')
end--Reset()
---------------------------------------------------------------
Next replace your CycleStart() Function with this
---------------------------------------------------------------
-- Cycle Start() function.
---------------------------------------------------------------
function CycleStart()
local rc
local tab, rc = scr.GetProperty("MainTabs", "Current Tab")
local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab")
local state = mc.mcCntlGetState(inst)
local M30Output = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT30)
local M30Flasher = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
if (state == mc.MC_STATE_MRUN_MACROH) then
mc.mcCntlCycleStart(inst)
mc.mcSignalSetState(M30Output, 0)
mc.mcSignalSetState(M30Flasher, 0)
elseif ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1)) then
scr.ExecMdi('mdi1')
mc.mcSignalSetState(M30Output, 0)
mc.mcSignalSetState(M30Flasher, 0)
elseif ((tonumber(tab) == 5 and tonumber(tabG_Mditwo) == 1)) then
scr.ExecMdi('mdi2')
mc.mcSignalSetState(M30Output, 0)
mc.mcSignalSetState(M30Flasher, 0)
else
mc.mcCntlCycleStart(inst)
mc.mcSignalSetState(M30Output, 0)
mc.mcSignalSetState(M30Flasher, 0)
end
end--CycleStart()
-------------------------------------------------------
Finally, add this to the end of your PLC Script (But above the section that says "this is the last thing we do".
--Custom Scripts
--Blink when m30 is on.
local inst = mc.mcGetInstance()
local M30Output = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT30)
local FlashingLight = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local M30OutputState = mc.mcSignalGetState(M30Output)
local FlashingLightState = mc.mcSignalGetState(FlashingLight)
if M30OutputState == 1 then
local TimerReg = mc.mcRegGetHandle(inst,"iRegs0/Timer")
local TimerVal = mc.mcRegGetValue(TimerReg)
mc.mcRegSetValue(TimerReg, (TimerVal + 1))
if TimerVal >= 50 then --Adjust the number for flashing frequency
if FlashingLightState == 0 then
mc.mcSignalSetState(FlashingLight, 1)
else
mc.mcSignalSetState(FlashingLight, 0)
end
mc.mcRegSetValue(TimerReg, 0)
end--Timer >= Number
end--M30Output == 1