This toolchange macro used to work fine in both MDI and when called from a program, now for some reason it is skipping the "loosendraw" lines - and only during program execution. It works fine when called from MDI.
The lines it is skipping are
--LOOSEN DRAWBAR
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 1)
rc=mc.mcSignalWait(inst, mc.ISIG_INPUT19,mc.WAIT_MODE_HIGH, 5.);
if (rc==mc.MERROR_TIMED_OUT) then
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 0)
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 0)
mc.mcCntlSetLastError(inst, "LOOSEN DRAWBAR TIMED OUT")
mc.mcCntlFeedHold(inst)
mc.mcCntlCycleStop(inst)
do return end
end
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 0)
I hope someone can help, I am beyond frustrated right now.
function m6()
local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
--local selectedtool = 2
--local currenttool = 1
local spindleorient = mc.OSIG_OUTPUT2
local spindleoriented=mc.ISIG_INPUT18
local loosendraw = mc.OSIG_OUTPUT3
local drawloose = mc.ISIG_INPUT19
local tightendraw = mc.OSIG_OUTPUT4
local drawtight = mc.ISIG_INPUT20
local shuttleout = mc.OSIG_OUTPUT5
local xoffset = -29.7469
local yoffset = -14.2502
local zoffset = -22.30
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "Current tool == Selected"..selectedtool)
else
--SHUTTLE IN
hsig, rc=mc.mcSignalGetHandle(inst, shuttleout)
mc.mcSignalSetState(hsig, 0)
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 1)
mc.mcCntlGcodeExecuteWait(inst, "G0 G53 Z-14.")
if currenttool == 0 then
else
mc.mcCntlGcodeExecuteWait(inst, "G53 X"..xoffset+2.5+currenttool*5-5. .. " Y"..yoffset-2.5)
--mc.mcCntlGcodeExecuteWait(inst,"G53 Y"..yoffset-2.5)
mc.mcCntlGcodeExecuteWait(inst, "G53 Z"..zoffset+3.)
end
hsig, rc=mc.mcSignalGetHandle(inst, spindleoriented)
orient =mc.mcSignalGetState(hsig)
while orient do
orient =mc.mcSignalGetState(hsig)
if orient == 1 then break end
end
--if currenttool > 0 then
mc.mcCntlGcodeExecuteWait(inst," F100.")
mc.mcCntlGcodeExecuteWait(inst, "G53 G1 Z"..zoffset)
--LOOSEN DRAWBAR
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 1)
rc=mc.mcSignalWait(inst, mc.ISIG_INPUT19,mc.WAIT_MODE_HIGH, 5.);
if (rc==mc.MERROR_TIMED_OUT) then
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 0)
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 0)
mc.mcCntlSetLastError(inst, "LOOSEN DRAWBAR TIMED OUT")
mc.mcCntlFeedHold(inst)
mc.mcCntlCycleStop(inst)
do return end
end
hsig, rc=mc.mcSignalGetHandle(inst, loosendraw)
mc.mcSignalSetState(hsig, 0)
--end
--MOVE UP
mc.mcCntlGcodeExecuteWait(inst, "G0 G53 Z"..zoffset+4.)
if selectedtool == 0 then
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 0)
mc.mcToolSetCurrent(inst, selectedtool)
hsig, rc=mc.mcSignalGetHandle(inst, shuttleout)
mc.mcSignalSetState(hsig, 1)
do return end
end
mc.mcCntlGcodeExecuteWait(inst, "G53 X"..xoffset+2.5+(selectedtool*5)-5. .. " Y"..yoffset-2.5)
mc.mcCntlGcodeExecuteWait(inst, "G53 Z"..zoffset+1.5)
mc.mcCntlGcodeExecuteWait(inst, "G53 G1 Z"..zoffset)
--TIGHTEN DRAWBAR
hsig, rc=mc.mcSignalGetHandle(inst, tightendraw)
mc.mcSignalSetState(hsig, 1)
rc=mc.mcSignalWait(inst, mc.ISIG_INPUT20,mc.WAIT_MODE_HIGH, 5.);
if (rc==mc.MERROR_TIMED_OUT) then
hsig, rc=mc.mcSignalGetHandle(inst, tightendraw)
mc.mcSignalSetState(hsig, 0)
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 0)
mc.mcCntlSetLastError(inst, "DRAWBAR TIGHTEN TIMED OUT")
mc.mcCntlFeedHold(inst)
mc.mcCntlCycleStop(inst)
do return end
end
hsig, rc=mc.mcSignalGetHandle(inst, tightendraw)
mc.mcSignalSetState(hsig, 0)
mc.mcCntlGcodeExecuteWait(inst, "G53 G0 Z-14.")
hsig, rc=mc.mcSignalGetHandle(inst, spindleorient)
mc.mcSignalSetState(hsig, 0)
mc.mcToolSetCurrent(inst, selectedtool)
end
--SHUTTLE OUT
hsig, rc=mc.mcSignalGetHandle(inst, shuttleout)
mc.mcSignalSetState(hsig, 1)
end
if (mc.mcInEditor() == 1) then
m6()
end