Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: gorf23 on March 20, 2017, 02:37:50 PM
-
I have a m720 macro I wrote it reads and writes the mach4 registers...
If I compile and debug the macro it runs fine on its own...
I created a on screen button that I am trying to run the macro m720()
It will not run this way I always get a error nul value m720.
am I calling the macro wrong? is there another way? or can I not do this with a screen button?
Thanks gary
-
an mcode is a macro run from within gcode not a function available to the gui, to run an mcode from the gui you will need to use one of the api commands like mdiexecute or gcodeexecute. you will find the api docs within the mach4hobby docs directory.
DazTheGas
-
I looked thought the API doc's didn't see either of the commands you mentioned to look up..
Gary
-
I think I found it its was call mcScriptExecute ...
Thanks I will give it a try
-
I seem to have developed a new problem I run mach4 go to screen edit
click on one of the scripts and get the message can't run the lua editor, it just won't run, I even uninstalled mach4 and reinstalled deleted all the folders and still can't run the lua editor.
Any suggestions?
Thanks gary
-
The command you need is mcCntlMdiExecute, mcScriptExecute executes lua scripts.
Your command in the button should look something like
local inst = mc.mcGetInstance()
mc.mcCntlMdiExecute(inst, "m720"
As for the lua editor, can you post a screenshot of the error message. I have never heard od this before.
DazTheGas
-
Daz
Tested it getting strange results here is the button code
local inst = mc.mcGetInstance() --Captures current instance of Mach 4
--rc = mc.mcCntlMdiExecute(inst, "m720") This doesn't seem to work
rc = mc.mcScriptExecuteIfExists(inst, "m720", false) This works but in the messagebox I get no value printed from the getregister that's on a windows 10 64bit
if I run it on my laptop windows 7 32 the lua editor crashes get the message Lua editor stopped working
Here is the m720() code
function m720()
function WriteRegister(regname, regvalue)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))
end
function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end
-- probe = GetRegister("X_Probe")
Mytext = "1"
WriteRegister("X_Probe",Mytext)
regval = GetRegister("X_Probe")
wx.wxMessageBox(regval)
-- wx.wxMessageBox(probe)
return true
end
if (mc.mcInEditor() == 1) then
m720()
end
make any sense ?
Thanks gary
-
If you want a M code macro and a screen button to have the same functionality, put the code in a module and load the module in both the screen load script and the M code macro.
Make sure the m720 macro script filename is lower case. As in "m720.mcs". Also, you have functions within the m720 function. While this works in LUA, it can be confusing. The Write/GetRegister functions would be better suited in a file all by themselves. Say "utility.mcs" and drop that file into the macros directory. Or, as mentioned above, put in a global module.
Steve
-
I must be missing something or not getting your answer..
I added the getregister and writeregister functions to the screen load script...
I try to call it from a button script
regval = GetRegister("X_Probe") I get the error mcLua ERROR: Lua: Error while running chunk
wx.wxMessageBox(regval)
WriteRegister("Y_Probe", 12)
from what I have read in the lua docs this should work from a button..
Gary
-
DAZ
I have found that if I try to test the button script calling the get or read registers while stepping thought the debug editor
is when I get the error...
if I press the button from the main screen not in lua editor it works...
Still having trouble calling an script from button press, and using the m code from MDI tried one with just wx.wxMessageBox and it
didn't display the messagebox..
Gary