|
|
Work preparation
3.1 Flexible NC programming
$UUD\ LQGH[
1
,QLWLDOL]DWLRQ IRU
1
1
,QLWLDOL]DWLRQ ZLWK
1
1
,QLWLDOL]DWLRQ ZLWK
GHILQLWLRQ
LGHQWLFDO YDOXH
YDULRXV YDOXHV
7KH DUUD\ HOHPHQWV > @ WR
7KH DUUD\ HOHPHQWV > @ WR
>
@ KDYH EHHQ LQLWLDOL]HG
>
@ KDYH EHHQ LQLWLDOL]HG
ZLWK WKH GHIDXOW YDOXH
ZLWK WKH GHIDXOW YDOXH
7KH DUUD\ HOHPHQWV > @ WR
>
@ KDYH QRW EHHQ FKDQJHG
See also
Definition and initialization of array variables (DEF, SET, REP) (Page 418)
Variables (Page 389)
Additional information (SET)
initialization for the definition
• Starting with the 1st array element, as many array elements are assigned with the values
from the value list as there are elements programmed in the value list.
• A value of 0 is assigned to array elements without explicitly declared values in the value list
(gaps in the value list).
• For variables of the AXIS data type, gaps in the value list are not permitted.
• An alarm is displayed if the value list contains more values than there are array elements
defined.
NC programming
422
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Value assignment in program execution
In the case of value assignment in program execution, the rules described above for the
definition apply. The following options are also supported:
• Expressions are also permitted as elements in the value list.
• Value assignment starts with the programmed array index. Values can be assigned
selectively to subarrays.
Example:
Program code
Comment
DEF INT ARRAY[5,5]
; Array definition
ARRAY[0,0]=SET(1,2,3,4,5)
; Value assignment to the first 5 array ele-
ments [0,0] - [0,4]
ARRAY[0,0]=SET(1,2, , ,5)
; Value assignment with gap to the first 5 array
elements [0,0] - [0,4], array elements[0,2] and
[0,3] = 0
ARRAY[2,3]=SET(VARIABLE,4*5.6)
; Value assignment with variable and expression
starting at array index [2,3]:
[2,3] = VARIABLE
[2,4] = 4 * 5.6 = 22.4
Further information (REP)
initialization for the definition
• All or the optionally specified number of array elements are initialized with the specified value
(constant).
• Variables of the FRAME data type cannot be initialized.
Example:
Program code
Comment
DEF REAL varName[10]=REP(3.5,4)
; Initialize array definition and array ele-
ments [0] to [3] with value 3.5.
Value assignment in program execution
In the case of value assignment in program execution, the rules described above for the
definition apply. The following options are also supported:
• Expressions are also permitted as elements in the value list.
• Value assignment starts with the programmed array index. Values can be assigned
selectively to subarrays.
Examples:
Program code
Comment
DEF REAL varName[10]
; Array definition
varName[5]=REP(4.5,3)
; Array elements [5] to [7] = 4.5
R10=REP(2.4,3)
; R-parameters R10 to R12 = 2.4
DEF FRAME FRM[10]
; Array definition
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
423
Work preparation
3.1 Flexible NC programming
Program code
Comment
FRM[5]=REP(CTRANS(X,5))
; Array elements [5] to [9] = CTRANS(X,5)
See also
Definition and initialization of array variables (DEF, SET, REP) (Page 418)
3.1.1.13
Data types
The following data types are available in the NC:
Data type
Meaning
Value Range
INT
Integer with sign
-2147483648 ... +2147483647
REAL
Real number (LONG REAL to IEEE)
±(∼2,2*10-308 … ∼1,8*10+308)
BOOL
Truth value TRUE (1) and FALSE (0)
1, 0
CHAR
ASCII character
ASCII code 0 to 255
STRING
Character string of a defined length
Maximum of 200 characters (no special
characters)
AXIS
Axis/spindle identifier
Channel axis identifier
FRAME
Geometric parameters for static coordinate
---
transformation (translation, rotation, scal-
ing, mirroring)
Implicit data type conversions
The following data type conversions are possible and are performed implicitly during
assignments and parameter transfers:
from ↓/ to →
REAL
INT
BOOL
REAL
x
o
&
INT
x
x
&
BOOL
x
x
x
x : Possible without restrictions
o: Data loss possible due to the range of values being overshot ⇒ alarm;
rounding: decimal place value ≥ 0.5 ⇒ round up, decimal place value < 0.5 ⇒ round down
&: value ≠ 0 ⇒ TRUE, value== 0 ⇒ FALSE
See also
Variables (Page 389)
3.1.1.14
Variable minimum, maximum and range (MINVAL, MAXVAL and BOUND)
The MINVAL and MAXVAL commands compare the values of two variables. The smaller value (in
the case of MINVAL) or the larger value (in the case of MAXVAL) respectively is delivered as a
result.
NC programming
424
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
The BOUND command tests whether the value of a test variable falls within a defined range of
values.
Syntax
<smaller value>=MINVAL(<variable1>,<variable2>)
<larger value>=MAXVAL(<variable1>,<variable2>)
<return value>=<BOUND>(<minimum>,<maximum>,<test variable>)
Meaning
MINVAL:
Obtains the smaller value of two variables
(<variable1>, <variable2>)
<smaller value>:
Result variable for the MINVAL command
Set to the smaller variable value.
MAXVAL:
Obtains the larger value of two variables (<variable1>, <variable2>)
<larger value>:
Result variable for the MAXVAL command
Set to the larger variable value.
BOUND:
Tests whether a variable (<test variable) is within a defined range of
values.
<minimum>:
Variable which defines the minimum value of the range of values.
<maximum>:
Variable which defines the maximum value of the range of values.
<return value>:
Result variable for the BOUND command
If the value of the test variable is within the defined range of values, the
result variable is set to the value of the test variable.
If the value of the test variable is greater than the maximum value, the
result variable is set to the maximum value of the definition range.
If the value of the test variable is less than the minimum value, the result
variable is set to the minimum value of the definition range.
Note
MINVAL, MAXVAL, and BOUND can also be programmed in synchronized actions.
Note
Behavior if values are equal
If the values are equal, MINVAL/MAXVAL are set to this equal value. In the case of BOUND the
value of the variable to be tested is returned again.
Example
Program code
Comment
DEF REAL rVar1=10.5, rVar2=33.7, rVar3, rVar4, rVar5, rValMin, rValMax, rRetVar
rValMin=MINVAL(rVar1,rVar2)
; rValMin is set to value 10.5.
rValMax=MAXVAL(rVar1,rVar2)
; rValMax is set to value 33.7.
rVar3=19.7
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
425
Work preparation
3.1 Flexible NC programming
Program code
Comment
rRetVar=BOUND(rVar1,rVar2,rVar3)
; rVar3 is within the limits, rRetVar is set to 19.7.
rVar3=1.8
rRetVar=BOUND(rVar1,rVar2,rVar3)
; rVar3 is below the minimum limit, rRetVar is set to
10.5.
rVar3=45.2
rRetVar=BOUND(rVar1,rVar2,rVar3)
; rVar3 is above the maximum limit, rRetVar is set to
33.7.
3.1.1.15
Check availability of a variable (ISVAR)
The predefined ISVAR function can be used to check whether a system/user variable (e.g.
machine data, setting data, system variable, general variables such as GUD) is known in the NC.
Variable
The variables to be queried have the following structure:
Dimensionless variable:
<Variable>
One-dimensional variable without array index: <Variable>[ ]
One-dimensional variable with array index n: <Variable>[<n>]
Two-dimensional variable without array index: <Variable>[ , ]
Two-dimensional variable with array indices n <Variable>[<n>,<m>]
and m:
Syntax
<Result>=ISVAR(<Variable>[<n>,<m>])
Meaning
<result>:
Return value
Data type:
BOOL
Range of values:
1
Variable available
0
Variable unknown
ISVAR:
Checks whether the specified system/user variable is known in the NC.
<Variable>:
Name of the system/user variable
Data type:
STRING
<n>:
Array index of the first dimension (optional)
Data type:
INT
<m>:
Array index of the second dimension (optional)
Data type:
INT
The following checks are made in accordance with the transfer parameter:
• Is the name known?
• Is the variable an array?
NC programming
426
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
• Is it a one- or two-dimensional array?
• Is the respective array index in the permissible range?
Only if all checks are positive, TRUE (1) is returned.
If a check is negative or a syntax error has occurred, FALSE (0) is returned.
Examples
Program code
Comment
DEF INT VAR1
DEF BOOL IS_VAR=FALSE
N10 IS_VAR=ISVAR("VAR1")
; IS_VAR is in this case TRUE.
Program code
Comment
DEF REAL VARARRAY[10,10]
DEF BOOL IS_VAR=FALSE
N10 IS_VAR=ISVAR("VARARRAY[,]")
; IS_VAR is in this case TRUE, is a two-di-
mensional array.
N20 IS_VAR=ISVAR("VARARRAY")
; IS_VAR is TRUE, variable exists.
N30 IS_VAR=ISVAR("VARARRAY[8,11]")
; IS_VAR is FALSE, array index is not per-
mitted.
N40 IS_VAR=ISVAR("VARARRAY[8,8")
; IS_VAR is FALSE, "]" missing (syntax er-
ror).
N50 IS_VAR=ISVAR("VARARRAY[,8]")
; IS_VAR is TRUE, array index is permitted.
N60 IS_VAR=ISVAR("VARARRAY[8,]")
; IS_VAR is TRUE, array index is permitted.
Program code
Comment
DEF BOOL IS_VAR=FALSE
N100 IS_VAR=ISVAR("$MC_GCODE_RESET_VALUES[1]"
; Transfer parameter is a machine
data item, IS_VAR is TRUE.
Program code
Comment
DEF BOOL IS_VAR=FALSE
N10 IS_VAR=ISVAR("$P_EP")
; IS_VAR is in this case TRUE.
N20 IS_VAR=ISVAR("$P_EP[X]")
; IS_VAR is in this case TRUE.
3.1.1.16
Reading attribute values / data type (GETVARPHU, GETVARAP, GETVARLIM,
GETVARDIM, GETVARDFT, GETVARTYP)
The attribute values of system/user variables can be read with the predefined GETVARPHU,
GETVARAP, GETVARLIM, GETVARDIM and GETVARDFT functions, the data type of a system/user
variable with GETVARTYP.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
427
Work preparation
3.1 Flexible NC programming
Read physical unit
Syntax:
<Result>=GETVARPHU(<name>)
Meaning:
<result>:
Numeric value of the physical unit
Data type:
INT
Range of values:
See Table in "Attribute: Physical unit (PHU) (Page 410)"
In case of fault
- 2
The specified variable name has not been assigned to a
system parameter or a user variable.
GETVARPHU:
Reading of the physical unit of a system/user variable
<name>:
Name of the system/user variables
Data type:
STRING
Example:
The NC contains the following GUD variables:
DEF CHAN REAL PHU 42 LLI 0 ULI 10000 electric
Program code
Comment
DEF INT result=0
result=GETVARPHU("electric")
; Determine the physical unit of the GUD var-
iables.
IF (result < 0) GOTOF error
The value 42 is returned as result. This corresponds to the physical unit [kW].
Note
GETVARPHU can be used, for example, to check whether both variables have the expected
physical units in a variable assignment a = b.
Read access right
Syntax:
<Result>=GETVARAP(<name>,<access>)
NC programming
428
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Meaning:
<result>:
Protection level for the specified <access>
Data type:
INT
Range of val-
0 ... 7
See "Attribute: Access rights (APR, APW, APRP, APWP, APRB,
ues:
APWB) (Page 412)".
In case of fault
- 1
Cannot be written (only relevant for access types "WP" and
"WB")
- 2
The specified variable name has not been assigned to a
system parameter or a user variable.
- 3
Incorrect value for the parameter <access>
GETVARAP:
Reading of the access right to a system/user variable
<name>:
Name of the system/user variables
Data type:
STRING
<access>:
Type of access
Data type:
STRING
Range of val-
"RP"
Read via part program
ues:
"WP"
Write via part program
"RB"
Read via OPI
"WB"
Write via OPI
Example:
Program code
Comment
DEF INT result=0
result=GETVARAP("$TC_MAP8","WB")
; Determine the access protection for the sys-
tem parameter "magazine position" with regard
to writing via OPI.
IF (result < 0) GOTOF error
The value 7 is returned as result. This corresponds to the key switch position 0 (= no access
protection).
Note
GETVARAP can be used, for example, to implement a checking program that checks the access
rights expected by the application.
Read limit values
Syntax:
<Status>=GETVARLIM(<name>,<limit value>,<result>)
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
429
Work preparation
3.1 Flexible NC programming
Meaning:
<Status>:
Function status
Data type:
INT
Range of val-
1
OK
ues:
-1
No limit value defined
(for variables of type AXIS, STRING, FRAME)
-2
The specified variable name has not been assigned to a sys-
tem parameter or a user variable.
-3
Incorrect value for the parameter <limit value>
GETVARLIM:
Reading of the lower/upper limit value of a system/user variable
<name>:
Name of the system/user variables
Data type:
STRING
<limit
specifies which limit value should be read out
value>:
Data type:
CHAR
Range of val-
"L"
Lower limit value
ues:
"U"
Upper limit value
:
<result>:
Return of the limit value
Data type:
VAR REAL
Example:
Program code
Comment
DEF INT state=0
DEF REAL result=0
state=GETVARLIM("$MA_MAX_AX_VELO","L",result)
; Determine the lower limit val-
ue for MD32000 $MA_MAX_AX_VELO.
IF (result < 0) GOTOF error
Read dimension value
Syntax:
<Result>=GETVARDIM(<Name>,<Index>)
Meaning:
<result>:
Size of the dimension specified by the parameter <Index>
Data type:
INT
GETVARDIM:
Reading the size of the first, second or third dimension of the field of a system/user
variable
<name>:
Name of the system/user variables
Data type:
STRING
NC programming
430
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
<Index>:
Array index
Data type:
INT
Range of val-
1 ... 3
ues:
1
Index for first Dimension of the field
2
Index for 2nd Dimension of the field
3
Index for third Dimension of the field
Example:
Program code
Comment
N5 DEF REAL myReal[5,4]
N10 R1=GETVARDIM("myReal",1)
; Determine the size of the first dimension of the
field.
; Result: R1 = 5
N15 R2=GETVARDIM("myReal",2)
; Determine the size of the second dimension of
the field.
; Result: R2 = 4
Read default value
Syntax:
<Status>=GETVARDFT(<Name>,<Result>[,<Index_1>,<Index_2>, <Index_3>])
Meaning:
<Status>:
Function status
Data type:
INT
Range of val-
1
OK
ues:
-1
No default value available
(e.g. because the data type definition of the result variables
does not match the data type of the system/user variables).
-2
The specified variable name has not been assigned to a sys-
tem parameter or a user variable.
-3
Incorrect value for parameter <Index_1>, dimension smaller
than one (⇒ no field but scalar variable)
-4
Incorrect value for the parameter <Index_2>
-5
Incorrect value for the parameter <Index_3>
GETVARDFT:
Reading of the default value of a system/user variable
<name>:
Name of the system/user variables
Data type:
STRING
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
431
Work preparation
3.1 Flexible NC programming
<result>:
Return of the default value
Data type:
VAR REAL
(when reading the default value of variables of the types INT, REAL,
BOOL, AXIS)
VAR STRING
(when reading the default value of variables of the types STRING
and CHAR)
VAR FRAME
(when reading the default value of variables of the type FRAME)
<index_1>:
Index for first dimension of the field (optional)
Data type:
INT
Not programmed means = 0
<index_2>:
Index for 2nd dimension of the field (optional)
Data type:
INT
Not programmed means = 0
<index_3>:
Index for third dimension of the field (optional)
Data type:
INT
Not programmed means = 0
Example:
Program code
Comment
DEF INT state=0
DEF REAL resultR=0
; Variable to accept the default values of
the types INT, REAL, BOOL, AXIS.
DEF FRAME resultF=0
; Variable to accept the default values of
the type FRAME
IF (GETVARTYP("$MA_MAX_AX_VELO") <> 4) GOTOF error
state=GETVARDFT("$MA_MAX_AX_VELO",resultR, AXTOINT(X))
; Determine the default value of the "X"
axis.
IF (result < 0) GOTOF error
IF (GETVARTYP("$TC_TP8") <> 3) GOTOF error
state=GETVARDFT("$TC_TP8", resultR)
IF (GETVARTYP("$P_UBFR")
<> 7) GOTOF error
state=GETVARDFT("$P_UBFR", resultF )
Read data type
Syntax:
<Result>=GETVARTYP(<name>)
NC programming
432
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Meaning:
<result>:
Data type of the specified system/user variables
Data type:
INT
Range of val-
1
= BOOL
ues:
2
= CHAR
3
= INT
4
= REAL
5
= STRING
6
= AXIS
7
= FRAME
In case of fault
< 0
The specified variable name has not been assigned to a sys-
tem parameter or a user variable.
GETVARTYP:
Reading of the data type of a system/user variable
<name>:
Name of the system/user variables
Data type:
STRING
Example:
Program code
Comment
DEF INT result=0
DEF STRING name="R"
result=GETVARTYP(name)
; Determine the type of the R parameter.
IF (result < 0) GOTOF error
The value 4 is returned as result. This corresponds to the REAL data type.
3.1.1.17
Possible type conversions
The constant numeric value, the variable, or the expression assigned to a variable must be
compatible with the variable type. If this is the case, the type is automatically converted when
the value is assigned.
Possible type conversions
to
REAL
INT
BOOL
CHAR
STRING
AXIS
FRAME
from
REAL
yes
Yes*
Yes1)
Yes*
-
-
-
INT
yes
yes
Yes1)
Yes2)
-
-
-
BOOL
yes
yes
yes
yes
yes
-
-
CHAR
yes
yes
Yes1)
yes
yes
-
-
STRING
-
-
Yes4)
Yes3)
yes
-
-
AXIS
-
-
-
-
-
yes
-
FRAME
-
-
-
-
-
-
yes
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
433
Work preparation
3.1 Flexible NC programming
Explanation
*
At type conversion from REAL to INT, fractional values that are >=0.5 are rounded up,
others are rounded down (cf. ROUND function).
1)
Value <> 0 is equivalent to TRUE; value == 0 is equivalent to FALSE
2)
If the value is in the permissible range
3)
If only 1 character
4)
String length 0 = >FALSE, otherwise TRUE
Note
If conversion produces a value greater than the target range, an error message is output.
If mixed types occur in an expression, type conversion is automatic. Type conversions are also
possible in synchronous actions, see Chapter "Motion-synchronous actions, implicit type
conversion".
3.1.2
Indirect programming
3.1.2.1
Indirectly programming addresses
When indirectly programming addresses (Page 1278), the extended address (<Index>) is replaced
by the suitable type of variable.
Note
It is not possible to indirectly program addresses for:
• N (block number)
• L (subprogram)
• Settable addresses
(e.g. X[1] instead of X1 is not permissible)
Syntax
<ADDRESS>[<Index>]
Meaning
<ADDRESS>[...]:
Fixed address with extension (index)
<index>:
Variable, e.g. for spindle number, axis,
NC programming
434
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Examples
Example 1: Indirectly programming a spindle number
Direct programming:
Program code
Comment
S1=300
; Speed 300 rpm for the spindle number 1.
Indirect programming:
Program code
Comment
DEF INT SPINU=1
; Defining variables, type INT and value assignment.
S[SPINU]=300
; Speed 300 rpm for the spindle, whose number is saved in
the SPINU variable (in this example 1, the spindle with the
number 1).
Example 2: Indirectly programming an axis
Direct programming:
Program code
Comment
FA[U]=300
; Feedrate 300 for axis "U".
Indirect programming:
Program code
Comment
DEF AXIS AXVAR2=U
; Defining a variable, type AXIS and value assignment.
FA[AXVAR2]=300
; Feedrate of 300 for the axis whose address name is saved
in the variables with the name AXVAR2.
Example 3: Indirectly programming an axis
Direct programming:
Program code
Comment
$AA_MM[X]
; Read probe measured value (MCS) of axis "X".
Indirect programming:
Program code
Comment
DEF AXIS AXVAR3=X
; Defining a variable, type AXIS and value assignment.
$AA_MM[AXVAR3]
; Read probe measured value (MCS) whose name is saved in
the variables AXVAR3.
Example 4: Indirectly programming an axis
Direct programming:
Program code
X1=100 X2=200
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
435
Work preparation
3.1 Flexible NC programming
Indirect programming:
Program code
Comment
DEF AXIS AXVAR1 AXVAR2
; Defining two type AXIS variables.
AXVAR1=(X1) AXVAR2=(X2)
; Assigning the axis names.
AX[AXVAR1]=100 AX[AXVAR2]=200
; Traversing the axes whose address names are
saved in the variables with the names AXVAR1
and AXVAR2
Example 5: Indirectly programming an axis
Direct programming:
Program code
G2 X100 I20
Indirect programming:
Program code
Comment
DEF AXIS AXVAR1=X
; Defining a variable, type AXIS and value assignment.
G2 X100 IP[AXVAR1]=20
; Indirect programming the center point data for the axis,
whose address name is saved in the variable with the name
AXVAR1.
Example 6: Indirectly programming array elements
Direct programming:
Program code
Comment
DEF INT ARRAY1[4,5]
; Defining array 1
Indirect programming:
Program code
Comment
DEFINE DIM1 AS 4
; For array dimensions, array sizes must be specified as
fixed values.
DEFINE DIM2 AS 5
DEF INT ARRAY[DIM1,DIM2]
ARRAY[DIM1-1,DIM2-1]=5
Example 7: Indirect subprogram call
Program code
Comment
CALL "L" << R10
; Call the program, whose number is located in R10 (string
cascading).
3.1.2.2
Indirectly programming G commands
Indirectly programming G commands (Page 1290) permits cycles to be effectively programmed.
NC programming
436
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Syntax
G[<group>]=<number>
Meaning
G[...]:
G command with extension (index)
<group>:
Index parameter: G group
Type:
INT
<number>:
Variable for the G command number
Type:
INT or REAL
Note
Generally, only G commands that do not determine the syntax can be indirectly programmed.
Only G group 1 is possible from the G commands that determine the syntax.
The syntax-determining G commands of G groups 2, 3 and 4 are not possible.
Note
Arithmetic functions are not permitted in the indirect G command programming. If it is
necessary to calculate the G command number, this must be done in a separate part program
line before the indirect G command programming.
Examples
Example 1: Adjustable work offset (G group 8)
Program code
Comment
N1010 DEF INT INT_VAR
N1020 INT_VAR=2
N1090 G[8]=INT_VAR G1 X0 Y0
;G54
N1100 INT_VAR=INT_VAR+1
; G command calculation
N1110 G[8]=INT_VAR G1 X0 Y0
;G55
Example 2: Level selection (G group 6)
Program code
Comment
N2010 R10=$P_GG[6]
; Read active G command of G group 6
N2090 G[6]=R10
3.1.2.3
Indirectly programming position attributes (GP)
Position attributes, e.g. the incremental or absolute programming of the axis position, can be
indirectly programmed as variables in conjunction with the key word GP.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
437
Work preparation
3.1 Flexible NC programming
Application
Indirectly programming position attributes is used in replacement cycles, as in this case, the
following advantage exists over programming position attributes as keyword (e.g. IC, AC, ...):
As a result of the indirect programming as variable, no CASE statement is required, which would
otherwise branch over all possible position attributes.
Syntax
<POSITIONING COMMAND>[<axis/spindle>]=
GP(<position>,<position attribute)
<axis/spindle>=BP(<position>,<position attribute)
Meaning
<POSITIONING COMMAND>[]:
The following positioning commands can be programmed to-
gether with the key word GP:
POS, POSA,SPOS, SPOSA
Also possible:
• All axis and spindle identifiers present in the channel:
<axis/spindle>
• Variable axis/spindle identifier AX
<axis/spindle>:
Axis/spindle that is to be positioned
GP():
Key word for positioning
<position>:
Parameter 1
Axis/spindle position as constant or variable
<position attribute>:
Parameter 2
Position attribute (e.g. position approach mode) as a variable
(e.g. $P_SUB_SPOSMODE) or as key word (IC, AC, ...)
The values supplied from the variables have the following significance:
Value
Meaning
Permissible for:
0
No change to the position attribute
1
AC
POS, POSA,SPOS, SPOSA,AX, axis address
2
IC
POS, POSA,SPOS, SPOSA,AX, axis address
3
DC
POS, POSA,SPOS, SPOSA,AX, axis address
4
ACP
POS, POSA,SPOS, SPOSA,AX, axis address
5
ACN
POS, POSA,SPOS, SPOSA,AX, axis address
6
OC
-
7
PC
-
8
DAC
POS, POSA,AX, axis address
9
DIC
POS, POSA,AX, axis address
10
RAC
POS, POSA,AX, axis address
11
RIC
POS, POSA,AX, axis address
12
CAC
POS, POSA
13
CIC
POS, POSA
NC programming
438
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Value
Meaning
Permissible for:
14
CDC
POS, POSA
15
CACP
POS, POSA
16
CACN
POS, POSA
Example
For an active synchronous spindle coupling between the leading spindle S1 and the following
spindle S2, the following replacement cycle to position the spindle is called using the SPOS
command in the main program.
Positioning is realized using the statement in N2230:
SPOS[1]=GP($P_SUB_SPOSIT,$P_SUB_SPOSMODE)
SPOS[2]=GP($P_SUB_SPOSIT,$P_SUB_SPOSMODE)
The position to be approached is read from the system variable $P_SUB_SPOSIT; the position
approach mode is read from the system variable $P_SUB_SPOSMODE.
Program code
Comment
N1000 PROC LANG_SUB DISPLOF SBLOF
N2100 IF($P_SUB_AXFCT==2)
N2110
; Replacement of the SPOS / SPOSA / M19
command for an active synchronous spindle
coupling
N2185 DELAYFSTON
; Start of stop delay area
N2190 COUPOF(S2,S1)
; Deactivate synchronous spindle coupling
N2200
; Position leading and following spindles
N2210 IF($P_SUB_SPOS==TRUE) OR
($P_SUB_SPOSA==TRUE)
N2220
; Positioning the spindle with SPOS:
N2230
SPOS[1]=GP($P_SUB_SPOSIT,
$P_SUB_SPOSMODE)
SPOS[2]=GP($P_SUB_SPOSIT,
$P_SUB_SPOSMODE)
N2250 ELSE
N2260
; Positioning the spindle using M19:
N2270 M1=19 M2=19
; Position leading and following spindles
N2280 ENDIF
N2285 DELAYFSTOF
; End of stop delay area
N2290 COUPON(S2,S1)
; Activate synchronous spindle coupling
N2410 ELSE
N2420
; Query on further replacements
N3300 ENDIF
N9999 RET
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
439
Work preparation
3.1 Flexible NC programming
Supplementary conditions
The indirect programming of position attributes is not possible in synchronized actions.
3.1.2.4
Indirectly programming part program lines (EXECSTRING)
Using the part program command EXECSTRING, it is possible to execute a previously generated
string variable as part program line.
Syntax
EXECSTRING is programmed in a separate part program line:
EXECSTRING (<string_variable>)
Meaning
EXECSTRING:
Command to execute a string variable as part program line
<string variable>:
Type STRING variable, that includes the actual part program line to be
executed
Note
With EXECSTRING, all part program constructions that can be programmed in the program
section of a part program, with the exception of control structures (Page 475), can be
extracted. This means that PROC and DEF statements are excluded as well as the general use in
INI and DEF files.
Example
Program code
Comment
N100 DEF STRING[100] MY_BLOCK
; Definition of string variables to accept the part
program line to be executed.
N110 DEF STRING[10] MFCT1="M7"
N200 EXECSTRING(MFCT1 <<
; Execute part program line "M7 M4711".
"M4711")
N300 R10=1
N310 MY_BLOCK="M3"
N320 IF(R10)
N330 MY_BLOCK = MY_BLOCK <<
MFCT1
N340 ENDIF
N350 EXECSTRING(MY_BLOCK)
; Execute part program line "M3 M7".
NC programming
440
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
3.1.3
Instructions
3.1.3.1
Arithmetic functions
Operator / arithmetic function
Meaning
+
Addition
-
Subtraction
*
Multiplication
/ 1)
Division 1)
DIV 1)
Integer number division 1)
MOD 1)
Modulo division (supplies the remainder of the integer number divi-
sion) 1)
:
Chain operator for FRAME variables
SIN()
Sine
COS()
Cosine
TAN()
Tangent
ASIN()
Arc sine
ACOS()
Arc cosine
ATAN2(,) 1)
Arc tangent2 1)
SQRT()
Square root
ABS()
Absolute value
POT()
2nd power (square)
TRUNC()
Integer component
The accuracy for comparison commands can be set using TRUNC (see
"Precision correction on comparison errors (TRUNC) (Page 445)")
ROUND()
Round to integer
LN()
Natural logarithm
EXP()
Exponential function
MINVAL ()
Lower value of two variables
(see "Variable minimum, maximum and range (MINVAL, MAXVAL
and BOUND) (Page 424)")
MAXVAL ()
Larger value of two variables
(see "Variable minimum, maximum and range (MINVAL, MAXVAL
and BOUND) (Page 424)")
BOUND ()
Variable value within the defined value range
(see "Variable minimum, maximum and range (MINVAL, MAXVAL
and BOUND) (Page 424)")
CTRANS()
Offset
CROT ()
Rotation
CSCALE()
Change of scale
CMIRROR()
Mirroring
1) See the paragraph, "Examples"
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
441
Work preparation
3.1 Flexible NC programming
Programming
The usual mathematical notation is used for arithmetic functions. Priorities for execution are
indicated by parentheses. Angles are specified for trigonometry functions and their inverse
functions (right angle = 90°).
Examples
Division: /
(type REAL) = type INT or type REAL) / (type INT or type REAL);
Example: 3 / 4 = 0.75
Integer number division: DIV
(type INT) = (type INT or REAL) / (type INT or REAL);
Example: 7 DIV 4.1 = 1
Modulo division (supplies the remainder of the integer number division): MOD
(type REAL) = (type INT or REAL) MOD (type INT or REAL);
Example: 7 MOD 4.1 = 2.9
Arc tangent 2: ATAN2
The arithmetic function ATAN2 calculates the angle of the total vector from two mutually
perpendicular vectors.
The result is in one of four quadrants (-180° < 0 < +180°).
The angular reference is always based on the 2nd value in the positive direction.
5
$7$1
$QJOH
r
QG YHFWRU
5
$7$1
$QJOH
r
QG YHFWRU
NC programming
442
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Programming examples
Program code
Comment
R1=R1+1
; New R1 = old R1 + 1
R1=R2+R3 R4=R5-R6 R7=R8*R9
R10=R11/R12 R13=SIN(25.3)
R14=R1*R2+R3
; Multiplication or division takes precedence
over addition or subtraction.
R14=(R1+R2)*R3
; Expressions and parentheses are calculated
first.
R15=SQRT(POT(R1)+POT(R2))
; Inner parentheses are resolved first:
R15 = square root of ( (R1^2 + R2^2) )
RESFRAME=FRAME1:FRAME2
; FRAME logic operation with chain operator
FRAME3=CTRANS(…):CROT(…)
Value assignment at a FRAME component
3.1.3.2
Comparison and logic operations
Comparison operations can be used, for example, to formulate a jump condition. Complex
expressions can also be compared.
The comparison operations are applicable to variables of type CHAR, INT, REAL and BOOL. The
code value is compared with the CHAR type.
For types STRING, AXIS and FRAME, the following are possible: == and <>, which can be used
for STRING type operations, even in synchronous actions.
The result of comparison operations is always of BOOL type.
Logic operators are used to link truth values.
The logical operations can only be applied to type BOOL variables. However, they can also be
applied to the CHAR, INT and REAL data types via internal type conversion.
For the logic (Boolean) operations, the following applies to the BOOL, CHAR, INT and REAL
data types:
•
0 corresponds to: FALSE
• Not equal to 0 means: TRUE
Bit-by-bit logic operators
Logic operations can also be applied to single bits of types CHAR and INT. Type conversion is
automatic.
Programming
Relational operator
Meaning
==
Equal to
<>
Not equal to
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
443
Work preparation
3.1 Flexible NC programming
Logic operator
Meaning
AND
AND
OR
OR
NOT
Negation
XOR
Exclusive OR
Bit-by-bit logic operator
Meaning
B_AND
Bit-by-bit AND
B_OR
Bit-by-bit OR
B_NOT
Bit-by-bit negation
B_XOR
Bit-by-bit exclusive OR
Note
In arithmetic expressions, the execution order of all the operators can be specified by
parentheses, in order to override the normal priority rules.
Note
Spaces must be left between BOOLEAN operands and operators.
Note
The operator B_NOT only refers to one operand. This is located after the operator.
Examples
Example 1: Comparison operators
IF R10>=100 GOTOF DEST
or
R11=R10>=100
IF R11 GOTOF DEST
The result of the R10>=100 comparison is first buffered in R11.
Example 2: Logic operators
IF (R10<50) AND ($AA_IM[X]>=17.5) GOTOF DESTINATION
or
IF NOT R10 GOTOB START
NOT only refers to one operand.
Example 3: Bit-by-bit logic operators
IF $MC_RESET_MODE_MASK B_AND 'B10000' GOTOF ACT_PLANE
NC programming
444
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
3.1.3.3
Priority of the operations
Each operator is assigned a priority. When an expression is evaluated, the operators with the
highest priority are always applied first. Where operators have the same priority, the evaluation
is from left to right.
In arithmetic expressions, the execution order of all the operators can be specified by
parentheses, in order to override the normal priority rules.
Order of operators
From the highest to lowest priority
1.
NOT, B_NOT
Negation, bit-by-bit negation
2.
*, /, DIV, MOD
Multiplication, division
3.
+, -
Addition, subtraction
4.
B_AND
Bit-by-bit AND
5.
B_XOR
Bit-by-bit exclusive OR
6.
B_OR
Bit-by-bit OR
7.
AND
AND
8.
XOR
Exclusive OR
9.
OR
OR
10.
<<
Concatenation of strings, result type STRING
11.
==, <>, >, <, >=, <=
Comparison operators
Note
The concatenation operator ":" for Frames must not be used in the same expression as other
operators. A priority level is therefore not required for this operator.
Example: IF statement
If (otto==10) and (anna==20) gotof end
3.1.3.4
Precision correction on comparison errors (TRUNC)
The TRUNC command truncates the operand multiplied by a precision factor.
Settable precision for comparison commands
Program data of type REAL is displayed internally with 64 bits in IEEE format. This display format
can cause decimal numbers to be displayed imprecisely and lead to unexpected results when
compared with the ideally calculated values.
Relative equality
To prevent the imprecision caused by the display format from interfering with program flow, the
comparison commands do not check for absolute equality, but rather for relative equality.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
445
Work preparation
3.1 Flexible NC programming
Syntax
Precision correction on comparison errors
TRUNC (R1*1000)
Meaning
TRUNC:
Truncate decimal places
Relative quality of 10-12 taken into account for
• Equality: (==)
• Inequality: (<>)
• Greater than or equal to: (>=)
• Less than or equal to: (<=)
• Greater/less than: (><) with absolute equality
• Greater than: (>)
• Less than: (<)
Compatibility
For compatibility reasons, the check for relative quality for (>) and (<) can be deactivated by
setting machine data MD10280 $MN_ PROG_FUNCTION_MASK Bit0 = 1.
Note
Comparisons with data of type REAL are subject to a certain imprecision for the above reasons.
If deviations are unacceptable, use INTEGER calculation by multiplying the operands by a
precision factor and then truncating with TRUNC.
Synchronized actions
The response described for the comparison commands also applies to synchronized actions.
Examples
Example 1: Precision considerations
Program code
Comments
N40 R1=61.01 R2=61.02 R3=0.01
;Assignment of initial values
N41 IF ABS(R2-R1) > R3 GOTOF ERROR
; Jump would have been executed up
until now
N42 M30
; End of program
N43 ERROR: SETAL(66000)
R1=61.01 R2=61.02 R3=0.01
;Assignment of initial values
NC programming
446
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Program code
Comments
R11=TRUNC(R1*1000) R12=TRUNC(R2*1000)
; Accuracy correction
R13=TRUNC(R3*1000)
IF ABS(R12-R11) > R13 GOTOF ERROR
; Jump is no longer executed
M30
; End of program
ERROR: SETAL(66000)
Example 2: Calculate and evaluate the quotient of both operands
Program code
Comments
R1=61.01 R2=61.02 R3=0.01
;Assignment of initial values
IF ABS((R2-R1)/R3)-1) > 10EX-5 GOTOF ERROR
; Jump is not executed
M30
; End of program
ERROR: SETAL(66000)
3.1.3.5
Roundup (ROUNDUP)
Input values, type REAL (fractions with decimal point) can be rounded up to the next higher
integer number using the ROUNDUP" function.
Syntax
ROUNDUP(<value>)
Meaning
ROUNDUP:
Command to roundup an input value
<value>:
Input value, type REAL
Note
Input value, type INTEGER (an integer number) is returned unchanged.
Examples
Example 1: Various input values and their rounding up results
Example
Rounding up result
ROUNDUP(3.1)
4.0
ROUNDUP(3.6)
4.0
ROUNDUP(-3.1)
-3.0
ROUNDUP(-3.6)
-3.0
ROUNDUP(3.0)
3.0
ROUNDUP(3)
3.0
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
447
Work preparation
3.1 Flexible NC programming
Example 2: ROUNDUP in the NC program
Program code
N10 X=ROUNDUP(3.5) Y=ROUNDUP(R2+2)
N15 R2=ROUNDUP($AA_IM[Y])
N20 WHEN X=100 DO Y=ROUNDUP($AA_IM[X])
3.1.4
String operations
Sting operations
In addition to the classic operations "assign" and "comparison" the following string operations
are possible:
• Type conversion to STRING (AXSTRING) (Page 449)
• Type conversion from STRING (NUMBER, ISNUMBER, AXNAME) (Page 449)
• Concatenation of strings (<<) (Page 450)
• Conversion to lower/upper case letters (TOLOWER, TOUPPER) (Page 451)
• Determine length of string (STRLEN) (Page 452)
• Search for character/string in the string (INDEX, RINDEX, MINDEX, MATCH) (Page 453)
• Selection of a substring (SUBSTR) (Page 454)
• Reading and writing of individual characters (Page 455)
• Formatting a string (SPRINT) (Page 456)
Special significance of the 0 character
Internally, the 0 character is interpreted as the end identifier of a string. If a character is replaced
with the 0 character, the string is truncated.
Example:
Program code
Comment
DEF STRING[20] STRG="axis . stationary"
STRG[6]="X"
MSG(STRG)
; Supplies the message "axis X sta-
tionary".
STRG[6]=0
MSG(STRG)
; Supplies the message "axis".
NC programming
448
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
3.1.4.1
Type conversion to STRING (AXSTRING)
The function "type conversion to STRING" allows variables of different types to be used as a
component of a message (MSG).
When using the << operator this is realized implicitly for data types INT, REAL, CHAR and BOOL
(see " Concatenation of strings (<<) (Page 450) ").
An INT value is converted to normal readable format. REAL values convert with up to 10 decimal
places.
Type AXIS variables can be converted to STRING using the AXSTRING command.
Syntax
<STRING_RES> = << <any_type>
<STRING_RES> = AXSTRING(<axis identifier>)
Meaning
<STRING_RES>:
Variable for the result of the type conversion
Type:
STRING
<any_type>:
Variable types INT, REAL, CHAR, STRING and BOOL
AXSTRING:
The AXSTRING command supplies the specified axis identifier as string.
<axis identifier>:
Variable for axis identifier
Type:
AXIS
Note
FRAME variables cannot be converted.
3.1.4.2
Type conversion from STRING (NUMBER, ISNUMBER, AXNAME)
A conversion is made from STRING to REAL using the NUMBER command. The ability to be
converted can be checked using the ISNUMBER command.
A string is converted into the axis data type using the AXNAME command.
Syntax
<REAL_RES>=NUMBER("<string>")
<BOOL_RES>=ISNUMBER("<string>")
<AXIS_RES>=AXNAME("<string>")
Meaning
NUMBER:
The NUMBER command returns the number represented by the <string> as REAL
value.
<string>:
Type STRING variable to be converted
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
449
Work preparation
3.1 Flexible NC programming
<REAL_RES>:
Variable for the result of the type conversion with NUMBER
Type:
REAL
ISNUMBER:
The ISNUMBER command checks whether the <string> can be converted into a
valid number.
<BOOL_RES>:
Variable for the result of the interrogation with ISNUMBER
Type:
BOOL
Value:
TRUE
ISNUMBER supplies the value TRUE, if the <string>
represents a valid REAL number in compliance with the
language rules.
FALSE
If ISNUMBER supplies the value FALSE, when
calling NUMBER with the same <string>, an alarm is
initiated.
AXNAME:
The AXNAME command converts the specified <string> into an axis identifier.
Note:
If the <string> cannot be assigned a configured axis identifier, an alarm is initi-
ated.
<AXIS_RES>:
Variable for the result of the type conversion with AXNAME
Type:
AXIS
Example
Program code
Comment
DEF BOOL BOOL_RES
DEF REAL REAL_RES
DEF AXIS AXIS_RES
REAL_RES == 1234.9876Ex-7
; BOOL_RES == TRUE
BOOL_RES=ISNUMBER("1234XYZ")
; BOOL_RES == FALSE
REAL_RES=NUMBER("1234.9876Ex-7")
; REAL_RES == 1234.9876Ex-7
AXIS_RES=AXNAME("X")
; AXIS_RES == X
3.1.4.3
Concatenation of strings (<<)
The function "concatenation strings" allows a string to be configured from individual
components.
The concatenation is realized using the operator "<<". This operator has STRING as the target
type for all combinations of basic types CHAR, BOOL, INT, REAL, and STRING. Any conversion that
may be required is carried out according to existing rules.
Syntax
<any_type> << <any_type>
NC programming
450
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Meaning
<any_type>:
Variable, type CHAR, BOOL, INT, REAL or STRING
<< :
Operator to chain variables (<any_type>) to configure a character string (type
STRING).
This operator is also available alone as a so-called "unary" variant. This can be used for
explicit type converter to STRING (not for FRAME and AXIS):
<< <any_type>
For example, such a message or a command can be configured from text lists and parameters
can be inserted (for example a block name):
MSG(STRG_TAB[LOAD_IDX]<<BLOCK_NAME)
Note
The intermediate results of string concatenation must not exceed the maximum string length.
Note
The FRAME and AXIS types cannot be used together with the operator "<<".
Examples
Example 1: Concatenation of strings
Program code
Comment
DEF INT IDX=2
DEF REAL VALUE=9.654
DEF STRING[20] STRG="INDEX:2"
IF STRG=="Index:"<<IDX GOTOF NO_MSG
MSG("Index:"<<IDX<<"/value:"<<VALUE)
; Display:
"Index:2/value:9.654"
NO_MSG:
Example 2: Explicit type conversion with <<
Program code
Comment
DEF REAL VALUE=3.5
<<VALUE
; The specified REAL type variable is converted into a
STRING type.
3.1.4.4
Conversion to lower/upper case letters (TOLOWER, TOUPPER)
The "conversion to lowercase/uppercase letters" function allows all of the letters of a string to be
converted into a standard representation.
Syntax
<STRING_RES>=TOUPPER("<string>")
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
451
Work preparation
3.1 Flexible NC programming
<STRING_RES>=TOLOWER("<string>")
Meaning
TOUPPER:
Using the TOUPPER command, all of the letters in a character string are con-
verted into uppercase letters.
TOLOWER:
Using the TOLOWER command, all of the letters in a character string are con-
verted into lowercase letters.
<string>:
Character string that is to be converted
Type:
STRING
<STRING_RES>:
Variable for the result of the conversion
Type:
STRING
Example
Because user inputs can be initiated on the user interface, they can be given standard
capitalization (uppercase or lowercase):
Program code
DEF STRING [29] STRG
IF "LEARN.CNC"==TOUPPER(STRG) GOTOF LOAD_LEARN
3.1.4.5
Determine length of string (STRLEN)
The STRLEN command determines the length of a character string.
Syntax
<INT_RES>=STRLEN("<STRING>")
Meaning
STRLEN:
The STRLEN command determines the length of the specified character string.
The number of characters that are not the 0 character, counting from the beginning
of the string is returned.
<string>:
Character string whose length is to be determined
Type:
STRING
<INT_RES>:
Variable for the result of the determination
Type:
INT
NC programming
452
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Example
In conjunction with the single character access, this function allows the end of a character string
to be determined:
Program code
IF (STRLEN(BLOCK_NAME)>10) GOTOF ERROR
3.1.4.6
Search for character/string in the string (INDEX, RINDEX, MINDEX, MATCH)
This functionality searches for single characters or a string within a string. The function results
specify where the character/string is positioned in the string that has been searched.
Syntax
INT_RES=INDEX(STRING,CHAR) ; Result type: INT
INT_RES=RINDEX(STRING,CHAR) ; Result type: INT
INT_RES=MINDEX(STRING,STRING) ; Result type: INT
INT_RES=MINDEX(STRING,STRING) ; Result type: INT
Semantics
Search functions: It supplies the position in the string (first parameter) where the search has
been successful. If the character/string cannot be found, then the value -1 is returned. The first
character has position 0.
Meaning
INDEX:
Searches for the character specified as second parameter (from the beginning) in the
first parameter.
RINDEX:
Searches for the character specified as second parameter (from the end) in the first
parameter.
MINDEX:
Corresponds to the INDEX function, except for the case that a list of characters is trans-
ferred (as string) in which the index of the first found character is returned.
MATCH:
Searches for a string in a string.
This allows strings to be broken up according to certain criteria, for example, at positions with
blanks or path separators ("/").
Example
Breaking up an input into path and block names
Program code
Comment
DEF INT PFADIDX, PROGIDX
DEF STRING[26] INPUT
DEF INT LISTIDX
INPUT = "/_N_MPF_DIR/_N_EXECUTE_MPF"
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
453
Work preparation
3.1 Flexible NC programming
Program code
Comment
LISTIDX = MINDEX (INPUT, "M,N,O,P")
; The value returned in LISTIDX is 3; because
+ 1
"N" is the first character in the parameter IN-
PUT from the selection list starting from the
beginning.
PFADIDX = INDEX (INPUT, "/") +1
; Therefore the following applies: PFADIDX = 1
PROGIDX = RINDEX (INPUT, "/") +1
; Therefore the following applies: PROGIDX = 12
; The SUBSTR function introduced in the next
section can be used to break-up
variable INPUT into the components "path" and
"module":
VARIABLE = SUBSTR (INPUT,
; Then returns "_N_MPF_DIR"
PFADIDX, PROGIDX-PFADIDX-1)
VARIABLE = SUBSTR (INPUT, PROGIDX)
; Then returns "_N_EXECUTE_MPF"
3.1.4.7
Selection of a substring (SUBSTR)
Arbitrary parts within a string can be read with the SUBSTRING function.
Syntax
<STRING_RES>=SUBSTR(<string>,<index>,<length>)
<STRING_RES>=SUBSTR(<string>,<index>)
Meaning
SUBSTR:
This function returns a substring from <string>, starting with <index> with the speci-
fied <length>.
If the parameter <length> is not specified, the function returns a substring starting
with <index> until the end of the string.
<index>:
Start position of the substring within the string. If the start position is after the end of
the string, an empty string (" ") is returned. First character of the string: Index = 0
Range of values: 0 ... (string length - 1)
<length>:
Length of the substring. If too long a length is specified, only the substring up to the
end of the string is returned.
Range of values: 1 ... (string length - 1)
Example
Program code
Comment
DEF STRING[29] RES
;
1
;
0123456789012345678
RES = SUBSTR("QUITTUNG: 10 to 99", 10, 2)
; RES == "10"
RES = SUBSTR("QUITTUNG: 10 to 99", 10)
; RES == "10 to 99"
NC programming
454
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
3.1.4.8
Reading and writing of individual characters
Individual characters can be read and written within a string.
The following supplementary conditions must be observed:
• Only possible with user-defined variables, not with system variables
• Individual characters of a string are only transferred "call by value" for subprogram calls
Syntax
<Character>=<string>[<index>]
<Character>=<string_array>[<array_index>,<index>]
<String>[<index>]=<character>
<String_array>[<array_index>,<index>]=<character>
Meaning
<string>:
Any string
<character>:
Variable of type CHAR
<index>:
Position of the character within the string.
First character of the string: Index = 0
Range of values: 0 ... (string length - 1)
Examples
Example 1: Variable message
Program code
Comment
;
0123456789
DEF STRING [50] MESSAGE = "Axis n has reached position"
MESSAGE [6] = "X"
MSG (MESSAGE)
; "Axis X has reached position"
Example 2: Evaluating a system variable
Program code
Comment
DEF STRING[50] STRG
; Buffer for system variable
STRG = $P_MMCA
; Load system variable
IF STRG[0] == "E" GOTO ...
; Evaluating the system variable
Example 3: Parameter transfer "call by value" and "call by reference"
Program code
Comment
;
0123456
DEF STRING[50] STRG = "Axis X"
DEF CHAR CHR
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
455
Work preparation
3.1 Flexible NC programming
Program code
Comment
EXTERN UP_VAL(ACHSE)
; Definition of subprogram with "call
by value" parameters
EXTERN UP_REF(VAR ACHSE)
; Definition of subprogram with "call
by reference" parameters
UP_VAL(STRG[6])
; Parameter transfer "by value"
CHR = STRG[6]
; Buffer
UP_REF(CHR)
; Parameter transfer "by reference"
3.1.4.9
Formatting a string (SPRINT)
Using the pre-defined SPRINT function, character strings can be formatted and e.g. prepared for
output on external devices (also see "Process DataShare - Output to an external device/file
(EXTOPEN, WRITE, EXTCLOSE): (Page 1001)").
Syntax
"<Result_string>"=SPRINT("<Format_string>",<value_1>,<value_2>,...,
<value_n>)
Meaning
SPRINT:
Identifier for a pre-defined function that supplies a val-
ue, type STRING.
"<Format_String>":
Character string that contains fixed and variable ele-
ments. The variable elements are defined using the
format control character % and a subsequent format
description.
< value_1>,< value_2>,…,< value_n>:
Value in the form of a constant or NC variables, which
is inserted at the location where the nth format control
character % is located, corresponding to the format
description in the <format_string>.
"<result_string>":
Formatted character string (maximum 400 bytes)
NC programming
456
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Format descriptions available
%B:
Conversion into the "TRUE" string, if the value to be converted:
• Is not equal to 0.
• Is not an empty string (for string values).
Conversion into the "FALSE" string, if the value to be converted:
• Is equal to 0.
• Is an empty string.
Example:
N10 DEF BOOL BOOL_VAR=1
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF BOOL_VAR:%B", BOOL_VAR)
Result: The character string "CONTENT OF BOOL_VAR:TRUE" is written to the RESULT
string variable.
%C:
Conversion into an ASCII character.
Example:
N10 DEF CHAR CHAR_VAR="X"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF CHAR_VAR:%C",CHAR_VAR)
Result: The character string "CONTENT OF CHAR_VAR:X is written to the string variable
RESULT.
%D:
Conversion into a string with an integer value (INTEGER).
Example:
N10 DEF INT INT_VAR=123
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF INT_VAR:%D",INT_VAR)
Result: The character string "CONTENT OF INT_VAR:123" is written to the string vari-
able RESULT.
%<m>D:
Conversion into a string with an integer value (INTEGER). The string has a minimum
length of <m> characters. The missing locations are filled with spaces, left-justified.
Example:
N10 DEF INT INT_VAR=-123
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF INT_VAR:%6D",INT_VAR)
Result: The character string "CONTENT OF INT_VAR:xx-123" is written to string variable
RESULT ("x" in the example represents spaces).
%F:
Conversion into a string with a decimal number with 6 decimal places. Where relevant,
the decimal places are rounded-off or filled with 0.
Example:
N10 DEF REAL REAL_VAR=-1.2341234EX+03
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%F",REAL_VAR)
Result: The string variable RESULT is written with the character string "CONTENT OF
REAL_VAR: -1234.123400".
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
457
Work preparation
3.1 Flexible NC programming
%<m>F:
Conversion into a string with a decimal number with 6 decimal places and a total
length of at least <m> characters. Where relevant, the decimal places are rounded-off
or filled with 0. Missing characters are filled up to the total length <m> using spaces,
left-justified.
Example:
N10 DEF REAL REAL_VAR=-1.23412345678EX+03
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%15F",REAL_VAR)
Result: The string variable RESULT is written with the character string "CONTENT OF
REAL_VAR: xxx-1234.123457" (where "x" is a placeholder for space).
%.<n>F:
Conversion into a string with a decimal number with <n> decimal places. Where rel-
evant, the decimal places are rounded-off or filled with 0.
Example:
N10 DEF REAL REAL_VAR=-1.2345678EX+03
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%.3F",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:-1234.568" is written to the
string variable RESULT.
%<m>.<n>F:
Conversion into a string with a decimal number with <n> decimal places and a total
length of at least <m> characters. Where relevant, the decimal places are rounded-off
or filled with 0. Missing characters are filled up to the total length <m> using spaces,
left-justified.
Example:
N10 DEF REAL REAL_VAR=-1.2341234567890EX+03
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%10.2F",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xx-1234.12" is written to the
string variable RESULT ("x" in the example represents spaces).
%E:
Conversion into a string with a decimal number in the exponential representation. The
mantissa is saved, normalized with one pre-decimal place and 6 decimal places. Where
relevant, the decimal places are rounded-off or filled with 0. The exponent starts with
the keyword "EX". It is followed by the sign ("+" or "-") and a two or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.567890
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%E",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:-1.234568EX+03" is written to
the string variable RESULT.
%<m>E:
Conversion into a string with a decimal number in the exponential representation and
a total length of at least <m> characters. The missing characters are filled with spaces,
left-justified. The mantissa is saved, normalized with one pre-decimal place and 6
decimal places. Where relevant, the decimal places are rounded-off or filled with 0. The
exponent starts with the keyword "EX". It is followed by the sign ("+" or "-") and a two
or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%20E",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxxxxx-1.234500EX+03" is writ-
ten to the string variable RESULT ("x" in the example represents spaces).
NC programming
458
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
%.<n>E:
Conversion into a string with a decimal number in the exponential representation. The
mantissa is saved, normalized with one pre-decimal place and <n> decimal places.
Where relevant, the decimal places are rounded-off or filled with 0. The exponent
starts with the keyword "EX". It is followed by the sign ("+" or "-") and a two or three-
digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5678
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%.2E",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:-1.23EX+03" is written to the
string variable RESULT.
%<m>.<n>E:
Conversion into a string with a decimal number in the exponential representation and
a total length of at least <m> characters. The missing characters are filled with spaces,
left-justified. The mantissa is saved, normalized with one pre-decimal place and <n>
decimal places. Where relevant, the decimal places are rounded-off or filled with 0. The
exponent starts with the keyword "EX". It is followed by the sign ("+" or "-") and a two
or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5678
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%12.2E", REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xx-1.23EX+03" is written to the
string variable RESULT ("x" in the example represents spaces).
%G:
Conversion into a string with a decimal number - depending on the value range - in
a decimal or exponential representation: If the absolute value to be represented is less
than 1.0EX-04 or greater than/equal to 1.0EX+06, then the exponential notation is
selected, otherwise the decimal notation. A maximum of six significant places are
displayed or if required, rounded-off.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:0.000123457" is written to the
string variable RESULT.
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+06
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:1.23457EX+06" is written to the
string variable RESULT.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
459
Work preparation
3.1 Flexible NC programming
%<m>G:
Conversion into a string with a decimal number - depending on the value range - in
a decimal or exponential notation (like %G). The string has a total length of at least <m>
characters. The missing characters are filled with spaces, left-justified.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%15G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxxx0.000123457" is written to
the string variable RESULT ("x" in the example represents spaces).
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+06
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%15G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxx1.23457EX+06" is written to
the string variable RESULT ("x" in the example represents spaces).
%.<n>G:
Conversion into a string with a decimal number - depending on the value range - in
a decimal or exponential representation. A maximum of <n> significant places are
displayed or if required, rounded-off. If the absolute value to be represented is less than
1.0EX-04 or greater than/equal to 1.0EX(+<n>), then the exponential notation is se-
lected, otherwise the decimal notation.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%.3G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:0.000123" is written to the string
variable RESULT.
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+03
N20 DEF STRING[80] RESULT
N30 RESULT = SPRINT("CONTENT OF REAL_VAR:%.3G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:1.23EX+03" is written to the
string variable RESULT.
%<m>.<n>G:
Conversion into a string with a decimal number - depending on the value range - in
a decimal or exponential notation (like %.<n>G). The string has a total length of at
least <m> characters. The missing characters are filled with spaces, left-justified.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%12.4G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxx0.0001235" is written to the
string variable RESULT ("x" in the example represents spaces).
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%12.4G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xx1.235EX+06" is written to the
string variable RESULT ("x" in the example represents spaces).
NC programming
460
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
%.<n>P:
Converting a REAL value into an INTEGER value taking into account <n> decimal pla-
ces. The INTEGER value is output as a 32-bit binary number. If the value to be converted
cannot be represented with 32 bits, then processing is interrupted with an alarm.
As a byte sequence generated using the format statement %.<n>P can also contain
binary zeroes, then the total string that is generated in this way no longer corresponds
to the conventions of the NC data type STRING. As a consequence, it can neither be
saved in a variable, type STRING, nor be further processed using the string commands
of the NC language. The only possible use is to transfer the parameter to the WRITE
command with output at an appropriate external device (see the following example).
As soon as the <Format_String> contains a format description, type %P then the com-
plete string, with the exception of the binary number generated with %.<n>P, is
output corresponding to the MD10750 $MN_SPRINT_FORMAT_P_CODE in the ASCII
character code, ISO (DIN6024) or EIA (RS244). If a character that cannot be converted
is programmed, then processing is interrupted with an alarm.
Example:
N10 DEF REAL REAL_VAR=123.45
N20 DEF INT ERROR
N30 DEF STRING[20] EXT_DEVICE="/ext/dev/1"
N100 EXTOPEN(ERROR,EXT_DEVICE)
N110 IF ERROR <> 0
; error handling
N200 WRITE(ERROR,EXT_DEVICE,SPRINT("INTEGER BINARY
CODED:%.3P",REAL_VAR)
N210 IF ERROR <> 0
… ; error handling
Result: The string "INTEGER BINARY CODED: 'H0001E23A'" is transferred to the output
device /ext/dev/1. The hexadecimal value 0x0001E23A corresponds to the decimal
value 123450.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
461
Work preparation
3.1 Flexible NC programming
%<m>.<n>P:
Conversion of a REAL value corresponding to the setting in machine data
MD10751 $MN_SPRINT_FORMAT_P_DECIMAL into a string with:
• An integer of <m> + <n> places or
• A decimal number with a maximum of <m> pre-decimal places and precisely <n>
decimal places.
Just the same as for the format description %.<n>P, the complete string is saved in the
character code defined by MD10750 $MN_SPRINT_FORMAT_P_CODE.
Conversion for MD10751 = 0:
The REAL value is converted into a string with an integer number of <m> + <n> places.
If required, decimal places are rounded-off to <n> places or filled with 0. The missing
pre-decimal places are filled with spaces. The minus sign is attached, left-justified; a
space is entered instead of the plus sign.
Example:
N10 DEF REAL REAL_VAR=-123.45
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("PUNCHED TAPE FORMAT:%5.3P",REAL_VAR)
Result: The character string "PUNCHED TAPE FORMAT:-xx123450" is written to the
string variable RESULT ("x" in the example represents spaces).
Conversion for MD10751 = 1:
The REAL value is converted into a string with a decimal number with a maximum of
<m> pre-decimal places and precisely <n> decimal places. Where necessary, the pre-
decimal places are cut-off and the decimal places are rounded-off or filled with 0. If <n>
is equal to 0, then the decimal point is also omitted.
Example:
N10 DEF REAL REAL_VAR1=-123.45
N20 DEF REAL REAL_VAR2=123.45
N30 DEF STRING[80] RESULT
N40 RESULT=SPRINT("PUNCHED TAPE FORMAT:%5.3P VAR2:%2.0P",
REAL_VAR1,REAL_VAR2)
Result: The character string "PUNCHED TAPE FORMAT:-123.450 VAR2:23" is written to
the string variable RESULT.
%S:
Inserting a string.
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%S",STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:ABCDEFG" is written to the
string variable RESULT.
%<m>S:
Inserting a string with a minimum of <m> characters. The missing places are filled with
spaces.
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%10S",STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:xxxABCDEFG" is written to the
string variable RESULT ("x" in the example represents spaces).
NC programming
462
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
%.<n>S:
Inserting <n> characters of a string (starting with the first character).
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%.3S",STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:ABC" is written to the string
variable RESULT.
%<m>.<n>S:
Inserting <n> characters of a string (starting with the first character). The total length
of the generated string has at least <m> characters. The missing places are filled with
spaces.
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%10.5S", STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:xxxxxABCDE" is written to the
string variable RESULT ("x" in the example represents spaces).
%X:
Converting an INTEGER value into a string with the hexadecimal notation.
Example:
N10 DEF INT INT_VAR='HA5B8’
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("INTEGER HEXADECIMAL:%X",INT_VAR)
Result: The character string "INTEGER HEXADECIMAL:A5B8" is written to the string
variable RESULT.
Note
A property of the NC language, where a distinction is not made between uppercase and
lowercase letters for identifiers and keywords, also applies to the format descriptions. As a
consequence, you can program using either lowercase or uppercase letters without any
functional difference.
Combination options
The following table provides information as to which NC data types can be combined with which
format description. The rules regarding implicit data type conversion apply (see "Data types
(Page 424)").
NC data types
BOOL
CHAR
INT
REAL
STRING
AXIS
FRAME
%B
+
+
+
+
+
-
-
%C
-
+
-
-
+
-
-
%D
+
+
+
+
-
-
-
%F
-
-
+
+
-
-
-
%E
-
-
+
+
-
-
-
%G
-
-
+
+
-
-
-
%S
-
+
-
-
+
-
-
%X
+
+
+
-
-
-
-
%P
-
-
+
+
-
-
-
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
463
Work preparation
3.1 Flexible NC programming
Note
The table indicates that the NC data types AXIS and FRAME cannot be directly used in the SPRINT
function. However it is possible:
• To convert the AXIS data type into a string using the AXSTRING function - which can then be
processed with SPRINT.
• To read the individual values of the FRAME data type per frame component access. As a
consequence, a REAL data type is obtained, which can be processed with SPRINT.
3.1.5
Program jumps and branches
3.1.5.1
Return jump to the start of the program (GOTOS)
The GOTOS command can be used to jump back to the beginning of a main or subprogram in
order to repeat the program.
Machine data can be used to set that for every return jump is made to the program start:
• The program runtime is set to "0".
• Workpiece counting is incremented by the value "1".
Syntax
GOTOS
Meaning
GOTOS:
Jump statement where the destination is the beginning of the program.
The execution is controlled via the NC/PLC interface signal:
DB21, to DBX384.0 (control program branching)
Value:
Meaning:
0
No return jump to the beginning of the program. Program execution is re-
sumed with the next part program block after GOTOS.
1
Return jump to the beginning of the program. The part program is repeated.
Supplementary conditions
• GOTOS internally initiates a STOPRE (pre-processing stop).
• For a subprogram with data definitions (LUD variables) with the GOTOS, a jump is made to the
first program block after the definition section, i.e. data definitions are not executed again.
This is the reason that the defined variables retain the value reached in the GOTOS block and
are not reset to the standard values programmed in the definition section.
• The GOTOS command is not available in synchronized actions and technology cycles.
NC programming
464
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Example
Program code
Comment
N10 ...
; Start of the program.
N90 GOTOS
; Jump to beginning of the program.
3.1.5.2
Program jumps to jump markers (GOTOB, GOTOF, GOTO, GOTOC)
Jump labels can be set in a program, which can be jumped to from another location within the
same program using the commands GOTOF, GOTOB, GOTO, or GOTOC. Program execution is
resumed with the statement that immediately follows the jump label. This means that branches
can be realized within the program.
In addition to jump labels, main and sub-block numbers are possible as jump designation.
If a jump condition (IF ...) is formulated before the jump statement, the program jump is only
executed if the jump condition is fulfilled.
Syntax
GOTOB <jump destination>
IF <jump condition> == TRUE GOTOB <jump destination>
GOTOF <jump destination>
IF <jump condition> == TRUE GOTOF <jump destination>
GOTO <jump destination>
IF <jump condition> == TRUE GOTO <jump destination>
GOTOC <jump destination>
IF <jump condition> == TRUE GOTOC <jump destination>
Meaning
GOTOB:
Jump statement with jump destination toward the beginning of the program.
GOTOF:
Jump statement with jump destination toward the end of the program.
GOTO:
Jump statement with jump destination search. The search is first made in the
direction of the end of the program, then in the direction of the beginning of the
program.
GOTOC:
Same effect as for GOTO with the difference that Alarm 14080 "Jump designation
not found" is suppressed.
This means that program execution is not interrupted in the case that the jump
destination search is unsuccessful - but is continued with the program line fol-
lowing the GOTOC command.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
465
Work preparation
3.1 Flexible NC programming
<jump
Jump destination parameter
destination>:
Possible data include:
<jump label>:
Jump destination is the jump label set in the program
with a user-defined name:<jump label>:
<block number>:
Jump destination is main block or sub-block number
(e.g.: 200, N300)
STRING type variable:
Variable jump destination. The variable stands for a
jump label or a block number.
IF:
Keyword to formulate the jump condition.
The jump condition permits all comparison and logical operations (result: TRUE or
FALSE). The program jump is executed if the result of this operation is TRUE.
Note
Jump labels
Jump labels are always located at the beginning of a block. If a program number exists, the jump
label is located immediately after the block number.
The following rules apply when naming jump labels:
• Number of characters:
- Minimum 2
- Maximum 32
• Permissible characters are:
- Letters
- Numbers
- Underscores
• The first two characters must be letters or underscores.
• The name of the jump label is followed by a colon (":").
Supplementary conditions
• The jump destination can only be a block with jump label or block number that is
located within the program.
• A jump statement without jump condition must be programmed in a separate block. This
restriction does not apply to jump statements with jump conditions. In this case, several jump
statements can be formulated in a block.
• For programs with jump statements without jump conditions, the end of the program M2/
M30 does not necessarily be at the end of the program.
Examples
Example 1: Jumps to jump labels
Program code
Comment
N10 …
NC programming
466
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Program code
Comment
N20 GOTOF Label_1
; Jump toward end of program to
; jump label "Label_1".
N30 …
N40 Label_0: R1=R2+R3
; Jump label "Label_0" set.
N50 …
N60 Label_1:
; Jump label "Label_1" set.
N70 …
N80 GOTOB Label_0
; Jump toward beginning of program
; to the jump label "Label_0."
N90 …
Example 2: Indirect jump to the block number
Program code
Comment
IF <condition> == TRUE
R10=100
; Assign jump destination
ELSE
R10=110
; Assign jump destination
ENDIF
; Jump toward end of program to the block whose block number is located in R10
N10 GOTOF "N"<<R10
N90 ...
N100 ...
; Jump destination
N110 ...
Example 3: Jump to variable jump destination
Program code
Comment
DEF STRING[20] DESTINATION
IF <condition> == TRUE
DESTINATION = "Label1"
; Assign jump destination
ELSE
DESTINATION = “Label2"
; Assign jump destination
ENDIF
; Jump toward end of program to the variable jump destination "Content of DESTINA-
TION."
GOTOF DESTINATION
Label1: T="Drill1"
; Jump destination 1
Label2: T="Drill2"
; Jump destination 2
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
467
Work preparation
3.1 Flexible NC programming
Example 4: Jump with jump condition
Program code
Comment
N40 R1=30 R2=60 R3=10 R4=11 R5=50 R6=20
; Assignment of the initial values
N41 LA1: G0 X=R2*COS(R1)+R5 Y=R2*SIN(R1)+R6
; Jump label LA1
N42 R1=R1+R3 R4=R4-1
; IF jump condition == TRUE
; THEN jump toward beginning of program to the jump label LA1
N43 IF R4>0 GOTOB LA1
N44 M30
; End of program
3.1.5.3
Program branch (CASE ... OF ... DEFAULT ...)
The CASE function provides the possibility of checking the actual value (type: INT) of a variable
or an arithmetic function and, depending on the result, to jump to different positions in the
program.
Syntax
CASE(<expression>) OF <constant_1> GOTOF <jump target_1>
<constant_2> GOTOF <jump target_2> ... DEFAULT GOTOF <jump target_n>
Meaning
CASE:
Jump statement
<expression>:
Variable or arithmetic function
OF:
Keyword to formulate conditional program branches.
<constant_1>:
First specified constant value for the variable or arithmetic function
Type:
INT
<constant_2>:
Second specified constant value for the variable or arithmetic function
Type:
INT
DEFAULT:
For the cases where the variable or arithmetic function does not assume any
of the specified constant values, the DEFAULT statement can be used to
determine the jump target.
Note:
If the DEFAULT statement is not programmed, then in these cases, the block
following the CASE statement is the jump target.
GOTOF:
Jump statement with jump target towards the end of the program.
Instead of GOTOF all other GOTO commands can be programmed (refer to
the subject "Program jumps to jump markers").
NC programming
468
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
<jump target_1>:
A branch is made to this jump target if the value of the variable or arithmetic
function corresponds to the first specific constant.
The jump target can be specified as follows:
<jump marker>:
Jump target is the jump marker (label) set in the
program with a user-defined name: <jump
marker>:
<block number>:
Jump target is main block or sub-block number
(e.g.: 200, N300)
STRING type variable:
Variable jump target. The variable stands for a jump
marker or a block number.
<jump target_2>:
A branch is made to this jump target if the value of the variable or arithmetic
function corresponds to the second specified constant.
<jump target_n>:
A branch is made to this jump target if the value of the variable does not
assume the specified constant value.
Example
Program code
N20 DEF INT VAR1 VAR2 VAR3
N30 CASE(VAR1+VAR2-VAR3) OF 7 GOTOF Label_1 9 GOTOF La-
bel_2 DEFAULT GOTOF Label_3
N40 Label_1: G0 X1 Y1
N50 Label_2: G0 X2 Y2
N60 Label_3: G0 X3 Y3
The CASE statement from N30 defines the following program branch possibilities:
1. If the value of the arithmetic function VAR1+VAR2-VAR3 = 7, then jump to the block with the
jump marker definition "Label_1" (→ N40).
2. If the value of the arithmetic function VAR1+VAR2-VAR3 = 9, then jump to the block with the
jump marker definition "Label_2" (→ N50).
3. If the value of the arithmetic function VAR1+VAR2-VAR3 is neither 7 nor 9, then jump to the
block with the jump marker definition "Label_3" (→ N60).
3.1.6
Repeat program section (REPEAT, REPEATB, ENDLABEL, P)
Program section repetition allows you to repeat existing program sections within a program in
any order.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
469
Work preparation
3.1 Flexible NC programming
The program lines or program sections to be repeated are identified by jump markers (labels).
Note
Jump markers (labels)
Jump markers are always located at the beginning of a block. If a program number exists, the
jump marker is located immediately after the block number.
The following rules apply when naming jump markers:
• Number of characters:
- Minimum 2
- Maximum 32
• Permissible characters are:
- Letters
- Numbers
- Underscores
• The first two characters must be letters or underscores.
• The name of the jump marker is followed by a colon (":").
Syntax
1. Repeat individual program line:
<jump marker>: ...
REPEATB <jump marker> P=<n>
2. Repeat program section between jump marker and REPEAT statement:
<jump marker>: ...
REPEAT <jump marker> P=<n>
3. Repeat section between two jump markers:
<start jump marker>: ...
<end jump marker>: ...
REPEAT <start jump marker> <end jump marker> P=<n>
NC programming
470
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Note
It is not possible to nest the REPEAT statement with the two jump markers in parentheses. If
the <start jump marker> appears before the REPEAT statement and the <end jump
marker> is not reached before the REPEAT statement, the section between the <start
jump marker> and the REPEAT statement will be repeated.
4. Repeat section between jump marker and ENDLABEL:
<jump marker>: ...
ENDLABEL: ...
REPEAT <jump marker> P=<n>
Note
It is not possible to nest the REPEAT statement with the <jump marker> and the ENDLABEL in
parentheses. If the <jump marker> appears before the REPEAT statement and the ENDLABEL
is not reached before the REPEAT statement, the section between the <jump marker> and
the REPEAT statement will be repeated.
Meaning
REPEATB:
Command for repeating a program line
REPEAT:
Command for repeating a program section
<jump marker>:
The <jump marker> identifies:
• The program line to be repeated (in the case of REPEATB)
or
• The start of the program section to be repeated (in the case of REPEAT)
The program line identified by the <jump marker> can appear before or after
the REPEAT/REPEATB statement. The search initially commences toward the
start of the program. If the jump marker is not found in this direction, the search
continues working toward the end of the program.
Exception:
If the program section between the jump marker and the REPEAT statement
needs to be repeated (see 2. under Syntax), the program line identified by
the <jump marker> has to appear before the REPEAT statement, since in
this case the search runs only toward the beginning of the program.
If the line with the <jump marker> contains further operations, these are
executed again on each repetition.
ENDLABEL:
Keyword marking the end of a program section to be repeated.
If the line with the ENDLABEL contains further operations, these are executed
again on each repetition.
ENDLABEL can be used more than once in the program.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
471
Work preparation
3.1 Flexible NC programming
P:
Address for specifying the number of repetitions
<n>:
Number of program section repetitions
Type:
INT
The program section to be repeated is repeated <n> times. After the last rep-
etition, the program is resumed at the line following the REPEAT/REPEATB
line.
Note:
In the absence of a number being specified for P=<n>, the program section is
repeated just once.
Examples
Example 1: Repeat individual program line
Program code
Comment
N10 POSITION1: X10 Y20
N20 POSITION2: CYCLE(0,,9,8)
;Position cycle
N30 ...
N40 REPEATB POSITION1 P=5
; Execute BLOCK N10 five times.
N50 REPEATB POSITION2
; Execute block N20 once.
N60 ...
N70 M30
Example 2: Repeat program section between jump marker and REPEAT statement:
Program code
Comment
N5 R10=15
N10 Begin: R10=R10+1
;Width
N20 Z=10-R10
N30 G1 X=R10 F200
N40 Y=R10
N50 X=-R10
N60 Y=-R10
N70 Z=10+R10
N80 REPEAT BEGIN P=4
; Execute section from N10 to N70 four times.
N90 Z10
N100 M30
Example 3: Repeat section between two jump markers
Program code
Comment
N5 R10=15
N10 Begin: R10=R10+1
;Width
N20 Z=10-R10
N30 G1 X=R10 F200
N40 Y=R10
N50 X=-R10
NC programming
472
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Program code
Comment
N60 Y=-R10
N70 END: Z=10
N80 Z10
N90 CYCLE(10,20,30)
N100 REPEAT BEGIN END P=3
; Execute section from N10 to N70 three times.
N110 Z10
N120 M30
Example 4: Repeat section between jump marker and ENDLABEL
Program code
Comment
N10 G1 F300 Z-10
N20 BEGIN1:
N30 X10
N40 Y10
N50 BEGIN2:
N60 X20
N70 Y30
N80 ENDLABEL: Z10
N90 X0 Y0 Z0
N100 Z-10
N110 BEGIN3: X20
N120 Y30
N130 REPEAT BEGIN3 P=3
; Execute section from N110 to N120 three times.
N140 REPEAT BEGIN2 P=2
; Execute section from N50 to N80 twice.
N150 M100
N160 REPEAT BEGIN1 P=2
; Execute section from N20 to N80 twice.
N170 Z10
N180 X0 Y0
N190 M30
Example 5: Milling, machine drill position with different technologies
Program code
Comment
N10 CENTER DRILL()
; Load centering drill.
N20 POS_1:
;Drilling positions 1
N30 X1 Y1
N40 X2
N50 Y2
N60 X3 Y3
N70 ENDLABEL:
N80 POS_2:
;Drilling positions 2
N90 X10 Y5
N100 X9 Y-5
N110 X3 Y3
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
473
Work preparation
3.1 Flexible NC programming
Program code
Comment
N120 ENDLABEL:
N130 DRILL()
; Change drill and drilling cycle.
N140 THREAD(6)
; Load tap M6 and threading cycle.
N150 REPEAT POS_1
; Repeat program section once from POS_1 up to ENDLABEL.
N160 DRILL()
; Change drill and drilling cycle.
N170 THREAD(8)
; Load tap M8 and threading cycle.
N180 REPEAT POS_2
; Repeat program section once from POS_2 up to ENDLABEL.
N190 M30
Further information
• Program section repetitions can be nested. Each call uses a subprogram level.
• If M17 or RET is programmed during processing of a program section repetition, the
repetition is canceled. The program is resumed at the block following the REPEAT line.
• In the actual program display, the program section repetition is displayed as a separate
subprogram level.
• If the level is canceled during the program section repetition, the program resumes at the
point after the program section repetition call.
Example:
Program code
Comments
N5 R10=15
N10 BEGIN: R10=R10+1
;Width
N20 Z=10-R10
N30 G1 X=R10 F200
N40 Y=R10
; Interrupt level
N50 X=-R10
N60 Y=-R10
N70 END: Z10
N80 Z10
N90 CYCLE(10,20,30)
N100 REPEAT BEGIN END P=3
N120 Z10
; Resume program execution.
N130 M30
• Check structures and program section repetitions can be used in combination. There should
be no overlap between the two, however. A program section repetition should appear within
a check structure branch or a check structure should appear within a program section
repetition.
• If jumps and program section repetitions are mixed, the blocks are executed purely
sequentially. For example, if a jump is performed from a program section repetition,
processing continues until the programmed end of the program section is found.
Example:
NC programming
474
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Program code
N10 G1 F300 Z-10
N20 BEGIN1:
N30 X=10
N40 Y=10
N50 GOTOF BEGIN2
N60 ENDLABEL:
N70 BEGIN2:
N80 X20
N90 Y30
N100 ENDLABEL: Z10
N110 X0 Y0 Z0
N120 Z-10
N130 REPEAT BEGIN1 P=2
N140 Z10
N150 X0 Y0
N160 M30
Note
The REPEAT statement should appear after the traversing block.
3.1.7
Check structures
The control processes the NC blocks as standard in the programmed sequence.
This sequence can be variable by programming alternative program blocks and program loops.
These check structures are programmed using the key words IF, ELSE, ENDIF, LOOP, FOR, WHILE
and REPEAT.
NOTICE
Programming error
Check structures may only be inserted in the statement section of a program. Definitions in the
program header may not be executed conditionally or repeatedly.
It is not permissible to superimpose macros on keywords for check structures or on jump
targets. No such check is made when the macro is defined.
Effectiveness
The check structure cannot be used program-wide.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
475
Work preparation
3.1 Flexible NC programming
Nesting depth
A nesting depth of up to 16 check structures can be set up on each subprogram level.
Main program
Subprogram
PROC SUBPROG
LOOP
REPEAT
FOR
WHILE
FOR
IF
WHILE
ENDIF
ENDWHILE
WHILE
WHILE
ENDWHILE
SUBPROG
ENDFOR
ENDWHILE
ENDFOR
ENDWHILE
UNTIL
ENDLOOP
Runtime response
In interpreter mode (active as standard), it is possible to shorten program processing times more
effectively by using program branches than can be obtained with check structures.
There is no difference between program branches and check structures in precompiled cycles.
Current block display for program loops
If only selected blocks are executed within a program loop, the last main run block before the
program loop is shown in the current block display.
So that the processed selected blocks are also visible in the current block display, e.g. for
diagnostic purposes, the decoding single block SBL2 must be activated.
Grinding without main run block
If, within a program loop, no main run block has been programmed, then the loop is pre-
processed until the loop condition is satisfied.
As a consequence, a high level of utilization can occur and this can have a negative impact on
the display.
The STOPRE command or a dwell time G04 of 0 seconds can be inserted in the loop as
countermeasure.
NC programming
476
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Supplementary conditions
• Blocks with check structure elements cannot be suppressed.
• Jumper markers (labels) are not permitted in blocks with check structure elements.
• Check structures are processed interpretively. When a loop end is detected, a search is made
for the loop beginning, allowing for the check structures found in the process. For this
reason, the block structure of a program is not checked completely in interpreter mode.
• It is not generally advisable to use a mixture of check structures and program branches.
• A check can be made to ensure that check structures are nested correctly when cycles are
preprocessed.
3.1.7.1
Conditional statement and branch (IF, ELSE, ENDIF)
Conditional statement: IF - program block - ENDIF
With a conditional statement, the program block between IF and ENDIF is only executed when
the condition is satisfied.
Branch: IF - program block_1 - ELSE - program block_2 - ENDIF
With a branch, one of two program blocks is always executed.
If the condition is satisfied, program block_1 between IF and ELSE is executed.
If the condition is not satisfied, program block_2 between ELSE and ENDIF is executed.
Note
ELSE in synchronized actions
The keyword ELSE can also be programmed in synchronized actions. Thus a synchronized action
can be expanded by actions that are to be executed if the condition is not fulfilled.
Syntax
Conditional statement
IF <condition>
Program block
; Execution with: <Condition> == TRUE
ENDIF
Branch
IF <condition>
Program block_1
; Execution with: <Condition> == TRUE
ELSE
Program block_2
; Execution with: <Condition> == FALSE
ENDIF
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
477
Work preparation
3.1 Flexible NC programming
Meaning
IF:
Introduces the conditional statement or branch.
ELSE:
Introduces the alternative program block.
ENDIF:
Marks the end of the conditional statement or branch.
<condition>:
Logical expression that is evaluated as TRUE or FALSE.
Example: Tool change subprogram
Program code
Comment
PROC L6
Tool change routine
N500 DEF INT TNR_AKTUELL
Variable for active T number
N510 DEF INT TNR_VORWAHL
Variable for preselected T number
Determine current tool
N520 STOPRE
N530 IF $P_ISTEST
In the program test mode ...
N540
TNR_AKTUELL = $P_TOOLNO
... the "current" tool is read
from the program context.
N550 ELSE
Otherwise ...
N560
TNR_AKTUELL = $TC_MPP6[9998,1]
... the tool of the spindle is
read-out.
N570 ENDIF
N580 GETSELT(TNR_VORWAHL)
Read the T number of the pre-se-
lected tool in the spindle.
N590 IF TNR_AKTUELL <> TNR_VORWAHL
If the pre-selected tool is
still not the current tool,
then ...
N600
G0 G40 G60 G90 SUPA X450 Y300 Z300 D0
... Approach tool change posi-
tion ...
N610 M206
... and perform a tool change.
N620 ENDIF
N630 M17
3.1.7.2
Continuous program loop (LOOP, ENDLOOP)
Endless loops are used in endless programs. At the end of the loop, there is always a branch back
to the beginning.
Syntax
LOOP
ENDLOOP
NC programming
478
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Meaning
LOOP:
Initiates the endless loop.
ENDLOOP:
Marks the end of the loop and results in a return jump to the beginning of the loop.
Example
Program code
LOOP
MSG ("no tool cutting edge active")
M0
STOPRE
ENDLOOP
3.1.7.3
Count loop (FOR ... TO ..., ENDFOR)
The count loop is used if an operation must be repeated with a fixed number of runs.
Syntax
FOR <variable> = <initial value> TO <end value>
ENDFOR
Meaning
FOR:
Initiates the count loop.
ENDFOR:
Marks the end of the loop and results in a return jump to the beginning of the
loop, as long as the end value of the count has still not been reached.
<variable>:
Count variable, which is incremented from the initial to the end value and is
increased by the value "1" at each run.
Type
INT or REAL
Note:
The REAL type is used if R parameters are programmed for a count loop,
for example. If the count variable is of the REAL type, its value is rounded
to an integer.
<initial value>:
Initial value of the count
Condition: The start value must be lower than the end value.
<full-scale
End value of the count
value>:
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
479
Work preparation
3.1 Flexible NC programming
Examples
Example 1: INTEGER variable or R parameter as count variable
INTEGER variable as count variable:
Program code
Comment
DEF INT iVARIABLE1
R10=R12-R20*R1 R11=6
FOR iVARIABLE1 = R10 TO R11
; Count variable = INTEGER variable
R20=R21*R22+R33
ENDFOR
M30
R parameter as count variable:
Program code
Comment
R11=6
FOR R10=R12-R20*R1 TO R11
; Count variable = R parameter (real variable)
R20=R21*R22+R33
ENDFOR
M30
Example 2: Production of a fixed quantity of parts
Program code
Comment
DEF INT WKPCCOUNT
; Defines type INT variable with the name
"WKPCCOUNT".
FOR WKPCCOUNT = 0 TO 100
; Initiates the count loop. The "WKPCCOUNT" vari-
able increments from the initial value "0" to the
end value "100".
G01 …
ENDFOR
; End of count loop
M30
3.1.7.4
Program loop with condition at start of loop (WHILE, ENDWHILE)
For a WHILE loop, the condition is at the beginning of the loop. The WHILE loop is executed as
long as the condition is fulfilled.
Syntax
WHILE <condition>
ENDWHILE
NC programming
480
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Meaning
WHILE:
Initiates the program loop.
ENDWHILE:
Marks the end of the loop and results in a return jump to the beginning of the loop.
<condition>:
The condition must be fulfilled so that the WHILE loop is executed.
Example
Program code
Comment
WHILE $AA_IW[DRILL_AXIS] > -10
; Call the WHILE loop under the following
condition: The actual WCS setpoint for the
drilling axis must be greater than -10.
G1 G91 F250 AX[DRILL_AXIS] = -1
ENDWHILE
3.1.7.5
Program loop with condition at the end of the loop (REPEAT, UNTIL)
For a REPEAT loop, the condition is at the end of the loop. The REPEAT loop is executed once and
repeated continuously until the condition is fulfilled.
Syntax
REPEAT
UNTIL <significance>
Meaning
REPEAT:
Initiates the program loop.
UNTIL:
Marks the end of the loop and results in a return jump to the beginning of the loop.
<condition>:
The condition that must be fulfilled so that the REPEAT loop is no longer executed.
Example
Program code
Comment
REPEAT
; Call the REPEAT loop.
UNTIL ...
; Check whether the condition is fulfilled.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
481
Work preparation
3.1 Flexible NC programming
3.1.7.6
Program example with nested check structures
Program code
Comment
LOOP
IF NOT $P_SEARCH
; IF no block search
G1 G90 X0 Z10 F1000
WHILE $AA_IM[X] <= 100
; WHILE (setpoint X axis <= 100)
G1 G91 X10 F500
; Drilling pattern
Z-5 F100
Z5
ENDWHILE
ELSE
; ELSE block search
MSG("No drilling during block search")
ENDIF
; ENDIF
$A_OUT[1] = 1
; Next drilling plate
G4 F2
ENDLOOP
M30
3.1.8
Cross-channel program coordination (INIT, START, WAITM, WAITMC, WAITE,
SETM, CLEARM)
In principle, a channel of the NC can execute the program started in it independently of other
channels in its mode group. If, however, several programs in several channels of the mode group
are involved in machining a workpiece, the program sequences in the various channels must be
coordinated with the following coordination commands.
Requirement
All the channels involved in the program coordination must belong to the same mode group:
MD10010 $MC_ASSIGN_CHAN_TO_MODE_GROUP[<Channel>] = <Mode group number>
Channel name instead of channel number
Instead of the channel numbers, the channel names entered in MD20000
$MC_CHAN_NAME[<Channel index>] can be used as parameters of the predefined procedures
for the program coordination. The use of the channel names in the NC programs first has to be
enabled:
MD10280 $MN_PROG_FUNCTION_MASK, bit 1 = TRUE
NC programming
482
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Note
Minimum distance between commands
At least two traversing block distances must be maintained between the commands INIT,
START, WAITE, WAITM, SETM, CLEARM and the command WAITMC. WAITMC is an executable
block, but is moved into the previous block for optimization, and then deleted as a block. SETM
for example is not an executable block, and is moved into the next block so that if there were a
distance of one block between two commands, both commands would be in the middle block.
As only one block is possible, optimization is not performed with a one block distance
for WAITMC.
This stops the program, and processing is briefly interrupted.
Syntax
INIT(<ChanNo>, <Prog>, <AckMode>)
START(<ChanNo>, <ChanNo>, ...)
WAITM(<MarkNo>, <ChanNo>, <ChanNo>, ...)
WAITE(<ChanNo>, <ChanNo>, ...)
WAITMC(<MarkNo>, <ChanNo>, <ChanNo>, ...)
SETM(<MarkNo>, <MarkNo>, ...)
CLEARM(<MarkNo>, <MarkNo>, ...)
Meaning
INIT():
Predefined procedure for selecting the NC program that is to be executed in the specified
channel
START():
Predefined procedure for starting the selected program in the respective channel
WAITM():
Predefined procedure to wait for a wait marker to be reached in the specified channels
The specified wait marker is set by WAITM in the same channel. The previous block is
terminated with exact stop. The wait marker is deleted after synchronization.
A maximum of 10 markers can be set simultaneously in each channel.
WAITE():
Predefined procedure to wait for the end of program in one or more other channels
WAITMC(): 1)
Predefined procedure to wait for a wait marker to be reached in the specified channels
In contrast to WAITM, the braking of the axes to exact stop is only initiated if the other
channels have not yet reached the wait marker.
SETM(): 1)
Predefined procedure to set one or more wait markers for the channel coordination
The processing in own channel is not affected by this.
SETM remains valid after a channel reset and NC start.
CLEARM(): 1)
Predefined procedure to delete one or more wait markers for the channel coordination
The processing in own channel is not affected by this.
CLEARM() deletes all wait markers in the channel.
CLEARM(0) only deletes wait marker "0".
CLEARM remains valid after a channel reset and NC start.
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
483
Work preparation
3.1 Flexible NC programming
<ChanNo>:
Channel number
The number of the own channel does not have to be specified.
Type:
INT
<Prog>:
Absolute or relative path specification (optional) + program name
Type:
STRING
Information relating to path data, see the Programming Manual NC Programming, Chap-
ter "Addressing program memory files" (Page 555).
<AckMode>:
Acknowledgment mode (optional)
Type:
CHAR
Val-
"N"
Without acknowledgment
ues:
The program execution is continued after the command has been sent.
The sender is not informed if the command cannot be executed suc-
cessfully.
"S"
Synchronous acknowledgment
The program execution is stopped until the receiving component has
acknowledged the command. If the acknowledgment is positive, the
next command is executed. If the acknowledgment is negative, an error
message is output.
<MarkNo>:
Number of the wait marker
Note
In a multi-channel system, a maximum of 100 wait markers are available (wait markers
0 ... 99).
Only wait marker 0 is available in a single-channel system.
1) For user-specific communication and/or coordination of channels, wait markers can be deployed
using SETM / CLEARM - and also without using the conditional wait command WAITMC. The wait markers
retain their values, even after a channel reset and NC start.
Examples
START using channel names from MD20000
• Parameter assignment
MD10280 $MN_PROG_FUNCTION_MASK, bit 1 = TRUE
$MC_CHAN_NAME[ 0 ] = "MACHINING"; Name of channel 1
$MC_CHAN_NAME[ 1 ] = "INFEED"; Name of channel 2
• Programming
Program code
Comment
START(MACHINING)
; Start of channel 1
START(INFEED)
; Start of channel 2
START using local "channel names" and user variables
Program code
Comment
DEF INT MACHINE = 1
; Definition of user variable for channel 1
DEF INT LOADER = 2
; Definition of user variable for channel 2
START(MACHINE)
; Start of channel 1
NC programming
484
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Program code
Comment
START(LOADER)
; Start of channel 2
START using local "channel names", user variables and parameterized channel names
Program code
Comment
DEF INT chanNo1
; Definition of user variable for channel 1
DEF INT chanNo2
; Definition of user variable for channel 2
chanNo1 = CHAN_1
; Assignment of parameterized channel name channel 1
chanNo2 = CHAN_2
; Assignment of parameterized channel name channel 2
START(ChanNo1)
; Start of channel 1
START(ChanNo2)
; Start of channel 2
INIT command with absolute path specification
Selection of program /_N_MPF_DIR/_N_ABSPAN1_MPF in channel 2.
Program code
INIT(2,"/_N_WCS_DIR/_N_SHAFT1_WPD/_N_CUT1_MPF")
INIT command with program name
Selection of the program with the name "MYPROG". The control searches for the program using
the search path.
Program code
INIT(2,"MYPROG")
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
485
Work preparation
3.1 Flexible NC programming
Program coordination with WAITM
• Channel 1: The program /_N_MPF_DIR/_N_MPF100_MPF has already been selected and
started.
Program code
Comment
; Program MPF100
N10 INIT(2,"MPF200","N")
; Selection of program MPF200, channel 2
N11 START(2)
; Start of channel 2
N80 WAITM(1,1,2)
; Wait for WAIT marker 1 in channels 1 and
2
N81 ...
; Channel 1, N81 and channel 2, N71 are
; started synchronously
N180 WAITM(2,1,2)
; Wait for WAIT marker 2 in channels 1 and
2
N181 ...
; Channel 1, N181 and channel 2, N271 are
; started synchronously
N200 WAITE(2)
; Wait for end of program in channel 2
N201 ...
; N201 is not started until the end of
program
; MPF200 started in channel 2
N201 M30
; End of program channel 1
• Channel 2: In channel 1, the program MPF200_MPF is selected and started for channel 2
using blocks N10 and N20.
Program code
Comment
;$PATH=/_N_MPF_DIR
; Program MPF200
N70 WAITM(1,1,2)
Wait for WAIT marker 1 in channels 1 and 2
N71 ...
; Channel 1, N81 and channel 2, N71 are
; started synchronously
N270 WAITM(2,1,2)
Wait for WAIT marker 2 in channels 1 and 2
N271 ...
; Channel 1, N181 and channel 2, N271 are
; started synchronously
N400 M30
End of program channel 2
NC programming
486
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
1
1
:$,70
:$,70
&KDQQHO
1
03)
1
0
:DLWLQJ
&KDQQHO
1
1
1
03)
:DLWLQJ
:DLWLQJ
0
1
1
1
67$57
:$,70
:$,70
:$,7(
6WDUW
67$57
0
0
(QG RI WLPH
Supplementary conditions
Non-synchronous start of execution of following blocks after WAIT markers
In the case of channel coordination using WAIT markers, execution of the following blocks may
start non-synchronously. This behavior occurs if an action is triggered in one of the channels to
be synchronized immediately before reaching the common WAIT marker; the consequence of
which is implicit repositioning (REPOSA) in this delete distance-to-go.
Assumption: Current axis assignment in channels 1 and 2
• Channel 1: Axes X1 and U
• Channel 2: Axis X2
Table 3-2
Time sequence in channels 1 and 2
Channel 1
Channel 2
Description
Arbitrary processing in channels 1 and 2
N100
Channel 1: reaches the WAIT marker and waits for syn-
WAITM(20,1,2)
chronization with channel 2
Start of the GETD(U) pro-
N200 GETD(U)
Channel 2: Requests axis U from channel 1
cessing:
Channel 1: Processing of GET(U) in the backg7round
• Axis interchange
N210
Channel 2: reaches the WAIT marker. ⇒ This completes
• Delete distance-to-
WAITM(20,1,2)
the synchronization of channels 1 and 2
go
N220 G0 X2=100
Channel 2: Start of processing of N220
• REPOSA
End
N110 G0 X1=100
Channel 1: Staggered start of processing of N110
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
487
Work preparation
3.1 Flexible NC programming
3.1.9
Macro technique (DEFINE ... AS)
NOTICE
Macro technology increases the complexity of the programming
Macros can significantly alter the control's programming language. Macro technology may only
be used with great care.
A macro is a sequence of individual statements which have together been assigned a name of
their own. When a macro is called during a program run, the statements programmed under the
program name are executed one after the other.
According to the range of validity (in other words, the range in which the macro definition is
active), there are the following macro categories:
• Local macros
Local macros are macros that are defined at the beginning of an NC program, which at the
time of execution is not the main program. They are created when the NC program is called,
and deleted with an end of program reset - or the next time that the control system powers
up. Local macros can only be accessed within the NC program in which they are defined.
• Program-global macros
Program-global macros are macros that are defined at the beginning of an NC program,
which is used as a main program. They are created when the NC program is called, and
deleted with an end of program reset - or the next time that the control system powers up.
Program-global macros can be accessed in the main program and in all subprograms.
Note
Availability of program-global macros
Program-global macros defined in the main program are only available in subprograms if the
following machine data is set:
MD11120 $MN_LUD_EXTENDED_SCOPE = 1
If MD11120 = 0, the program-global macros defined in the main program will only be
available in the main program.
• Global macros
Global macros are NC or channel-global macros, which are defined in a definition file (macro
file) - and are retained even after an end of program reset or the next time that the control
system powers up. Global macros can be called in any main program or subprogram and
executed.
Note
In order to use the macros of an external macro file in the NC program, the macro file must
be downloaded to the NC.
NC programming
488
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
Work preparation
3.1 Flexible NC programming
Macros must be defined before they can be used. The following rules must be observed in this
context:
• Any identifier, G, M, H functions and L subprogram names can be defined in a macro.
• The macro can be defined at the beginning of the program or in a dedicated definition file
(macro file).
• Local and program-global macros are defined at the beginning of the program.
• Global macros must be defined in a macro file, e.g._N_DEF_DIR/_N_UMAC_DEF.
• G command macros can only be defined as global macros.
• H and L functions can be programmed with 2 digits.
• M and G commands can be programmed with 3 digits.
Note
Keywords and reserved names may not be overwritten with macros. This also applies to all jump
destinations within a GOTO command, and to the keywords in program loops, such as FOR,
WHILE, LOOP, REPEAT.
Syntax
Macro definition:
DEFINE <Macro_name> AS <Operation_1> <Operation_2> ...
Call in the NC program:
<Macro_name>
Meaning
DEFINE ... AS:
Keyword combination to define a macro
<Macro_name>:
Macro name
Only identifiers are permissible as macro names.
The macro is called from the NC program by the macro name.
<Operation_1>:
First programming instruction in the macro
<Operation_2>:
Second programming instruction in the macro
Examples
Example 1: Macro definition at the beginning of the program
Program code
Comment
DEFINE LINE AS G1 G94 F300
; Macro definition
N70 LINE X10 Y20
; Macro call
NC programming
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
489
Work preparation
3.1 Flexible NC programming
Example 2: Macro definitions in a macro file
Program code
Comment
DEFINE M6 AS L6
; A subprogram is called at tool change to handle
the necessary data transfer. The actual tool change
M function is output in the subprogram (e.g. M106).
DEFINE G81 AS DRILL(81)
; Emulation of the DIN-G command.
DEFINE G33 AS M333 G333
; During thread cutting, synchronization is reques-
ted with the PLC. The original G command G33 was
renamed to G333 by machine data so that the program-
ming remains identical for the user.
Example 3: External macro file
After reading the external macro file into the control, the macro file must be downloaded into the
NC. Only then can macros be used in the NC program.
Program code
Comment
%_N_UMAC_DEF
;$PATH=/_N_DEF_DIR
; Customer-specific macros
DEFINE PI AS 3.14
DEFINE TC1 AS M3 S1000
DEFINE M13 AS M3 M7
; Spindle clockwise, coolant on
DEFINE M14 AS M4 M7
; Spindle counter-clockwise, coolant on
DEFINE M15 AS M5 M9
; Spindle stop, coolant off
DEFINE M6 AS L6
; Call tool change program
DEFINE G80 AS MCALL
; Deselect drilling cycle
M30
NC programming
490
Programming Manual, 10/2020, 6FC5398-2EP40-0BA1
|