31
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 27, 2016, 02:36:03 PM »
Well a gave it a go as and I get a lua error in the macro "Error while running chunk" it doesn't seem to want to run my function (GrindCycle) in the Screenload script from within the Macro(M100)?
Here is what I have now:
Add to the ScreenLoad script:
In the M100 macro:
Added to the PLC script:
Here is what I have now:
Add to the ScreenLoad script:
Code: [Select]
--My GrindCycle function starts here:
function GrindCycle()
local inst = mc.mcGetInstance()
local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
if input_20 == 0 then
wx.wxMessageBox("Could not locate signal!")
else
if input_20_State == 1 then --If input_20_State equals 1, then grind cycle active signal is High.
wx.wxMessageBox("Signal is already active!")
else --If input_20_State does not equal 1, then the grind cycle signal is inactive.
mc.mcSignalSetState(input_20, 1) -- set grind cycle signal active
mc.mcSignalWait(inst, z_home_sig, WAIT_MODE_HIGH, 20) -- wait for z to get home
coroutine.yield () --yield coroutine so we can do the following after motion stops
wx.wxMessageBox("Grind Cycle Complete")
end
end
end
--My GrindCycle function ends here:
In the M100 macro:
Code: [Select]
function M100()
wait = coroutine.create (GrindCycle) --Run the GrindCycle function as a coroutine named wait.
end
if (mc.mcInEditor() == 1) then
M100()
end
Added to the PLC script:
Code: [Select]
-------------------------------------------------------
-- Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait) --Get the status of the coroutine named wait
if state == "suspended" then --Coroutine named wait is suspended
coroutine.resume(wait) --Resume coroutine named wait
end
end