G code: G36
, G37
Function: The commands change the value of a variable. G36
writes the specified value to a variable. G37
increments the variable by the specified value. O$var$
defines the variable that is edited. D
defines the value that is written for G36
or added for G37
. The command is used, for example, for a loop counter required for conditional jumps.
Syntax
G36 O D
G 37 O D
G code word for G36 |
Description |
---|---|
O |
Variable that is written. If |
D |
New variable value |
G code word for G37 |
|
O |
Variable that is incremented. If |
D |
Increment |
Example
Programing the counter (if the path is processed online)
The global variable g_i
is set to 5.
N1000 G36 O$g_i$ D5
Lines 1010 and 1020 are traveled five times.
N1000 G36 O$g_i$ D5
N1010 G1 X100 F100 E100 E-100
N1020 G1 X0
N1030 G37 O$g_i$ D-1
N1040 G20 L1010 K$g_i$
The mechanism functions only if the path is processed online, because only then can variables be used. This mechanism does not work in the CNC editor.
Programming the counter for offline mode
To work with the editor offline, specify no variable by means of O
. Then an implicit decoder variable of type INT
is used. However, only one variable is available. You cannot program any nested jumps or loops.
You can use a string variable in the O word in G code. Moreover, a string value can be assigned and inserted to this variable by means of the command G36
and G37
.
Example
N10 G36 O$strTest$ D'Name'
The variable strTest
contains the NAME value.
N20 G37 O$strTest$ D'=Test'
=Test
is added to the variable strTest
.
If string variables are used in the CNC program, and if the CNC program (in the IEC program) is read by means of the SMC_ReadNCFile
function block, then buffers for the strings must be reserved in the IEC program. Otherwise, the error SMV_RNCF_NO_STRINGBUFFER
occurs. The SMC_StringBuffer
function block is available for this purpose.
Every string of the CNC program requires its own space in the function block instance of SMC_StringBuffer
, even if the same string occurs multiple times.
The following declaration can buffer 32 strings, for example:
sb: SMC_StringBuffer(uiBufferSize := 32);
The the function block instance sb
is passed as a pointer to the pStringBuffer
input of the SMC_ReadNCFile
instance.
See also