Hello Guest it is April 16, 2024, 07:49:34 PM

Author Topic: Variable filenames in M98 subroutine call?  (Read 3472 times)

0 Members and 1 Guest are viewing this topic.

Variable filenames in M98 subroutine call?
« on: February 22, 2012, 11:59:33 PM »
I've created 14 G-code files containing text to be engraved, each text string starting at a 0,0 origin.  The text will be engraved in arrays (labels for tool holes in a storage box), so a subroutine looked like being the best way to handle them.

I named the text code files 10.nc, 15.nc, 20.nc, etc, and tried to perform the following (snippets):

Code: [Select]
#10 = 10 (first text file)
G0 X17 Y10 (move to first legend start location)
M98 P2 L5 (first five legends)
G92.1 (cancel coordinate offsets)
.
.
O2 (subroutine)
G92 X0 Y0 (make this the new origin)
M98 (#10.nc)
#10 = [#10 + 5]
G0 X20.667 Y0
M99 (return)

But Mach3 refuses to load this program!  It goes through the motions, but finishes with no code displayed, though no error message!

I've  tried square brackets around the parameter:
Code: [Select]
M98 ([#10].nc)
but still the same failure.  (I've tested with
Code: [Select]
M98 (10.nc)and this works OK, but of course I get the same text for each five labels!)

Does anyone know how I can implement 'variable' file names, or am I doomed to having to write 14 M98 calls to my text files? ???

Daniel
« Last Edit: February 23, 2012, 12:05:17 AM by DanielF »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Variable filenames in M98 subroutine call?
« Reply #1 on: February 23, 2012, 11:16:43 AM »
Are you trying to call SUB form within the program OR OUTSIDE subs.

Inside subs
#10=10
 M98 P#10 L1

o10
code
code
#10=[#10+5]
M99


Outside subs I have never tried to use a #var and am NOT SURE whether  it would work but I will give it a try. The problem IS the outside call par tis NOT a normal Gcode function.

Re: Variable filenames in M98 subroutine call?
« Reply #2 on: February 23, 2012, 06:28:57 PM »
Are you trying to call SUB form within the program OR OUTSIDE subs.
...
Outside subs I have never tried to use a #var and am NOT SURE whether  it would work but I will give it a try. The problem IS the outside call par tis NOT a normal Gcode function.

I thought my explanation and code snippet were fairly clear...

My program calls an internal subroutine (O2), which in turn I want to call a series of external subroutines (files), named 10.nc, 15.nc, etc.

I'm not sure what it is you're proposing to try, as I've already tried the code shown in the snippet, and it doesn't work.  I'm looking for some sort of 'work-around' or alternative method of calling external subroutines using a variable for the file name.

Rgds, Daniel

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Variable filenames in M98 subroutine call?
« Reply #3 on: February 23, 2012, 08:33:41 PM »
I really don't see any way for that to work.

You CAN use #var as in M98 P#10 L1 to call an internal SUB And the #var=[#var +5] will work fine.

BUT not to call and outside sub as in M98 (#10.txt) L1

You may be able to create a Hybrid CB macro to do it BUT would be a lot more work that just programming in what you need.

(;-) TP
Re: Variable filenames in M98 subroutine call?
« Reply #4 on: February 23, 2012, 08:44:12 PM »
Thanks TP.  I'm pretty much resigned to having to use 14 external M98 calls.

No big deal; it's just a one-off hobby job anyway.  But I'm trying to improve my G-coding skills, and thought it would be a good exercise in clever programming, had it worked!

Maybe some future version of Mach will incorporate this ability, and more importantly, conditional statements in G-code.

Daniel