Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: moorea21 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
-
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. (;-)
-
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
-
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.
-
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)
-
Okay, thanks, that's totally clear now. I'll look in the right manual this time...
-
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
-
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.