Ok really crap at VB and it has taken me years to get to the heady heights of crap
I am looking now at Mach4 and Lua is kicking me hard.
Below is a macro I have for my lathes turret (M6start.m1s)
'Toolchange macro for Computurn 290
NewTool = GetSelectedTool() Mod 8
Oldtool = GetCurrentTool()
If NewTool = 0 Then
NewTool = 8
End If
Modtoolout = NewTool - 1
ModtoolIn = NewTool - 1
If NewTool = OldTool Then
End
End If
Do
Call SetModOutput (Modtoolout,1)
If GetInput (ModtoolIn) Then Exit Do
Loop
SetCurrentTool( NewTool )
sleep 10
Call SetModOutput (Modtoolout,0)
Sleep 1000
If GetInput(42) Then
Message ("Toolchange Complete")
Else
MsgBox( "Turret failed to clamp, Programme stopped")
DoOemButton(1003)
End If
I am trying to get it into lua but really struggling with the modbus part especially. I have gotthe mod part working fine and think a repeat will do what the Do Loop in the VB does, just not sure how to get it looking at the modbus I/O.
Below is my quick adaption of the default m6.mcs and what I have works fine.
function m6()
local inst = mc.mcGetInstance()
local NewTool = mc.mcToolGetSelected(inst)%8
local OldTool = mc.mcToolGetCurrent(inst)
--local ModtoolOut
--local ModtoolIn
if (NewTool== 0) then
NewTool = 8
end
if NewTool == OldTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
return
else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
--mc.mcCntlToolChangeManual(inst, true);
wx.wxMessageBox("Tool needs changed to".. " ".. NewTool)
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(NewTool) .. " Previous Tool == " .. tostring(OldTool))
mc.mcToolSetCurrent(inst, NewTool)
end
end
if (mc.mcInEditor() == 1) then
m6()
end
Anyone have any hints or links to docs which might help?
Hood