So, with Lua replacing VBscript, how is the above described process handled by MACH4? Specifically, does MACH4 suspend the G-code execution until macros return or will the programmer still have to test and insert delays to assure this happens?
Secondly, will macros be able to have any legal windows file name and be called by a 'RunScript' (or equiv) call?
simpson36,
First I want to explain the main difference between how mach3 handled Mcodes and how mach4 handles Mcodes. In mach3 every time a Mcode was called from gcode or a RunScript command mach would go find the mcode load that single VB script, compile it and then run it. So in mach3 every mcode was run on its own thread and the only way to have one mcode pass variables to another mcode was through a DRO, LED ect.
Now lets talk about mach4!! When mach4 starts up it will look at all the Mcodes in the Macros directory and compile them and load them into a single file called mcLua.mcc this is the file mach will run from when a Mcode is called. Now this is where it gets cool! In mach4 when you define a variable you can define it as "local testvar = 123" or a global "testvar = 123" if it is a global variable then any Mcode or script that is in the macros directory can read that variable.
Another big difference is how you must create your mcodes, here is a example.
function m3()
local inst = mc.mcGetInstance() -- Get the current instance
local Range, Dwell
Range = mc.mcSpindleGetCurrentRange(inst);
Dwell = mc.mcSpindleGetAccelTime(inst, Range);
-- Turn on Spindle FWD Output
local hReg = mc.mcSignalGetHandle(inst,mc.OSIG_SPINDLEFWD)
if hReg == 0 then
mc.mcCntlSetLastError(inst, "Get Handle Error")
return
end
mc.mcSignalSetState(hReg,true)
-- Turn on Spindle On Output
local hReg = mc.mcSignalGetHandle(inst,mc.OSIG_SPINDLEON)
if hReg == 0 then
mc.mcCntlSetLastError(inst, "Get Handle Error")
return
end
mc.mcSignalSetState(hReg,true)
--Dwell while spindle gets up to speed
wx.wxSleep(Dwell);
end
if (mc.mcInEditor() == 1) then
m3()
end
Because mach4 compiles all the Mcodes into one script and runs them the only thing that separates Mcodes in the mcLua file are the "function" calls that each Mocde needs to have.
If I was making a custom mcode and needed to run m3 I would simply write "m3()" and because the custom mcode we made is compiled into mcLua along with m3 we can call m3 just like we would call a local function.
This opens up a whole new world of powerful options!!
I hope that helps!!
Andrew Eldredge
MachMotion