--Hurco Tool Change. Carousel Positions Testing --The Click can monitor these registers using DS#. --Setup Modbus: Write Single Register. Register = 1,2,3,Etc... will corrispond with DS1, DS2, etc... --Example of getting and setting registers --local ClickReg1 =mc.mcRegGetHandle(inst,"Click/Click Register 1") --mc.mcRegSetValue(ClickReg1,0) function m6000() --Hurco Tool Change Draft local inst = mc.mcGetInstance() local Current = mc.mcToolGetCurrent(inst) local RequestedTool = mc.mcToolGetSelected(inst) local CarouselPositionVal = mc.mcRegGetValueString (mc.mcRegGetHandle(inst,"Click/Carousel Position")) CarouselPosition = tonumber(CarouselPositionVal) local PositionToSendPLC = mc.mcRegGetHandle(inst,"Click/Requested Car Pos") --if RequestedTool == Current then -- mc.mcCntlSetLastError(inst, "Already at Requested Tool") --else -----Get the Carousel Position to send to PLC----- --if RequestedTool == 1 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 1 CP")) val = tonumber(Requested) mc.mcRegSetValue(PositionToSendPLC, val) --end --if RequestedTool == 2 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 2 CP")) val = tonumber(Requested) mc.mcRegSetValue(PositionToSendPLC, val) --end --if RequestedTool == 3 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 3 CP")) val = tonumber(Requested) mc.mcRegSetValue(PositionToSendPLC, val) --end --if RequestedTool == 4 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 4 CP")) val = tonumber(Requested) mc.mcRegSetValue(PositionToSendPLC, val) --end --if RequestedTool == 5 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 5 CP")) val = tonumber(Requested) mc.mcRegSetValue(PositionToSendPLC, val) --end -----Send PLC Tool Change Signal----- -----Receive PLC Tool Change Complete Signal----- -----Change the Previous Tool's Carousel Register Positions----- --if Current == 1 then local Tool1Pos = mc.mcRegGetHandle(inst,"gRegs0/Tool 1 CP") mc.mcRegSetValue(Tool1Pos, CarouselPosition) --end --if Current == 2 then local Tool2Pos = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 2 CP")) val = tonumber(Tool2Pos) mc.mcRegSetValue(CarouselPosition, val) --end --if Current == 3 then local Tool3Pos = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 3 CP")) val = tonumber(Tool3Pos) mc.mcRegSetValue(CarouselPosition, val) --end --if Current == 4 then local Tool4Pos = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 4 CP")) val = tonumber(Tool4Pos) mc.mcRegSetValue(CarouselPosition, val) --end --if Current == 5 then local Tool5Pos = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 5 CP")) val = tonumber(Tool5Pos) mc.mcRegSetValue(CarouselPosition, val) --end -----Set Requested Tool carousel position register to "0" (this means it's in the spindle). --if Requested == 1 then local Requested = mc.mcRegGetValueString(mc.mcRegGetHandle(inst,"gRegs0/Tool 1 CP")) val = tonumber(Requested) mc.mcRegSetValue(Requested, 0) --end mc.mcCntlSetLastError(inst, "Tool Change Complete") --end --If Requested == Current end --Macro End if (mc.mcInEditor()== 1) then m6000() end