o100 call (call the subroutine here)
M02
Subroutines can either be defined in the program file or in a
separate file. If the subroutine is defined in the same file as
the main program that calls the subroutine, it must be defined
before the call statement.
For example, this is valid:
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...
o100 call (call the subroutine here)
M02
But this is not:
o100 call (call the subroutine here)
M02
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...
A subroutine can be a separate file as long as:
l The file is named the same as your call.
l The file includes a sub and endsub in the file.
l The file is in the directory /subroutines.
l The file name only includes lowercase letters, numbers,
dashes, and underscores.
l The file only contains a single subroutine definition.
l The file ends with the extension .nc.
Note: File names are lowercase letters only.
o<MyFile> is converted to o<myfile> by the
interpreter.
To execute a subroutine in a program, it must be called. To call
a subroutine, program o~ call where ~ is the subroutine
name. The subroutine name may be either a named file, a
numbered file, or an expression that evaluates to a valid
subroutine label.
l Expression example: o[#101+2] call
l Named file example: o<myfile> call
l Numbered file example: o123 call
o~ call takes up to 30 optional arguments, which are
passed to the subroutine as #1, #2 , . . . , #N. Unused
parameters from #N+1 to #30 have the same value as in the
calling context.
Parameters #1-#30 are local to the subroutine. On return from
the subroutine, the values of parameters #1 through #30
(regardless of the number of arguments) are restored to the
values they had before the call.
The following calls a subroutine with three arguments: o200
call [1] [2] [3]
Because 1 2 3 is parsed as the number 123, the parameters
must be enclosed in square brackets.
Subroutine bodies may be nested.
l Nested subroutines may only be called after they are
defined.
l They may be called from other functions, and may call
themselves recursively if it makes sense to do so.
l The maximum subroutine nesting level is 10.
Subroutines do not have return values, but they may change
the value of parameters above #30 and those changes are
visible to the calling G-code. Subroutines may also change the
value of global named parameters.
Conditional Subroutines Reference
Subroutines can be conditionally executed using the if/endif or
the if/else/elseif/endif keyword constructs.
if/endif
The if/endif conditional will execute a block of code following
theif keyword only when the if argument evaluates to true.
If/endif example:
o100 sub
(notice that the if-endif block uses a different
number)
o110 if [#2 GT 5]
(some code here)
o110 endif
(some more code here)
o100 endsub
if/elseif/else/endif
The if/elseif/else/endif conditional will execute the block of
code following the if keyword when its argument evaluates to
true. If the argument evaluates to false, then the code
following each elseif is executed as long as the associated
elseif argument evaluates to true. If no elseif keywords are
©Tormach® 2023
Specifications subject to change without notice.
Page 222 Tormach 1100M® Operator's Manual (Version 1223A)
For the most recent version, see tormach.com/support
10: PROGRAMMING