Hello Guest it is December 13, 2019, 03:47:25 PM

Author Topic: Macro works in MDI but not during program execution  (Read 627 times)

0 Members and 1 Guest are viewing this topic.

Macro works in MDI but not during program execution
« on: May 06, 2018, 09:09:28 PM »
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.

Code: [Select]
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

Re: Macro works in MDI but not during program execution
« Reply #1 on: May 07, 2018, 07:36:40 AM »
Hi,

these are the return codes for mcSignalWait():

Quote
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_INVALID_ARG sigId or wiatMode is out of range or timeoutSecs is negative.
MERROR_NOT_ENABLED The control is not enabled.
MERROR_TIMED_OUT The timeout period was reached without a change of state.

Your code tests for MERROR_TIMED_OUT but what about the others? I've had trouble with this API as well because I didn't appreciate that ther are circumstances when an unexpected
return code is generated. Without some means of catching it it will screw up the logic of your script.

Could the return codes be put in a table?

Craig
My wife left with my best friend...
     and I miss him!
Re: Macro works in MDI but not during program execution
« Reply #2 on: May 07, 2018, 09:09:13 AM »
Is it possible for an error here to cause it to not run the two lines before mcSignalWait()? 
I will start testing for more error codes tonight, possibly mcSignalGetHandle and mcSignalSetState as well.
Re: Macro works in MDI but not during program execution
« Reply #3 on: May 08, 2018, 12:56:51 PM »
After scrutinizing the macro line by line, adding error catches, loops, alarms, etc, I figured out it wasn't the macro at all.  One little contact, placed in the plc logic by me several months ago while I was experimenting with something else finally tripped me up.  It was working in MDI mode, but apparently just barely.
Thanks for the help though.