beautypg.com

Smithy CNC Mills User Manual

Page 43

background image

SmithyCNC Programmer’s Reference Manual:O Codes

SmithyCNC Programmer’s Reference Manual: O-Codes

4-2

O-CODE OVERVIEW

O-codes provide for flow control in NC programs. Each block has an associated

number, which is the number used after O. Care must be taken to properly

match the O-numbers.

The behavior is undefined if

* Other words are used on a line with an O- word

4.1 Subroutines: "sub", "endsub", "return", "call"

Subroutines extend from a O- sub to an O- endsub. The lines inside the subrou-

tine (the "body") are not executed in order; instead, they are executed each

time the subroutine is called with O- call.

O100 sub (subroutine to move to machine home)

G0 X0 Y0 Z0

O100 endsub

(many intervening lines)

O100 call

Inside a subroutine, O- return can be executed. This immediately returns to the

calling code, just as though O- endsub was encountered.

O- call takes up to 30 optional arguments, which are passed to the subroutine

as #1, #2, ..., #N. Parameters from #N+1 to #30 have the same value as in

the calling context. On return from the subroutine the previous values parame-

ters #1 through #30 (regardless of the number of arguments) will be restored

to the values they had before the call.

Because "1 2 3" is parsed as the number 123, the parameters must be enclosed

in square brackets. The following calls a subroutine with 3 arguments:

O200 call [1] [2] [3]

Subroutine bodies may not be nested. They may only be called after they are

defined. They may be called from other functions, and may call themselves

recursively if it makes sense to do so. 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 will be visible to the calling code.