Here is the code I'm using on a lathe at work.
This bit of code is the mc.mcSignalWait.
I have it waiting 20 seconds, that's about 4 times as long as it takes to change a tool. If it doesn't finish in that time, I want to shut the motor off on the tool changer so it doesn't burn up. So, if rc does not equal 0 (which is no error) then message, error, stop my functions.
--Wait for the signal from the CLick.
mc.mcCntlSetLastError(inst, "Wait for Click to complete tool change.")
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT0, mc.WAIT_MODE_HIGH, 20)--Time in seconds the Click has to complete the tool change.
--Error check. If the Click took too long. Alarm out Mach4.
if (rc~= 0) then
wx.wxMessageBox("The Click did not complete the tool change in time. Check for malfunction.")
local Alarm = mc.mcSignalGetHandle(inst,mc.OSIG_ALARM)
mc.mcSignalSetState(Alarm,1)
mc.mcSignalSetState(TurretMotor, 0)
CycleStop()
else
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(Requested))
mc.mcToolSetCurrent(inst, Requested)
mc.mcCntlSetLastError(inst, "Tool Change Complete.")
end
NOTE: This is just the middle of the code, I have more code above that gets the instance, sets output handles, etc... and more at the end to complete the tool change.