Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: brianthechemist on January 11, 2025, 03:37:08 PM
-
OK, I've spent an embarrasingly long time scratching my head on this one. I'm mapping some physical buttons to Gcode start/Feed hold and Stop. The buttons work fine, however for some reason I am unable to get the following code to switch between cycle start and feed hold.
I have tried a couple of different signals to indicate that gcode is running, neither mc.mcCntlIsInCycle nor mc.OSIG_RUNNUNG_GCODE work.
[mc.ISIG_INPUT8] = function (state) -- Console Start/Feed Hold button
local inst = mc.mcGetInstance()
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_RUNNING_GCODE);
local holdState = mc.mcSignalGetState(sigh);
if (state == 1) then
if (holdState == TRUE) then
wx.wxMessageBox('This feed had better be held!');
mc.mcCntlFeedHold (inst)
else
CycleStart()
end
end
end,
I'm clearly missing something obvious
-
Change TRUE to lowercase true
-
I started there actually :( i also tried == 1
-
Technically, if the file is running, then OSIG_RUNNING_GCODE will always be high. The file is still running however it is running at zero velocity. I would use mc.mcCntlGetState() with mc.MC_STATE_FRUN_FH and mc.MC_STATE_MRUN_FH (File Feed Hold and MDI Feed hold states).
[mc.ISIG_INPUT8] = function (state) -- Console Start/Feed Hold button
local inst = mc.mcGetInstance()
local mstate = mc.mcCntlGetState(inst)
if (state == 1) then
if (mstate == mc.MC_STATE_FRUN_FH) or (mstate == mc.MC_STATE_MRUN_FH) then
-- We are in the feed hold state, so do Cycle Start()
CycleStart()
elseif (mstate == mc.MC_STATE_FRUN) or (mstate == mc.MC_STATE_FRUN) then
-- The file or MDI is running.
wx.wxMessageBox('This feed had better be held!') -- I don't like message boxes because they are modal. I much prefer mc.mcCntlSetLastError().
mc.mcCntlFeedHold(inst)
end
end
end,
Steve
-
This could be done in the PMC for a solution with less "programming".
-
Nice! I will check it out. Believe it or not, ladder logic escapes me but i can understand Lua (except for these machine-specific idiosyncrasies)
Thanks!
-
All is working. I thought I would post my final code snippet in case anyone wants it in the future.
This snippet fixes my issue and builds a bit on what we discussed. In the end, I needed the button to start the gcode/mdi initially and work like a play/pause button after it had started running. (The button on my console is labeled "START/Feed hold")
[mc.ISIG_INPUT8] = function (state) -- Console Start/Feed Hold button
local inst = mc.mcGetInstance()
local mstate = mc.mcCntlGetState(inst)
if (state == 1) then
if (mstate == mc.MC_STATE_FRUN) or (mstate == mc.MC_STATE_MRUN) then --if either gcode or macro is running
mc.mcCntlFeedHold (inst) --execute feed hold
elseif (mstate == mc.MC_STATE_FRUN_FH) or (mstate == mc.MC_STATE_MRUN_FH) then --otherwise if in feed hold
-- -- We are in the feed hold state, so do Cycle Start()
CycleStart()
else -- and if the code is not running at all yet...
CycleStart()
end
end
end,
-
Thank you for doing the
leg work !
Need this exact code for the mill I'm building.
So thank you much!
-
Happy i could help. My machine would not have been possible without the help on this board. I know how seemingly small things can turn into huge black holes of time! Haha