Hello Guest it is March 29, 2024, 08:04:38 AM

Author Topic: can subprograms be listed out of order?  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

can subprograms be listed out of order?
« on: May 12, 2015, 02:49:17 PM »
I'm not with my Mach pc for a few days, but I was wondering about how flexible Mach is when it comes to the order of subprograms and main code etc in a gcode file; so I thought I'd just ask instead.

My code runs fine, when the subprograms are written in numerical order, but it would be useful if they could be written in the order in the attached text file; I have a program that generates my gcode, which I can modify easily to resemble that in the attachment, but putting them in numerical order would be much more difficult.

Does Mach allow subprograms to be listed in non numerical order? Does it matter if some appear after the 'M30' line? My code has no main program as such; the main code is in sub 411, and it never gets to M30 because a macro called before that closes the file and opens the next one in the folder.

As I said, it runs fine when the subs are in numerical order; the only change to the attached version is the order they are written in.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: can subprograms be listed out of order?
« Reply #1 on: May 12, 2015, 09:25:04 PM »
YOU are not using SUB program code so your question does not really apply.

I cannot see the Mcode script to comment on that part.

The way you are doing the coding you can apply the  o word order any way you want to as the macro I assume is redirecting the code from Mcode script.

If you remember me telling you , there are Dragons in the woods when you do things this way.  IF you change the order of execution you must also declare the return point as the M98 from  inside of a macro cannot do the return as Mach3 has NO idea where the return point is. Gcode and Mcode code run in different threads and each know nothing of the other until it hits the run QUE.

It only runs now because the order of execution is correct. Changing the  order of the program code without redirecting will cause KAOS.

Just a thought, (;-) TP

Re: can subprograms be listed out of order?
« Reply #2 on: May 14, 2015, 07:49:37 AM »
I had wondered if the fact that none of my macros or subprograms ever have to return to the main program would mean that the running order was redundant; I've tested it now, mostly it runs okay but has a couple of quirks which I'd rather not have to deal with.

I'll stick to running it in order; if anything odd happens I'll declare the return point as you suggested.

Thanks,

M21

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: can subprograms be listed out of order?
« Reply #3 on: May 14, 2015, 09:24:16 AM »
Something to remember. All code(except SUBs) in front of the M30 WILL execute in the exact order that it is written UNLESS you redirect it from within an Mcode.  Subs after the M30 will execute in order of being called from a M98.

(;-) TP
Re: can subprograms be listed out of order?
« Reply #4 on: May 14, 2015, 11:32:16 AM »
OK, ta. More to get my head around...