5368
« on: February 06, 2018, 03:57:32 AM »
Hi Dany,
have tightened up on the code. Have included a loop that retries the GcodeExecuteWait() call to a maximum of five times. My testing has shown that its now
reasonably robust. Its time for you to put it into action and see how it performs in the real world.
function OfflineButton()
local inst=mc.mcGetInstance()
local hsigenable=mc.mcSignalGetHandle(inst,mc.OSIG_ENABLE0)
local hsigbuttonstate=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT2)
if (mc.mcCntlGetState(inst) ~=0)then mc.mcCntlCycleStop(inst)end
if (mc.mcSignalGetState(hsigenable)==1) then
if (mc.mcSignalGetState(hsigbuttonstate)==1) then
-- Mach is enabled and the servos are 'online'
-- Need to save current position and set servos 'offline'
local Xpos=mc.mcAxisGetMachinePos(inst,mc.X_AXIS)
local Zpos=mc.mcAxisGetMachinePos(inst,mc.Z_AXIS)
mc.mcCntlSetPoundVar(inst,500,Xpos)
mc.mcCntlSetPoundVar(inst,501,Zpos)
mc.mcSignalSetState(hsigbuttonstate,0)
else
--Mach enabled but servos 'offline'
--Need to restore current position and reset servos 'online'
local Xpos=mc.mcCntlGetPoundVar(inst,500)
local Zpos=mc.mcCntlGetPoundVar(inst,501)
local rc=1
local iter=0
repeat
rc=mc.mcCntlGcodeExecuteWait(inst,'g53 g0 x'..Xpos..' z'..Zpos)
iter=iter+1
if iter >=5 then wx.wxMessageBox('GcodeExecuteWait() Failed') break end
if rc~=0 then mc.mcCntlEnable(inst,0) mc.mcCntlEnable(inst,1) end
until (rc==0 )
if (rc==0) then mc.mcSignalSetState(hsigbuttonstate,1) end
end
else
--Mach disabled....do nothing
end
end
if ( mc.mcInEditor()==1) then
OfflineButton()
end
Craig