Welcome, Guest. Please login or register.
Did you miss your activation email?
November 18, 2017, 10:10:32 PM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  Mach4 General Discussion
| | |-+  M code Error calling a macro
Pages: 1   Go Down
Print
Author Topic: M code Error calling a macro  (Read 775 times)
0 Members and 1 Guest are viewing this topic.
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« on: March 20, 2017, 01: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
Logged
DazTheGas
Active Member

Offline Offline

Posts: 666


DazTheGas


View Profile
« Reply #1 on: March 20, 2017, 02:24:53 PM »

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
Logged

Theres always time for a choccy biccy
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #2 on: March 20, 2017, 04:14:18 PM »

I looked thought the API doc's didn't see either of the commands you mentioned to look up..

Gary
Logged
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #3 on: March 20, 2017, 04:37:07 PM »

I think I found it its was call mcScriptExecute ...

Thanks I will give it a try
Logged
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #4 on: March 20, 2017, 04:44:43 PM »

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
Logged
DazTheGas
Active Member

Offline Offline

Posts: 666


DazTheGas


View Profile
« Reply #5 on: March 20, 2017, 05:12:05 PM »

The command you need is mcCntlMdiExecute, mcScriptExecute executes lua scripts.

Your command in the button should look something like

Code:
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
Logged

Theres always time for a choccy biccy
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #6 on: March 21, 2017, 06:37:14 PM »

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
Logged
smurph
Mach4 Alpha

Offline Offline

Posts: 882


"That there... that's an RV."


View Profile
« Reply #7 on: March 21, 2017, 11:00:06 PM »

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

Logged
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #8 on: March 22, 2017, 07:34:02 PM »

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
Logged
gorf23
Active Member

Offline Offline

Posts: 61


View Profile
« Reply #9 on: March 26, 2017, 10:27:59 AM »

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
Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!