Hello Members,
I so much appreciate your help.

I have almost no chance to get a help like this in my country...
I'm trying to run a manual tool change macro in Mach4.
I use ESS + MB2(ver2.0) + 4 step motors(Y axis has 2 motors, I configured B as Y-Slave in ESS plugin, so MACH4 doesn't know there is a slaved motor.)
When I put "T3 M6" in MDI and click on Cycle Start, nothing happens....
And I captured log as below.
2018-02-08 01:19:05.002 - API: mcCntlMdiExecute(inst = 0, commands = 't2 m6') (Mach4GUI)
2018-02-08 01:19:05.104 - Attempt transition from "Idle" on event "MDI Start" Controller.cpp:1875
2018-02-08 01:19:05.104 - S_IDLE_on_exit
2018-02-08 01:19:05.104 - ACTION_start_mdi
2018-02-08 01:19:05.104 - S_MDI_RUNNING_on_entry
2018-02-08 01:19:05.104 - S_MDI_RUNNING2_on_entry
2018-02-08 01:19:05.105 - Signal id 1114, (Gcode Running), changed from LOW to HIGH.
2018-02-08 01:19:05.115 - Signal id 1121, (Tool Change), changed from LOW to HIGH.
2018-02-08 01:19:05.116 - >>>>> ESS received a Tool Change Required notification.
2018-02-08 01:19:05.120 - >>>>> ESS received a Tool Change Done notification.
2018-02-08 01:19:05.121 - Signal id 1121, (Tool Change), changed from HIGH to LOW.
2018-02-08 01:19:05.121 - >>>>> ESS received a Tool Change Done notification.
2018-02-08 01:19:05.241 - Attempt transition from "MDI Running" on event "Stop" GcodeExec.cpp:1179
2018-02-08 01:19:05.241 - S_MDI_RUNNING2_on_exit
2018-02-08 01:19:05.241 - Signal id 1114, (Gcode Running), changed from HIGH to LOW.
2018-02-08 01:19:05.241 - S_MDI_RUNNING_on_exit
2018-02-08 01:19:05.241 - ACTION_stop
2018-02-08 01:19:05.265 - S_IDLE_on_entry
Following is the code that I want to use with my machine. But nothing happens...
(I got it from DAZ part3 code, and only modified XY position and Spindle On/Off)
function M6()
local inst = mc.mcGetInstance();
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local xstart = mc.mcAxisGetPos(inst,0)
local ystart = mc.mcAxisGetPos(inst,1)
if selectedtool == currenttool then
return
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n X25.0 Y352.5")
-- wx.wxMessageBox("Please turn off spindle and click ok to continue") --can be removed if required
RunProbe(currenttool)
local toolz = mc.mcAxisGetPos(inst,2)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
wx.wxMessageBox("Please change to tool number "..selectedtool.." "..changetoo.." and press ok to continue")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X25.0 Y352.5")
RunProbe(selectedtool)
mc.mcAxisSetPos(inst, 2 , toolz)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
-- wx.wxMessageBox("Please turn on spindle and click ok to continue") --can be removed if required
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.." Y"..ystart)
mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")
end
end
function RunProbe(tool)
local inst = mc.mcGetInstance()
toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, tool)
if toollen == 0 then toollen = 50 end -- User Preference
mc.mcCntlSetLastError(inst, "Changing to Fallback Length")
local probestart = -60 + toollen
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\nG91 G31 Z-60 F100")
end
if (mc.mcInEditor() == 1) then
M6()
end
I don't think Mach4 correctly recognizes selectedtool and currenttool.
So... if I just get rid of the lines concerning selectedtool and currenttool from the code. M6 works...
But it always say... "Please change to tool number 2 and press OK to continue." always... number 2...... I don't know why...
This is always the same whatever tool number I put, such as T3, T4, T5.....
function m6()
local inst = mc.mcGetInstance();
local xstart = mc.mcAxisGetPos(inst,0)
local ystart = mc.mcAxisGetPos(inst,1)
local guesslen = -100
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool)
if toollen == 0 then toollen = 50 end
local probestart = guesslen + toollen
--if selectedtool == currenttool then
--return
mc.mcCntlSetLastError(inst, "Toolchange Activated")
--else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G00 Z0.000")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G00 X25.000")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G00 Y352.500")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G00 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z-60 F100")
local toolz = mc.mcAxisGetPos(inst,2)
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G00 Z0.000")
local changetoo = mc.mcToolGetDesc(inst, selectedtool)
wx.wxMessageBox("Please change to tool number "..selectedtool.." "..changetoo.." and press OK to continue")
currenttool = selectedtool
toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool)
if toollen == 0 then toollen = 50 end
probestart = guesslen + toollen
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G00 X25.000")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G00 Y352.500")
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G00 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-60 F100")
mc.mcAxisSetPos(inst, 2 , toolz)
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G00 Z0.000")
mc.mcCntlGcodeExecuteWait(inst, "G90 G00 Y"..ystart)
mc.mcCntlGcodeExecuteWait(inst, "G90 G00 X"..xstart)
mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "Toolchange Finished")
--wx.wxMessageBox('Toolchange Finished')
end
--end
if (mc.mcInEditor() == 1) then
m6()
end
What should I do....?
I'm desperately hopeless.... ;(