Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Overloaded on May 06, 2014, 08:36:45 PM
-
Looking at various btn script examples, like this one:
local inst = mc.mcGetInstance()
mc.mcCntlMdiExecute(inst, 'G00 X0 Y0 Z0 A0')
How would you write it to do multiple lines of GCode with one finishing before the next one starts ? [[ ]] /n \n ::)
One of several embarrassingly futile attempts: ::)
local inst = mc.mcGetInstance()
mc.mcCntlMdiExecute(inst, 'G00 Z2')
mc.mcCntlMdiExecute(inst, 'G00 X0 Y0')
Hey, I'm just tinkering here, don't go out of your way now, this is not important. :)
But, being you've already read it ............. ;D
Thanks again,
Russ
-
Here is a snip of a tool changer so you can see how I formatted the strings
--Drop off the current tool
local code = "G0 G53 Z0.0\n"
code = code .. string.format("G0 G53 X%.4f Y%.4f\n", m_changePos[CurrentTool].x + m_X_Pullout, m_changePos[CurrentTool].y + m_Y_Pullout)
code = code .. string.format("G0 G53 Z%.4f\n", m_ZtoolHeight)
code = code .. string.format("G0 G53 X%.4f Y%.4f\n", m_changePos[CurrentTool].x, m_changePos[CurrentTool].y)
mc.mcCntlGcodeExecute(inst, tostring(code))
--Release tool
mc.mcSignalSetState(unclamp, true);--Unclamp
wx.wxSleep(.75)
--Move to new tool
code = string.format("G0 G53 Z%.4f\n", m_ZtoolHeight + m_PullupDist)
code = code .. string.format("G0 G53 X%.4f Y%.4f", m_changePos[NewTool].x, m_changePos[NewTool].y)
code = code .. string.format("G0 G53 Z%.4f", m_ZtoolHeight)
mc.mcCntlGcodeExecute(inst, tostring(code))
--Clamp tool
mc.mcSignalSetState(unclamp, false);--Unclamp
wx.wxSleep(.75)
mc.mcToolSetCurrent(inst, NewTool)
code = string.format("G0 G53 X%.4f Y%.4f", m_changePos[NewTool].x + m_X_Pullout, m_changePos[NewTool].y + m_Y_Pullout)
code = code .. string.format("G0 G53 Z0.0")
mc.mcCntlGcodeExecute(inst, tostring(code))
I am going to wait for the sun and look for dust...
-
Thanks for your time Brian :)
I'll glean what I can out of that example. (almost looks like you found one of them scrolls too ;D )
Supposed to be cloudy here tomorrow, so the dust shouldn't distract me. ;D
See ya bud, thanks,
Russ
:)
-
With Brian's example, (and several references to the Rosetta Stone ;D ), I came up with this:
--Go to Part Zero via Safe Z
local inst = mc.mcGetInstance()
local code = "G0 G53 Z0.0\n"
code = code .. string.format("G0 X0 Y0\n")
code = code .. string.format("G0 Z0.5\n")
code = code .. string.format("G1 Z0 F10\n")
mc.mcCntlGcodeExecute(inst, tostring(code))
It works as expected. I was pleasantly surprised. :)
Added a button for a Safe Z type G28 also using the same format, a treat. :)
Thanks Brian, Steve !
Russ
:)
-
:)
-
And so it is, One more example is the dead machine scrolls ... I will put them in a cave so no one can find them!
-
;D
Thanks again,
:)
-
QUESTION, is mach4 using LUA or wxLUA or BOTH ??
(;-) TP
-
wxLua.
The hard part to get under one's hat is that there are two wxLua environments. One in the GUI and one in the mcLua plugin. The mcLua plugin is the one that runs all of the macros. Putting the macro scripting in a plugin makes it possible for other script languages to be added later. But I HIGHLY doubt that the GUI will ever run anything other than LUA. So anyway, be aware that there are two separate scripting environments. Both have access to the mc.* API. But only the GUI has access to the scr.* screen API.
-
Is that why you can not change a button label from a m3 script?
-
Yep, that is why. It is possible. But you have to get crafty. Both script environments have access to the Mach Registers. So a register can be used to "communicate" between the two environments. So in the M3 script, you set a register to something like "1" and in the PLC screen script, you watch that register. If the register is "1" change the button label to one thing. It is it "0", change the label to something else, etc...
Steve
-
Might be easier to do it in the PLC Script and just look for a ledCW on or off
-
Yes. There is that!
-
This code worked for me in the PLC Script to change the button labels.
I am interested in the ability to get and set values to the registers.
looked at it, but just caused Lua and Mach4 to crash several times just trying to get a value.
local SpinCW = scr.GetProperty('ledSpindleCW','Value','Value',0);
local SpinCCW = scr.GetProperty('ledSpindleCCW','Value','Value',0);
if (SpinCW == "1") then
scr.SetProperty('btnSpindleCW', 'Label', 'SpindleCW OFF');
else
scr.SetProperty('btnSpindleCW', 'Label', 'SpindleCW ON');
end
if (SpinCCW == "1") then
scr.SetProperty('btnSpindleCCW', 'Label', 'SpindleCCW OFF');
else
scr.SetProperty('btnSpindleCCW', 'Label', 'SpindleCCW ON');
end
-
Crafty indeed !
The nifty possibilities continue, thanks for posting that Craig.
Russ
:)