Hello Guest it is May 22, 2019, 01:18:55 PM

Author Topic: call subprogram from macro?  (Read 2102 times)

0 Members and 1 Guest are viewing this topic.

call subprogram from macro?
« on: May 03, 2015, 12:47:14 PM »
I could call a subprogram from a macro by coding

Code "G98 P112"
but is there a way that doesn't use 'Code "'?

Thanks
M21

Offline BR549

*
  •  6,865 6,865
    • View Profile
Re: call subprogram from macro?
« Reply #1 on: May 03, 2015, 01:36:21 PM »
YES and NO (;-)   I use teh rediredtion fnctio of the M98 to move to another spot in Gcode from a macro. For example

G0 X0 Y0
M100         ( this macro is used to redirect to a o100 point in the Gcode. It is simply Code"M98 P100")
X10
Y10
X0
Y0
o100
x1 Y1

The macro will JUMPTO the sub call line o100 BUT it cannot return so the redirection is one way. Of course you could use the call again to JUMPTO back to another sub call line.

You can also add conditional CB code to make decisions as what you need to do . MUCH like conditional Gcode. You can also add outside param to eth macro to program the conditional Mcode on the fly as M100 Pxx Qxx Rxx  you have 3 params to work with for each Mcode. ALSO you have ALL the #vars you can add as well. Mcode PxxQxxRxx #1=100 #31=300.. THE #vars are solved FIRST in the call line so they WILL be available when the macro runs.

I will double check on a straight SUb call from a macro to be sure about it. it has been a LONG time last I played with that idea. (;-)


Offline BR549

*
  •  6,865 6,865
    • View Profile
Re: call subprogram from macro?
« Reply #2 on: May 03, 2015, 01:53:47 PM »
NO you CANNOT call a sub from a macro as it has nowhere to return to as the Gcode side cannot SEE the M98 that is in the macro. You will get an erro"SUB called with no return"  But that does not mean you cannot redirect the end of the sub back to another Sub call line. basically back to the line after the macro. You just have to be clever.

SO more notes on Macros.

When you read or write to dros or variable give it a bit of sleep time to get it all done

SetOemDro(10,GetVar(24))         I use 100ms for each function(read/write)
sleep(300)

Group your motion code and use   WHile Ismoving() to wait untill Mach3 is done with it.  This will HOLD the macro until motion stops. Use it with ANY and all motion codes. Use it with a single call or a group call for motion.

Code"G0 X0Y0"
Code" X10"
Code" Y10"
Code"X0"
Code"Y0"

While Ismoving()
Wend


Hope that helps, (;-) TP
Re: call subprogram from macro?
« Reply #3 on: May 03, 2015, 02:25:44 PM »
Thanks, some of that's clear, some I'll have to re read and consult the manual on.

So I could do this:-
in Gcode;                      M100
In macro M100;             Code "M98 P112" (or o, or whatever it is, can't remember at the minute...)
Back in Gcode (o112),    do some code
                                  M98 P113

and then o113is basically the line after the line where M100 was called from.

Is that right? Seems sensible if so.

Where do I learn about #Var particularly,  and using params? I searched the programmers manual for #var; it doesnt exist there.

Offline BR549

*
  •  6,865 6,865
    • View Profile
Re: call subprogram from macro?
« Reply #4 on: May 03, 2015, 02:33:01 PM »
You will not find any mention of any redirection use or SUB use in a macro in ANY manual (;-) You just read the manual on that function.

THE #var info is in the Mach3 manuals .

To redirect BACK to the line after the Mcode you MUST put in the sub call line.


M100  ( the macro jumps to o100 in the Gcode)
o101
code
code
code
M30

o100
M101   ( this macro will Jump back to the o101 sub call line)


Re: call subprogram from macro?
« Reply #5 on: May 03, 2015, 02:41:45 PM »
Okay, thanks, that's totally clear now. I'll look in the right manual this time...
Re: call subprogram from macro?
« Reply #6 on: May 09, 2015, 03:09:54 AM »
Do be very careful. Mach3 supports subroutine calls of course, but if you go down too many layers it sometimes forgets things. Intermittently.

cheers
Roger
Re: call subprogram from macro?
« Reply #7 on: May 09, 2015, 04:09:42 AM »
I too often intermittently forget things.... Thankfully my programs don't need too many macro or sub calls, they do seem to work better that way.