Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Hood on August 09, 2016, 05:20:33 AM
-
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
-
the Do Loop could be done like this I believe
while (1)
{
if something then break -- this could infinite loop on you. but then so did your original
}
or
for element < 20
{
if something then break -- this would loop 20 times and then quit or break out if something happens
element += 1
}
-
Thanks for the reply, will look into that once I can work out what the heck I am doing :D
Brett has pointed me to a section in the manual, had read it but didn't think it related to modbus, will have another look and see what I can make of it.
Been struggling to get the PLC talking, no probs in Mach3 but took a long time to get somewhere in Mach4. It seems to be talking now but not seeing any changes on the Diagnostics when I should be, I think ::)
Will have to get a second cable and port on this comp so I can monitor both the PLC and Mach4 at the same time.
Hood