I imagine the workflow as synonymous.
I tried a lot in Mach4, also coroutines. But it does not work either.
This is the M6 Lua macro of Mach4 v3481 in the Profile folder:
--[[function m6()
local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
mc.mcCntlSetLastError(inst, "M06 Lua makro")
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
--mc.mcCntlGcodeExecute(inst, "G59\nG00 Z0\nG00 X0 Y48");--Move the Z axis all the way up
--mc.mcCntlFeedHold(inst);
mc.mcCntlToolChangeManual(inst, true);
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. " Previous Tool == " .. tostring(currenttool))
mc.mcToolSetCurrent(inst, selectedtool)
end
end
if (mc.mcInEditor() == 1) then
m6()
end]]
As soon as mc.mcCntlToolChangeManual(inst, true); is called, Mach4 is in a waiting loop. Execute MDI or gcode do not work (not allowed).
I developed my own solution.
If M6 is called then M00 (program stop) is executed and Output 1 is set to on. Then i change the tool and press the Cycle Start Button. The Output 1 is set to off and gcode will be processed further.
Here is my M6 Macro Code:
function m6()
local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
--if selectedtool == currenttool then
--mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
--else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
--mc.mcCntlSetLastError(inst, "m6()");
local signal = mc.OSIG_OUTPUT1;
--local signalToolchange = mc.OSIG_TOOL_CHANGE;
local hSig = mc.mcSignalGetHandle(inst, signal);
local state = mc.mcSignalGetState(hSig);
local stateToolchange = mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.OSIG_TOOL_CHANGE));
mc.mcCntlSetLastError(inst, "m6(): mc.OSIG_OUTPUT1 state"..tostring(state));
mc.mcCntlSetLastError(inst, "m6(): mc.OSIG_TOOL_CHANGE state"..tostring(stateToolchange));
if state == 0 then
mc.mcCntlSetLastError(inst, "m6(): Tool change active");
mc.mcCntlGcodeExecute(inst, "M00");
mc.mcSignalSetState(hSig, true);
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. " Previous Tool == " .. tostring(currenttool))
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcSignalSetState(hSig, false);
mc.mcCntlSetLastError(inst, "m6(): Tool change inactive");
--mc.mcCntlSetLastError(inst, "m6(): mcCntlToolChangeManual");
--mc.mcCntlToolChangeManual(inst, true);
end;
--end
end
if (mc.mcInEditor() == 1) then
m6()
end
There is still a problem. If press the Stop, Reset, etc. Button during the tool change (Output 1 on), the Output 1 will not be reseted. I will try to find a solution.