EasyManua.ls Logo

Tormach 1500MX - Conditional Subroutines Reference; If;Endif

Tormach 1500MX
288 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
9: PROGRAMMING
l Repeat/endrepeat: Execute the subroutine while a
condition is true
l If/elseif/else/endif: Conditionally execute the
subroutine
l Break: Break out of a while or if/elseif statement
l Continue: Skip remaining code and restart at top of
while or repeat loop
l Return: Return a value
The sub and endsub keywords are used to define the
beginning and end a subroutine. All lines of code between the
sub and endsub keywords are considered to be part of the
subroutine.
Example of sub, endsub, call:
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...
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.
©Tormach® 2024
Specifications subject to change without notice.
Page 199 UM10811: 1500MX Operator's Manual (Version 0424A)
For the most recent version, see tormach.com/support

Table of Contents

Related product manuals