--Hurco Tool Change Macro function m6() local inst = mc.mcGetInstance() local Requested = mc.mcToolGetSelected(inst) local Current = mc.mcToolGetCurrent(inst) local ToolChangeStart = mc.mcSignalGetHandle (inst,mc.OSIG_OUTPUT2) local Orient = mc.mcSignalGetHandle (inst,mc.OSIG_OUTPUT14) local tonumber ToolNum = Requested local Pocket = mc.mcToolGetData (inst, mc.MTOOL_MILL_POCKET, ToolNum) local DS2 = mc.mcRegGetHandle(inst,"Click/Requested Car Pos") mc.mcRegSetValue(DS2,Pocket) if Requested == Current then mc.mcCntlSetLastError(inst, "Current tool == Requested tool so there is nothing to do") else --Move Z axis up. --mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0") mc.mcCntlGcodeExecute (inst, "M5")--Wait for spindle to stop. mc.mcSignalWait(inst, mc.ISIG_INPUT20, mc.WAIT_MODE_HIGH, 0) -- wx.wxMilliSleep(1500) mc.mcCntlSetLastError(inst, "Spindle stopped.") --Spindle Orient mc.mcCntlGcodeExecuteWait (inst, "S60") mc.mcCntlGcodeExecute (inst, "M3") mc.mcSignalSetState(Orient,1) mc.mcCntlSetLastError(inst, "Spindle orienation in process.") mc.mcSignalWait(inst, mc.ISIG_INPUT17, mc.WAIT_MODE_HIGH, 0) mc.mcCntlGcodeExecute (inst, "M5") mc.mcCntlSetLastError(inst, "Spindle orienation complete.") mc.mcSignalSetState(Orient,0) -- mc.mcCntlToolChangeManual(inst, false); --Send signal to the Click to start the tool change. mc.mcSignalSetState(ToolChangeStart,1) wx.wxMilliSleep(1000) mc.mcSignalSetState(ToolChangeStart,0) --Wait for the signal from the CLick. (Orient Release Signal) mc.mcSignalWait(inst, mc.ISIG_INPUT19, mc.WAIT_MODE_HIGH, 0) mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(Requested)) mc.mcToolSetData(inst, mc.MTOOL_MILL_POCKET, Current, Pocket) mc.mcToolSetCurrent(inst, Requested) end mc.mcCntlSetLastError(inst, "Tool Change Complete.") end --m6 if (mc.mcInEditor() == 1) then m6() end