Hi Craig,
thanks!

i will look at it tomorrow. Is it maybe possible to get support from you to create the m6 macro?
this is where i`am right now...
to understand it... i have a 6 position toolchanger which is driven by a 24V dc motor on "output3"only in one direction, the reference will be scanned by a encoder signal on "input0" and the tool positions are scanned too by another encoder light source "input4" ....for the input4 -> on every tool position i get a "1" signal from the encoder.
I need a loop to count the tool positions, because the only way of the Toolnumbers are 1,2,3,4,5,6,1,2,3,4,5,6,1,2....and so on... the only thing that works now, is if i write in my MDI "M06 T0202", the motor starts to move... but it doesn`t count the signals from input 4 and didn`t stop the motor.
Before of all... i made a reference from the tool changer so that it starts from tool number 1 .. that works.
function m6()
local inst = mc.mcGetInstance()
local out3= mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3);
local outstate = mc.mcSignalGetState(out3);
local signalfait = mc.ISIG_INPUT4
local max = "6"
--maximal toolslocal selectedTool = mc.mcToolGetSelected(inst)
--selected toolselectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
-- current toolcurrentTool = math.tointeger(currentTool)
local newTool = mc.mcToolGetCurrent(inst)
-- new toolnewTool = math.tointeger(newTool)
mc.mcCntlSetLastError(inst, " ");
--delete error line mc.mcCntlGcodeExecuteWait(inst,"G53 G0 x0 \n G53 G0 Z0")
-- go to safety positionif (selectedTool == currentTool)then
--if selected tool is equal to current tool then mc.mcCntlSetLastError(inst, "new tool = old tool, toolchange not possible");
-- Error else
if (selectedTool > max) then
--if selected tool is greater than max tools (6) wx.wxMessageBox("tool number to high! max tools = "..tostring(max))
-- Error text else
mc.mcSignalSetState(out3, true)
--Output3 - Toolchange Motor o while (selectedTool ~= currentTool) do
--start loop local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local newTool = mc.mcToolGetCurrent(inst)
newTool = math.tointeger(newTool)
if (mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)) == 1) then
--if "1" Signal on Input4 ,then newTool = currentTool + 1
-- new tool = current tool + 1 mc.mcToolSetCurrent(inst,newTool)
-- set current tool display to current tool number if (newTool > max) then
-- if new tool is greater then max tool,then newTool = 1
-- new tool = 1 if (newTool = selectedTool) then
--if new tool is equal to selected tool, then break
--stop the loop mc.mcSignalSetState(out3, false)
--Output 3 off - toolchange motor stop mc.mcCntlGcodeExecuteWait(inst,"G43 H??")
-- set offset display to new tool offset mc.mcToolSetCurrent(inst,newTool)
-- set current tool display to current tool number end
end
end
end
end
if (mc.mcInEditor() == 1) then
m6()
end
------------------------------------------------------
hopefully you can help and understand me
andy from germany