Hello Guest it is March 28, 2024, 07:00:41 AM

Author Topic: Mach4 Executing Gcode from LUA  (Read 10213 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach4 Executing Gcode from LUA
« Reply #10 on: June 02, 2015, 01:23:16 AM »
Hi Dan,

Are you good now? I feel like a di@I( head asking a question on top of yours. I got some things working pretty good if your're stuck. Hope all's well.

-josh

Offline Dan13

*
  •  1,208 1,208
    • View Profile
    • DY Engineering
Re: Mach4 Executing Gcode from LUA
« Reply #11 on: June 02, 2015, 05:14:51 AM »
I will be writing a macro for probing, so will see if I manage it OK.

Dan
Re: Mach4 Executing Gcode from LUA
« Reply #12 on: July 01, 2015, 02:20:52 PM »
Have any of you run into problems when trying to call a custom M command through this method? I can get it to run regular gcode but the moment I put in say M10 (just activates an output signal) m4 locks up. I wonder if it is because of using a function within my new function..?

The code I am using looks like:
Code: [Select]
function m31() --  Load New Board
    local state, rc = mc.mcSignalGetState(mc.mcSignalGetHandle(0, mc.ISIG_INPUT3)) -- obtain loader signal state
    local inst = mc.mcGetInstance()
    if (state == 1) -- Check States for Board Loader Signal
        then
           --mc.mcCntlMdiExecute(inst, 'M12') -- used for testing (works for a button), freezes upon use
           mc.mcCntlGcodeExecute(inst, 'G00 X1700\nM10\nG00 X0\n') --goes to 1700, then freezes
        else
          -- do nothing
    end
end

m31();

if (mc.mcInEditor() == 1) then
    m31();
end

Any insight is greatly appreciated!
Re: Mach4 Executing Gcode from LUA
« Reply #13 on: July 01, 2015, 02:36:29 PM »
try using:

if state == 1 then mc.mcScriptExecute (inst, "m12.mcs", 0) end

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Mach4 Executing Gcode from LUA
« Reply #14 on: July 01, 2015, 02:55:51 PM »
For macro scripts (not screen or buttons scripts), The M code functions are available in the calling M code.

if state == 1 then
  m12();
end

Steve
Re: Mach4 Executing Gcode from LUA
« Reply #15 on: July 01, 2015, 03:06:42 PM »
Thanks! Calling the m12() worked smurph (should have guessed that would work  :-[), the execute script function still crashed m4 unfortunately louie, not sure what exactly is the reason.

Is there a cleaner way of piecing together my code aside from:

Code: [Select]
if (state == 1)-- Check States for Board Loader
        then
            mc.mcCntlGcodeExecute(inst, 'G00 X1700.');
            m12();
            mc.mcCntlGcodeExecute(inst, 'G00 X0.');
    end

That code works totally fine, just seems clunky, especially when I have much longer macros planned  :D