Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: chair-man on July 11, 2016, 05:45:34 PM

Title: conditional subroutine jump
Post by: chair-man on July 11, 2016, 05:45:34 PM
I am just getting a new 5 axis build running - this is my 3rd Mach machine, but first using Mach4.  Machine has dual Y axis tables (so 6 axis machine) for loading while other table is running operation.  I am trying to get the machine to run the following type of Gcode:

O0001
M200 (this will check input to see if left table is ready)
M201 (this will check input to see if right table is ready)
M99

O1000
(Y left table code goes here)
M99

O2000
(Y right table code goes here)
M99

The M200 monitors an input from a PLC that controls pneumatic clamps/vacuum table/etc, so I have logic that determines that a zone is "ready to run".  The goal is to have M200 look at input 5 on the CNC control (output from PLC), then if the state is on jump to subroutine 1000, if not on, returns and M201 would check input 6, if "on" jump to 2000, if off return to the main program which would start the cycle over again.

I have the M200/M201 script working with message boxes - so sees the input and properly does the logic.  I then tested the program by substituting "M98 P1000" for M200, and "M98 P2000" for M201, and the program ran correctly.  Now when I replaced the message boxes in the conditional script with "mc.mcCntlGcodeExecute (inst, "M98 P1000") it just cycled in the main program and never jumped out to the subroutine.  I decided to see if my coding was correct so I replaced "M98 P1000" with "G90 G0 X10." and that ran correctly... so there must be some kind of problem with putting the M98 code in the script????

Is there some other code I am missing that might allow that to happen?
Title: Re: conditional subroutine jump
Post by: bob_at_pmdx on July 11, 2016, 09:40:35 PM
Am I correct that you have something like this:

- Gcode file calls subroutine O0001
- Sub O0001 executes M200 (or M201) which is a Lua script
- The M200 (or M201) Lua script then tried to call mc.mcCntlGCodeExecute()

If so, I *think* the issue is that you cannot execute GCode from within a function that gets called from GCode (i.e. the GCode interpreter is not re-entrant).  Though I may be wrong.

Bob