Control
SINUMERIK 840D sl / 840DE sl
SINUMERIK 828D
Software Version
CNC software 4.5 SP2
Preface
Flexible NC programming
File and Program
Management
Protection zones
Special motion commands
Coordinate transformations
(frames)
Transformations
Kinematic chains
Collision avoidance with
kinematic chains
Tool offsets
Path traversing behavior
Axis couplings
Synchronized actions
Oscillation
Punching and nibbling
Grinding
Additional functions
User stock removal
programs
Programming cycles
externally
Tables
Appendix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
A
03/2013
6FC5398-2BP40-3BA1
Legal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent
damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert
symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are
graded according to the degree of danger.
DANGER
indicates that death or severe personal injury will result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury may result if proper precautions are not taken.
CAUTION
indicates that minor personal injury can result if proper precautions are not taken.
NOTICE
indicates that property damage can result if proper precautions are not taken.
If more than one degree of danger is present, the warning notice representing the highest degree of danger will
be used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to
property damage.
Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific
task in accordance with the relevant documentation, in particular its warning notices and safety instructions.
Qualified personnel are those who, based on their training and experience, are capable of identifying risks and
avoiding potential hazards when working with these products/systems.
Proper use of Siemens products
Note the following:
WARNING
Siemens products may only be used for the applications described in the catalog and in the relevant technical
documentation. If products and components from other manufacturers are used, these must be recommended
or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and
maintenance are required to ensure that the products operate safely and without any problems. The permissible
ambient conditions must be complied with. The information in the relevant documentation must be observed.
Trademarks
All names identified by ® are registered trademarks of Siemens AG. The remaining trademarks in this publication
may be trademarks whose use by third parties for their own purposes could violate the rights of the owner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software
described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the
information in this publication is reviewed regularly and any necessary corrections are included in subsequent
editions.
Siemens AG
Industry Sector
Postfach 48 48
90026 NÜRNBERG
GERMANY
Order number: 6FC5398-2BP40-3BA1
Ⓟ 04/2013 Technical data subject to change
You can find Frequently Asked Questions in the Service&Support pages under Product
Support. http://support.automation.siemens.com
SINUMERIK
You can find information on SINUMERIK under the following link:
www.siemens.com/sinumerik
Target group
This publication is intended for:
● Programmers
● Project engineers
Benefits
With the programming manual, the target group can develop, write, test, and debug
programs and software user interfaces.
Standard scope
This Programming Manual describes the functionality afforded by standard functions.
Extensions or changes made by the machine tool manufacturer are documented by the
machine tool manufacturer.
Other functions not described in this documentation might be executable in the control. This
does not, however, represent an obligation to supply such functions with a new control or
when servicing.
Further, for the sake of simplicity, this documentation does not contain all detailed
information about all types of the product and cannot cover every conceivable case of
installation, operation or maintenance.
Technical Support
You will find telephone numbers for other countries for technical support in the Internet under
http://www.siemens.com/automation/service&support
Job Planning
4Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Preface
Information on structure and contents
"Fundamentals" and "Job planning" Programming Manual
The description of the NC programming is divided into two manuals:
1. Fundamentals
The "Fundamentals" Programming Manual is intended for use by skilled machine
operators with the appropriate expertise in drilling, milling and turning operations. Simple
programming examples are used to explain the commands and statements which are
also defined according to DIN 66025.
2. Job planning
This "Job planning" Programming Manual is intended for use by technicians with in-depth,
comprehensive programming knowledge. By virtue of a special programming language,
the SINUMERIK control enables the user to program complex workpiece programs (e.g.
for free-form surfaces, channel coordination, ...) and makes programming of complicated
operations easy for technologists.
Availability of the described NC language elements
All NC language elements described in the manual are available for the SINUMERIK
840D sl. The availability regarding SINUMERIK 828D can be found in table "Operations:
Availability for SINUME
The use of variables, especially in conjunction with arithmetic functions and check structures,
enables part programs and cycles to be set up with extremely high levels of flexibility. The
system provides three different types of variables.
● System variables
System variables are variables with a fixed predefined meaning; they are defined in the
system and made available to the user. They are also read and written by the system
software. Example: Machine data
The meaning of a system variable is permanently set by the system. However, minor
modifications can be made to the properties by the user in the form of redefinition. See
"Redefinition of system variables, user variables, and NC language
(Page 29)"
● User variable
User variables are variables whose meaning is not known to the system; they are not
evaluated by the system. The meaning is defined exclusively by the user.
User variables are subdivided into:
s
ands (REDEF)
comm
1
– Predefined user variables
Predefined user variables are variables which have already been defined in the
system and whose number simply has to be parameterized by the user via specific
machine data. The user can make significant changes to the properties of these
variables. See "Redefinition of system variables, user variables, and NC language
comm
ands (REDEF) (Page 29)".
– User-defined
User-defined variables are variables which are defined exclusively by the user and are
not created by the system until runtime. Their number, data type, visibility, and all
other properties are defined exclusively by the user.
See "Definition of user variables (DEF) (Page 24)"
1.1.1 System variable
System variables are variables which are predefined in the system and enable access to the
current parameter settings of the control, as well as to machine, control, and process states,
in part programs and cycles.
Preprocessing variables are system variables that are read and written in the context of
preprocessing; in other words, at the point in time at which the part program block in which
the system variable is programmed is interpreted. Preprocessing variables do not trigger
preprocessing stops.
Main run variables
Main run variables are system variables which are read and written in the context of the main
run; in other words at the point in time at which the part program block in which the system
variable is programmed is executed. The following are main run variables:
● System variables which can be programmed in synchronized actions (read/write)
● System variables which can be programmed in the part program and trigger
preprocessing stops (read/write)
● System variables which can be programmed in the part program and whose value is
calculated during preprocessing but not written until the main run (main run synchronized:
write only)
Prefix system
In order that they can be specifically identified, the names of system variables are usually
preceded by a prefix comprising the $ sign followed by one or two letters and an underscore.
$ + 1st letter Meaning: Data type
System variables which are read/written during preprocessing
$M Machine data 1)
$S Setting data, protection zones 1)
$T Tool management data
$P Programmed values
$C Cycle variables of ISO envelope cycles
$O Option data
R R-parameters (arithmetic parameters) 2)
System variables which are read/written during the main run
$$M Machine data 1)
$$S Setting data 1)
$A Current main run data
$V Servo data
$R R-parameters (arithmetic parameters) 2)
1)
Whether machine and setting data is treated as preprocessing or main run variables depends on
whether they are written with one or two $ characters. The notation is freely selectable for the specific
application.
2)
When an R-parameter is used in the part program/cycle as a preprocessing variable, the prefix is
omitted, e.g. R10. When it is used in a synchronized action as a main run variable, a $ sign is written
as a prefix, e.g. $R10.
Job Planning
18Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
2nd letter Meaning: Visibility
N NCK-global variable (NCK)
C Channel-specific variable (Channel)
A Axis-specific variable (Axis)
Supplementary conditions
Exceptions in the prefix system
The following system of variables deviate from the prefix system specified above:
● $TC_...: Here, the 2nd letter C does not refer to channel-specific system variables but to
toolholder-specific system variables (TC= tool carrier).
● $P_ ...: Channel-specific system variables
Use of machine and setting data in synchronized actions
When machine and setting data is used in synchronized actions, the prefix can be used to
define whether the machine or setting data will be read/written synchronous to the
preprocessing run or the main run.
References
If the data remains unchanged during machining, it can be read synchronous to the
preprocessing run. For this purpose, the machine or setting data prefix is written with a $ sign:
ID=1 WHENEVER $AA_IM[z] < $SA_OSCILL_REVERSE_POS2[Z]–6 DO $AA_OVR[X]=0
If the data changes during machining, it must be read/written synchronous to the main run.
For this purpose, the machine or setting data prefix is written with two $ signs:
ID=1 WHENEVER $AA_IM[z] < $$SA_OSCILL_REVERSE_POS2[Z]–6 DO $AA_OVR[X]=0
Note
Writing machine data
When writing an item of machine or setting data, it is important to ensure that the access
level which is active when the part program/cycle is executed permits write access and that
the data is set to take "IMMEDIATE" effect.
A list of the properties of all system variables appears in:
1.1.2 Predefined user variables: Arithmetic parameters (R)
Function
Arithmetic parameters or R parameters are predefined user variables with the designation R,
defined as an array of the REAL data type. For historical reasons, notation both with array
index, e.g.
R[10], and without array index, e.g. R10, is permitted for R parameters.
Syntax
Meaning
When using synchronized actions, the $ sign must be included as a prefix, e.g.
$R10.
When used as a preprocessing variable:
R<n>
R[<expression>]
When used as a main run variable:
$R<n>
$R[<expression>]
R: Identifier when used as a preprocessing variable, e.g. in the part program
$R: Identifier when used as a main run variable, e.g. in synchronized actions
Type: REAL
Range of values: For a non-exponential notation:
± (0.000 0001 ... 9999 9999)
Note:
A maximum of 8 decimal places are permitted.
For an exponential notation:
± (1*10
-300
... 1*10
+300
)
Note:
Notation: <Mantisse>EX<exponent> e.g. 8.2EX-3
A maximum of 10 characters are permitted including
sign and decimal point.
<n>:
Number of the R parameter
Type: INT
Range of values: 0 - MAX_INDEX
Note
MAX_INDEX is calculated from the parameterized number
of R-parameters:
MAX_INDEX = (MD28050 $MN_MM_NUM_R_PARAM) - 1
<expression>: Array index
Any expression can be used as an array index, as long as the result of the
expression can be converted to the INT data type (INT, REAL, BOOL,
CHAR).
Job Planning
20Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Example
Assignments to R-parameters and use of R-parameters in mathematical functions:
Program code Comment
R0=3.5678 ; Assignment in preprocessing
R[1]=-37.3 ; Assignment in preprocessing
R3=-7 ; Assignment in preprocessing
$R4=-0.1EX-5 ; Assignment in main run: R4 = -0.1 * 10^-5
$R[6]=1.874EX8 ; Assignment in main run: R6 = 1.874 * 10^8
R7=SIN(25.3) ; Assignment in preprocessing
R[R2]=R10 ; Indirect addressing using R-parameter
R[(R1+R2)*R3]=5 ; Indirect addressing using math. expression
X=(R1+R2) ; Traverse axis X to the position resulting from the
sum of R1 and R2
Z=SQRT(R1*R1+R2*R2) ; Traverse axis Z to the square root position (R1^2 +
R2^2)
See also
Variables (Page 17)
1.1.3 Predefined user variables: Link variables
Function
Link variables can be used in the context of the "NCU-Link" function for cyclic data exchange
between NCUs which are linked on a network. They facilitate data-format-specific access to
the link variables memory. The link variables memory is defined both in terms of size and
data structure on a system-specific basis by the user/machine manufacturer.
Link variables are system-global user variables which can be read and written in part
programs and cycles by all NCUs involved in a link if link communication has been
configured. Unlike global user variables (GUD), link variables can also be used in
synchronized actions.
On systems without an active NCU link, link variables can be used locally on the controller
as additional global user variables alongside global user variables (GUD).
Link variable for BYTE data format (1 byte)
Data type: UINT
Range of values: 0 ... 255
Link variable for WORD data format (2 bytes)
Data type: INT
Range of values: -32768 ... 32767
Link variable for DWORD data format (4 bytes)
Data type: INT
Range of values: -2147483648 ... 2147483647
Link variable for REAL data format (8 bytes)
Data type: REAL
Range of values: ±(2.2*10
-308
… 1.8*10
+308
)
Address index in bytes, counted from the start of the link variable memory
Data type: INT
Range of values: 0 - MAX_INDEX
Note
MAX_INDEX is calculated from the parameterized size
of the link variables memory: MAX_INDEX = (MD18700
$MN_MM_SIZEOF_LINKVAR_DATA) - 1
Only indices may be programmed, so that the bytes
addressed in the link variables memory are located on a
data format limit ⇒
Index = n * bytes, where n = 0, 1, 2, etc.
$A_DLB[i]: i = 0, 1, 2, ...
–
–
$A_DLW[i]: i = 0, 2, 4, ...
–
$A_DLD[i]: i = 0, 4, 8, ...
–
$A_DLR[i]: i = 0, 8, 16, ...
Example
An automation system contains 2 NCUs (NCU1 and NCU2). Machine axis AX2 is connected
to NCU1. It is traversed as a link axis of NCU2.
NCU1 writes the actual current value ($VA_CURR) of axis AX2 cyclically to the link variables
memory. NCU2 reads the actual current value transmitted via link communication cyclically
and displays alarm 61000 if the limit value is exceeded.
Job Planning
22Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
The data structure in the link variables memory is illustrated in the following figure. The
actual current value is transmitted in the REAL value.
NCU1
NCU1 uses link variable $A_DLR[ 16 ] to write the actual current value of axis AX2 to the link
variables memory cyclically in the interpolation cycle in a static synchronized action.
Program code
N111 IDS=1 WHENEVER TRUE DO $A_DLR[16]=$VA_CURR[AX2]
NCU2
NCU2 uses link variable $A_DLR[ 16 ] to read the actual current value of axis AX2 from the
link variables memory cyclically in the interpolation cycle in a static synchronized action. If
the actual current value is greater than 23.0 A, alarm 61000 is displayed.
The DEF command is used to define user-specific variables and assign values to them. To set
them apart from system variables, these are called user-defined variables or user variables
(user data).
According to the range of validity (in other words, the range in which the variable is visible)
there are the following categories of user variable:
● Local user variables (LUD)
Local user variables (LUD) are variables defined in a part program which is not the main
program at the time of execution. They are created when the part program is called and
deleted at the end of the part program or when the NC is reset. Local user variables can
only be accessed within the part program in which they are defined.
● Program-global user variables (PUD)
Program-global user variables (PUD) are user variables defined in a part program used
as the main program. They are created when the part program starts up and deleted at
the end of the part program or when the NC is reset. It is possible to access PUD in the
main program and in all subprograms of the main program.
Syntax
● Global user variables (GUD)
Global user variables (GUD) are NC or channel-global variables which are defined in a
data block (SGUD, MGUD, UGUD, GUD4 to GUD9) and are retained following shutdown
and restart. GUD can be accessed in all part programs.
User variables must be defined before they can be used (read/write). The following rules
must be observed in this context:
● GUD have to be defined in a definition file, e.g. _N_DEF_DIR/_M_SGUD_DEF.
● PUD and LUD have to be defined in a definition section of the part program.
● The data must be defined in a dedicated block.
● Only one data type may be used for each data definition.
● Several variables of the same data type can be defined for each data definition.
DEF: Command for defining GUD, PUD, LUD user variables
<range>:
<PP_stop>:
<access rights>:
<type>:
<phys_unit>:
<limit values>:
Range of validity, only relevant for GUD:
NCK: NC-global user variable
CHAN: Channel-global user variable
Preprocessing stop, only relevant for GUD (optional)
SYNR: Preprocessing stop when reading
SYNW: Preprocessing stop when writing
SYNRW: Preprocessing stop when reading/writing
Protection level for reading/writing GUD via part program or OPI
(optional)
APRP <protection level>: Read: Part program
APWP <protection level>: Write: Part program
APRB <protection level>: Read: OPI
APWB <protection level>: Write: OPI
<protection level>: Range of values: 0 ... 7
See "Attribute: Access rights (APR, APW, APRP, APWP, APRB,
APWB) (Page 39)"
Data type:
INT: Integer with sign
REAL: Real number (LONG REAL to IEEE)
BOOL: Truth value TRUE (1)/FALSE (0)
CHAR: ASCII character
STRING[<MaxLength>]: Character string of a defined length
AXIS: Axis/spindle identifier
FRAME: Geometric data for a static coordinate
transformation
See "Data types (Page 52)"
Physical unit (optional)
PHU <unit>: Physical unit
See "Attribute: Physical unit (PHU) (Page 37)"
Lower/upp
LLI <limit value>: Lower limit value (lower limit)
ULI <limit value>: Upper limit value (upper limit)
er limit value (optional)
See "Attribute: Limit values (LLI, ULI) (Page 35)"
Maximum 31 characters
The first two characters must be a letter and/or an underscore.
The $ sign is reserved for system variables and must not be
used.
[<value_1>,
<value_2>,
<value_3>]
:
Specification of array sizes for 1- to max. 3-dimensional array
variables (optional)
For the Initialization of array variables see "Definition and
initialization of array
<init_value>: Initialization value (optional)
variables (DEF, SET, REP) (Page 45)"
See "Attribute: Initialization value (Page 32)"
For the Initializa
initialization of array
tion of array variables see "Definition and
variables (DEF, SET, REP) (Page 45)"
Examples
Example 1: Definition of user variables in the data block for machine manufacturers
Example 3: Definition and use of user variables of data type AXIS
Program code Comment
DEF AXIS ABSCISSA ;1st geometry axis
DEF AXIS SPINDLE ;Spindle
...
IF ISAXIS(1) == FALSE GOTOF CONTINUE
ABSCISSA = $P_AXN1
CONTINUE:
...
SPINDLE=(S1) ;1st spindle
OVRA[SPINDLE]=80 ;Spindle override = 80%
SPINDLE=(S3) ;3rd spindle
Supplementary conditions
Global user variables (GUD)
In the context of the definition of global user variables (GUD), the following machine data has
to be taken into account:
No. Identifier: $MN_ Meaning
11140 GUD_AREA_ SAVE_TAB Additional save for GUD blocks
18118 1) MM_NUM_GUD_MODULES Number of GUD files in the active file system
18120 1) MM_NUM_GUD_NAMES_NCK Number of global GUD names
18130 1) MM_NUM_GUD_NAMES_CHAN Number of channel-spec. GUD names
18140 1) MM_NUM_GUD_NAMES_AXIS Number of axis-spec. GUD names
18150 1) MM_GUD_VALUES_MEM Memory location for global GUD values
18660 1) MM_NUM_SYNACT_GUD_REAL Number of configurable GUD of the REAL data type
18661 1) MM_NUM_SYNACT_GUD_INT Number of configurable GUD of the INT data type
18662 1) MM_NUM_SYNACT_GUD_BOOL Number of configurable GUD of the BOOL data type
18663 1) MM_NUM_SYNACT_GUD_AXIS Number of configurable GUD of the AXIS data type
18664 1) MM_NUM_SYNACT_GUD_CHAR Number of configurable GUD of the CHAR data type
18665 1) MM_NUM_SYNACT_GUD_STRING Number of configurable GUD of the STRING data type
1)
For SINUMERIK 828D, MD can only be read!
Job Planning
28Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Program-global user variables (PUD)
Note
Visibility of program-global user variables (PUD)
Program-global user variables (PUD) defined in the main program will only be visible in
subprograms if the following machine data is set:
MD11120 $MN_LUD_EXTENDED_SCOPE = 1
If MD11120 = 0 the program-global user variables defined in the main program will only be
visible in the main program.
Cross-channel use of an NCK-global user variable of the AXIS data type
An NCK-global user variable of the
AXIS data type initialized during definition in the data
block with an axis identifier can then only be used in other NC channels if the axis has the
same channel axis number in these channels.
If this is not the case, the variable has to be loaded at the start of the part program or, as in
the following example, the AXNAME(...) function has to be used.
Program code Comment
DEF NCK STRING[5] ACHSE="X" ;Definition in the data block
...
N100 AX[AXNAME(ACHSE)]=111 G00 ;Use in the part program
1.1.5 Redefinition of system variables, user variables, and NC language commands
(REDEF)
Function
The REDEF command can be used to change the attributes of system variables, user
variables and NC language commands. A fundamental condition of redefinition is that it has
to post-date the corresponding definition.
Multiple attributes cannot be changed simultaneously during redefinition. A separate
statement has to be programmed for each attribute to be changed.
If two or more concurrent attribute changes are programmed, the last change is always
active.
The attributes for access rights and initialization time change with
default values by reprogramming
REDEF, followed by the name of the variable or the NC
REDEF can be reset to their
language command:
● Access rights: Protection level 7
● Initialization time: No initialization or retention of the current value
Redefinable attributes
See "Overview of definable and redefinable attributes (Page 44)"
Local u
ser va
riables (PUD/LUD)
Redefinitions are not permitted for local user variables (PUD/LUD).
REDEF <name> <PP_stop>
REDEF <name> <phys_unit>
REDEF <name> <limit_values>
REDEF <name> <access_rights>
REDEF <name> <init_time>
REDEF <name> <init_time> <init_value>
Meaning
REDEF <name>
REDEF: Command for redefinition of a certain attribute or to reset the
"Access rights" and/or "Initialization time" attributes of system
variables, user variables and NC language commands
<name>: Name of an already defined variable or an NC language
command
<PP stop>:
<phys_unit>:
Preprocessing stop
SYNR: Preprocessing stop when reading
SYNW: Preprocessing stop when writing
SYNRW: Preprocessing stop when reading/writing
Physical unit
PHU <unit>: Physical unit
See "Attribute: Physical unit (PHU) (Page 37)"
Note
Cannot be re
defined for:
System variables
Global user data (GUD) of the data types:
FRAME
BOOL, AXIS, STRING,
Job Planning
30Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
<limit values>:
Lower/upper limit
LLI <limit value>: Lower limit value (lower limit)
ULI <limit value>: Upper limit value (upper limit)
See "Attribute: Limit values (LLI, ULI) (Page 35)"
Note
Cannot be re
defined for:
System variables
Global user data (GUD) of the data types:
FRAME
<access rights>:
Access rights for reading/writing via part program or OPI
APX <protection level>: Execute: NC language element
APRP <protection level>: Read: Part program
APWP <protection level>: Write: Part program
APRB <protection level>: Read: OPI
APWB <protection level>: Write: OPI
<protection level>: Range of values: 0 ... 7
See "Attribute: Access rights (APR, APW, APRP, APWP, APRB,
APWB) (Page 39)"
<init_time>:
Point in time at which the variable is reinitializ
INIPO: Power On
INIRE: End of main program, NC reset or Power On
INICF: NewConfig or end of main program, NC reset or
Power On
PRLOC: End of main program, NC reset following local
change or Power On
See "Attribute: Initialization value (Page 32)"
<init_value>: Initialization value
When redefining the initialization value, an initialization time
always has to be specified also (see <init_time>).
See "Attribute: Initialization value (Page 32)"
For the Initializa
tion of array variables see "Definition and
initialization of array
Note
Cannot be re
defined for system variables, except setting data.
Redefinitions of system variable $TC_DPC1 in the data block for machine manufacturers
Program code
%_N_MGUD_DEF ; GUD block: Machine manufacturer
N100 REDEF $TC_DPC1 APWB 2 APWP 3
N200 REDEF $TC_DPC2 PHU 21
N300 REDEF $TC_DPC3 LLI 0 ULI 200
N400 REDEF $TC_DPC4 INIPO (100, 101, 102, 103)
; N100: Write access: OPI = protection level 2, part program = protection level 3
; Note
; When using ACCESS files the redefinition of access rights has to be moved from
; _N_MGUD_DEF to _N_MACCESS_DEF
; N200: Physical unit = [ % ]
; N300: Limit values: Lower limit value = 0, upper limit value = 200
; N400: The array variable is initialized with the four values at POWER ON.
; Reset of the "Access rights" and/or "Initialization time" attribute values
N800 REDEF $TC_DPC1
N900 REDEF $TC_DPC4
M30
Supplementary conditions
Granularity
A redefinition is always applied to the entire variable which is uniquely identified by its name.
Array variables do not, for example, support the assignment of different attributes to
individual array elements.
1.1.6 Attribute: Initialization value
Definition (DEF) of user variables
During definition an initialization value can be preassigned for the following user variables:
● Global user variables (GUD)
● Program-global user variables (PUD)
● Local user variables (LUD)
Job Planning
32Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Redefinition (REDEF) of system and user variables
During redefinition an initialization value can be preassigned for the following variables:
– Synchronized action GUD (SYG_xy[ ], where x=R, I, B, A, C, S and y=S, M, U, 4 to 9)
– EPS parameters
– Tool data OEM
– Magazine data OEM
– Global user variables (GUD)
Reinitialization time
During redefinition the point in time can be specified at which the variable should be
reinitialized, i.e. reset to the initialization value.
●
INIPO (POWER ON)
The variable is reinitialized at Power On.
●
INIRE (reset)
The variable is reinitialized on NC reset, mode group reset, at the end of the part program
(
M02/M30) or at Power On.
●
INICF (NewConfig)
The variable is reinitialized on a NewConf request via the HMI, with part program
command
NEWCONFIG or on an NC reset, mode group reset, at the end of the part program
(M02/M30) or at Power On.
●
PRLOC (program-local change)
The variable is only reinitialized on an NC reset, mode group reset or at the end of the
part program (M02/M30) if it has changed during the current part program.
The
PRLOC attribute may only be changed in conjunction with programmable setting data
1) This G command is used to address the setting data.
FPRAON
G26
G25
FXST
FXSW
OSP1
OSP2
OST1
OST2
FA
OSNSC
OSE
OSCTRL
OS
OSB
Supplementary conditions
Initialization value: Global user variables (GUD)
● Only
(GUD) with the
● In addition to
initialization time for global user variables (GUD) with the
● In the case of global user variables (GUD) with the
INICF (NewConfig) initialization time, for an NC reset, mode group reset and
or
NewConfig, the variables are only reinitialized in the channels in which the named events
were triggered.
Initialization value: FRAME data type
It is not permitted to specify an initialization value for variables of the
Variables of the
Initialization value: CHAR data type
For variables of the
ASCII character can be programmed in quotation marks, e.g. "A".
Initialization value: STRING data type
In the case of variables of the
quotation marks, e.g. ...= "MACHINE_1"
INIPO (Power On) can be defined as the initialization time for global user variables
NCK range of validity.
INIPO (Power On), INIRE (reset) or INICF (NewConfig) can be defined as the
CHAN range of validity.
CHAN range of validity and INIRE (reset)
FRAME data type.
FRAME data type are initialized implicitly and always with the default frame.
CHAR data type, instead of the ASCII code (0...255), the corresponding
STRING data type, the character string must be enclosed in
Initialization value: AXIS data type
In the case of variables of the
AXIS data type, for an extended address notation, the axis
identifier must be enclosed in brackets, e.g. ...=(X3).
Job Planning
34Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Initialization value: System variable
For system variables, redefinition cannot be used to define user-specific initialization values.
The initialization values for the system variables are specified by the system and cannot be
changed. However, redefinition can be used to change the point in time (
INIRE, INICF) at
which the system variable is reinitialized.
Implicit initialization value: AXIS data type
See also
For variables of the
AXIS data type the following implicit initialization value is used:
Implicit initialization value: Tool and magazine data
Initialization values for tool and magazine data can be defined using the following machine
data: MD17520 $MN_TOOL_DEFAULT_DATA_MASK
Note
Synchronization
The synchronization of events triggering the reinitialization of a global variable when this
variable is read in a different location is the sole responsibility of the user/machine
manufacturer.
Variables (Page 17)
1.1.7 Attribute: Limit values (LLI, ULI)
An upper and a lower limit of the definition range can only be defined for the following data
types:
● INT
● REAL
● CHAR
Definition (DEF) of user variables: Limit values and implicit initialization values
If no explicit initialization value is defined when defining a user variable of one of the above
data types, the variable is set to the data type's implicit initialization value.
If the implicit initialization value is outside the definition range specified by the programmed
limit values, the variable is initialized with the limit value which is closest to the implicit
initialization value:
● Implicit initialization value < lower limit value (LLI) ⇒
initialization value = lower limit value
● Implicit initialization value > upper limit value (ULI) ⇒
initialization value = upper limit value
Examples:
Program code Comment
DEF REAL GUD1 ;
DEF REAL LLI 5.0 GUD2 ;
DEF REAL ULI –5 GUD3 ;
Lower limit value = definition range limit
;
Upper limit value = definition range limit
;
No initialization value programmed
;
=> Implicit initialization value = 0.0
Lower limit value = 5.0
;
Upper limit value = definition range limit
;
=> Initialization value = 5.0
Lower limit value = definition range limit
;
Upper limit value = -5.0
;
=> Initialization value = -5.0
Redefinition (REDEF) of user variables: Limit values and current actual values
If, when the limit values of a user variable are redefined, they change to the extent that the
current actual value is outside the new definition range, an alarm will be issued and the limit
values will be rejected.
Note
Redefinition (REDEF) of user variables
When the limit values of a user variable are redefined, care must be taken to ensure that the
following values are changed consistently:
Limit values
Actual value
Initialization value on redefinition and automatic reinitialization on the basis of INIPO,
INIRE or INICF
See also
Variables (Page 17)
Job Planning
36Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
1.1.8 Attribute: Physical unit (PHU)
A physical unit can only be specified for variables of the following data types:
● INT
● REAL
Programmable physical units (PHU)
The physical unit is specified as fixed point number: PHU <unit>
The following physical units can be programmed:
<unit> Meaning Physical unit
0 Not a physical unit 1 Linear or angular position
2 Linear position 2) [ mm ], [ inch ]
3 Angular position [ degree ]
4 Linear or angular velocity
5 Linear velocity 2) [ mm/min ]
6 Angular velocity [ rpm ]
7 Linear or angular acceleration
8 Linear acceleration 2) [ m/s2 ], [ inch/s2 ]
9 Angular acceleration [ rev/s2 ]
10 Linear or angular jerk
11 Linear jerk 2) [ m/s3 ], [ inch/s3 ]
12 Angular jerk [ rev/s3 ]
13 Time [ s ]
14 Position controller gain [ 16.667/s ]
15 Revolutional feedrate 2) [ mm/rev ], [ inch/rev ]
16 Temperature compensation
18 Force [ N ]
19 Mass [ kg ]
20 Moment of inertia 3) [ kgm2 ]
21 Percent [ % ]
22 Frequency [ Hz ]
23 Voltage [ V ]
24 Current [ A ]
25 Temperature [ °C ]
26 Angle [ degree ]
27 KV [ 1000/min ]
28 Linear or angular position 3) [ mm ], [ inch ], [ degree ]
29 Cutting rate 2) [ m/min ], [ feet/min ]
69 Force controller controlled-system gain [ N/V ]
155 Thread lead 3) [ mm/rev ], [ inch/rev ]
156 Change in thread lead 3) [ mm/rev / rev ], [ inch/rev / rev ]
1) The physical unit depends on the axis type: Linear or rotary axis
2) System of units changeover
G70/G71(inch/metric)
After changing over the basic system (MD10240 $MN_SCALING_SYSTEM_IS_METRIC) with
G70/G71, for read/write operations to system and user variables involving a length, then the values
are not converted (actual value, default value and limit values)
G700/G710(inch/metric)
After changing over the basic system (MD10240 $MN_SCALING_SYSTEM_IS_METRIC) with
G700/G710, for read/write operations to system and user variables involving a length, then the values
are converted (actual value, default value and limit values)
3) The variable is not converted to the NC's current measuring system (inch/metric) automatically.
Conversion is the sole responsibility of the user/machine manufacturer.
Note
Level overflow due to format conversion
The internal storage format for all user variables (GUD/PUD/LUD) with physical units of
length is metric. Excessive use of these types of variable in the NCK's main run, e.g in
synchronized actions, can lead to a CPU time overflow at interpolation level when the
measuring system is switched over, generating alarm 4240.
Job Planning
38Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Note
Compatibility of units
When using variables (assignment, comparison, calculation, etc.) the compatibility of the
units involved is not checked. Should conversion be required, this is the sole responsibility of
the user/machine manufacturer.
See also
Variables (Page 17)
1.1.9 Attribute: Access rights (APR, APW, APRP, APWP, APRB, APWB)
The following protection levels, which have to be specified during programming, correspond
to the access rights:
Access right Protection level
System password 0
Machine manufacturer password 1
Service password 2
End user password 3
Key-operated switch position 3 4
Key-operated switch position 2 5
Key-operated switch position 1 6
Key-operated switch position 0 7
Definition (DEF) of user variables
Access rights (APR.../APW...) can be defined for the following variables:
– Synchronized action GUD (SYG_xy[ ], where x=R, I, B, A, C, S and y=S, M, U, 4 to 9)
– EPS parameters
– Tool data OEM
– Magazine data OEM
– Global user variables (GUD)
Note
During redefinition the access right can be freely assigned to a variable between the
lowest protection level 7 and the dedicated protection level, e.g. 1 (machine
manufacturer).
Job Planning
40Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Redefinition (REDEF) of NC language commands
The access or execution right (APX) can be redefined for the following NC language
commands:
● G functions/Preparatory functions
References:
Programming Manual, Fundamentals; Section: G functions/Preparatory functions
– During part program processing the end user password has to be set.
– The cycle has to be stored in the _N_CUS_DIR (user), _N_CMA_DIR or _N_CST_DIR
directory.
– The execution rights must be set to at least end user for the _N_CUS_DIR,
_N_CMA_DIR or _N_CST_DIR directories in machine data MD11162
$MN_ACCESS_EXEC_CUS, MD11161 $MN_ACCESS_EXEC_CMA or MD11160
$MN_ACCESS_EXEC_CST respectively.
●
APRP 4...7/APWP 4...7
– During part program processing the key-operated switch must be set to 3 ... 0.
– The cycle has to be stored in the _N_CUS_DIR, _N_CMA_DIR or _N_CST_DIR
directory.
– The execution rights must be set to at least the corresponding key-operated switch
position for the _N_CUS_DIR, _N_CMA_DIR or _N_CST_DIR directories in machine
data MD11162 $MN_ACCESS_EXEC_CUS, MD11161 $MN_ACCESS_EXEC_CMA
or MD11160 $MN_ACCESS_EXEC_CST respectively.
Access rights in relation to OPI (APRB, APWB)
The access rights (APRB, APWB) restrict access to system and user variables via the OPI
equally for all system components (HMI, PLC, external computers, EPS services, etc.).
APR/APW access attributes
Note
Local HMI access rights
When changing access rights to system data, care must be taken to ensure that such
changes are consistent with the access rights defined using HMI mechanisms.
For compatibility reasons, attributes APR and APW are implicitly mapped to the attributes APRP /
APRB and APWP / APWB:
●
APR x ⇒ APRP x APRB x
●
APW y ⇒ APWP y APWB y
Job Planning
42Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Setting access rights using ACCESS files
When using ACCESS files to assign access rights, redefinitions of access rights for system
data, user data, and NC language commands may only continue to be programmed in these
ACCESS files. Global user data (GUD) is an exception. For this data, access rights have to
continue to be redefined (if this appears necessary) in the corresponding definition files.
For continuous access protection, the machine data for the execution rights and the access
protection for the corresponding directories have to be modified consistently.
In principle, the procedure is as follows:
● Creation of the necessary definition files:
– _N_DEF_DIR/_N_SACCESS_DEF
– _N_DEF_DIR/_N_MACCESS_DEF
– _N_DEF_DIR/_N_UACCESS_DEF
● Setting of the write right for the definition files to the value required for redefinition:
– MD11170 $MN_ACCESS_WRITE_SACCESS
– MD11171 $MN_ACCESS_WRITE_MACCESS
– MD11172 $MN_ACCESS_WRITE_UACCESS
● For access to protected elements from cycles, the execution and write rights for cycle
directories _N_CST_DIR, _N_CMA_DIR, and _N_CST_DIR have to be modified.
Execution rights
– MD11160 $MN_ACCESS_EXEC_CST
– MD11161 $MN_ACCESS_EXEC_CMA
– MD11162 $MN_ACCESS_EXEC_CUS
Write rights
– MD11165 $MN_ACCESS_WRITE_CST
– MD11166 $MN_ACCESS_WRITE_CMA
– MD11167 MN_ACCESS_WRITE_CUS
The execution right has to be set to at least the same protection level as the highest
protection level of the element used.
The write right must be set to at least the same protection level as the execution right.
● The write rights of the local HMI cycle directories must be set to the same protection level
as the local NC cycle directories.
To structure access protection further, subprograms (SPF or MPF identifier) can be called in
ACCESS files. The subprograms inherit the execution rights of the calling ACCESS file.
Note
Only access rights can be redefined in the ACCESS files. All other attributes have to
continue to be programmed/redefined in the corresponding definition files.
See also
Variables (Page 17)
1.1.10 Overview of definable and redefinable attributes
The following tables show which attributes can be defined (DEF) and/or redefined (REDEF) for
which data types.
System data
Data type Init. value Limit values Physical unit Access rights
Machine data --- --- --Setting data
REDEF
--- --FRAME data --- --- --Process data --- --- --Leadscrew error comp. (EEC) --- --- --Sag compensation (CEC) --- --- --Quadrant error compensation (QEC) --- --- --Magazine data --- --- --Tool data --- --- --Protection zones --- --- --Toolholder, with orientation capability --- --- --Kinematic chains --- --- --3D protection zones --- --- --Working area limitation --- --- --ISO tool data --- --- ---
Data type Init. value Limit values Physical unit Access rights
R-parameters
Synchronized action variable ($AC_...)
Synchronized action GUD (SYG_...)
EPS parameters
Tool data OEM
Magazine data OEM
Global user variables (GUD)
Local user variables (PUD/LUD)
<string length>: Maximum number of characters for a STRING data type
<variable name>: Variable name.
[<n>,<m>,<o>]: Array sizes or array indices
<n>:
<m>:
<o>:
SET: Value assignment using specified value list
(<value1>,<value2>, etc.): Value list
REP: Value assignment using specified <value>
<value>: Value, which the array elements should be written when
<number_array_elements>: Number of array elements to be written with the specified
Data type of variables
Range of values:
for system variables:
BOOL, CHAR, INT, REAL, STRING, AXIS
for GUD or LUD variables:
BOOL, CHAR, INT, REAL, STRING, AXIS, FRAME
Array size or array index for 1st dimension
Type: INT (for system variables, also AXIS)
Range of values: Max. array size: 65535
Array index: 0 ≤ n ≤ 65534
Array size or array index for 2nd dimension
Type: INT (for system variables, also AXIS)
Range of values: Max. array size: 65535
Array index: 0 ≤ m ≤ 65534
Array size or array index for 3rd dimension
Type: INT (for system variables, also AXIS)
Range of values: Max. array size: 65535
Array index: 0 ≤ o ≤ 65534
initializing with
<value>. The following apply to the remaining array elements,
REP.
dependent on the point in time:
Initialization when defining the array:
→ Zero is written to the remaining array elements.
→ The actual values of the array elements remain unchanged.
If the parameter is not programmed, all array elements are
written with
<value>.
If the parameter equals zero, the following apply dependent on
the point in time:
Initialization when defining the array:
→ All elements are pre-assigned zero
Assignment during program execution:
→ The actual values of the array elements remain unchanged.
47
Flexible NC programming
1.1 Variables
Array index
The implicit sequence of the array elements, e.g. in the case of value assignment using SET
or REP, is right to left due to iteration of the array index.
Example: Initialization of a 3-dimensional array with 24 array elements:
Definition and initialization of array variables (DEF, SET, REP): Further Information
(Page 49)
Variables (Page 17)
1.1.12 Definition and initialization of array variables (DEF, SET, REP): Further
Information
Further information (SET)
initialization during 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.
● If the value list contains more values than there are array elements defined, an alarm will
be displayed.
Data type Significance Value Range
INT Integer with sign -2147483648 ... +2147483647
REAL Real number (LONG REAL to IEEE) ±(∼2.2*10
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
The following data type conversions are possible and are performed implicitly during
assignments and parameter transfers:
+308
)
See also
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
Variables (Page 17)
Job Planning
52Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
1.1.14 Explicit data type conversions (AXTOINT, INTTOAX)
Function
The data type of an axis variable can be converted explicitly with the predefined functions
AXTOINT and INTTOAX.
Type conversion AXIS → INT
Syntax:
<result>=AXTOINT(<value>)
Meaning:
<result>:
AXTOINT: AXTOINT converts the data type of a axis variable from AXIS to INT
<value>:
INT representation of the axis variables (≙ axis index <n>)
In case of fault
= 7 NO_AXIS, i.e. <value> contains the value "no axis"
= -1 <value> is not an axis name of type AXIS
Geometry axis name (MD20060 $MC_AXCONF_GEOAX_NAME_TAB[<n>])
or
Channel axis name (MD20080 $MC_AXCONF_CHANAX_NAME_TAB[<n>])
or
Machine axis name (MD10000 $MN_AXCONF_MACHAX_NAME_TAB[<n>])
Data type: AXIS
Type conversion INT → AXIS
Syntax:
<result>=INTTOAX(<value>)
<result>:
INTTOAX: INTTOAX converts the data type of a axis variable from INT to AXIS
AXIS representation of the axis variables (≙ axis name)
In case of fault
= NO_AXIS <value> contains the value "no axis"?
= -1 <value> is an INT value for which there is no axis name of type
INT value of the axis variables <value>:
Range of
values:
Example
See example of GETVARDFT at "Read attribute values / data type (GETVARPHU,
GETVARAP, GETVARLIM, GETVARDFT, GETVARTYP) (Page 56)".
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
NCK.
Syntax
<Result>=ISVAR(<variable>)
Meaning
The transfer parameter
Undimensioned $ variable:
One-dimensional $ variable without array index:
One-dimensional $ variable with array index:
Two-dimensional $ variable without array index:
Two-dimensional $ variable with array index:
<result>:
ISVAR: Checks whether system/user variable is known in the NCK
<variable> can be set up as follows:
$<identifier>
$<identifier>[ ]
$<identifier>[<n>]
$<identifier>[,]
$<identifier>[<n>,<m>]
Return value
Data type: BOOL
Range of values:
Name of the system/user variables <identifier>:
Data type: STRING
Array index for first dimension <n>:
Data type: INT
Array index for second dimension <m>:
Data type: INT
1 Variable available
0 Variable unknown
The following checks are made in accordance with the transfer parameter:
● Does the identifier exist
● Is it a 1- or 2-dimensional array
● Is the array index permitted
Only if all these checks have a positive result will TRUE (1) be returned. If a check has a
negative result or if a syntax error has occurred, it will return FALSE (0).
Job Planning
54Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
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-
dimensional 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
permitted.
N40 IS_VAR=ISVAR("VARARRAY[8,8") ; IS_VAR is FALSE, "]" missing (syntax
error).
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.
1.1.16 Read attribute values / data type (GETVARPHU, GETVARAP, GETVARLIM,
GETVARDFT, GETVARTYP)
The attribute values of system/user variables can be read with the predefined GETVARPHU,
GETVARAP, GETVARLIM and GETVARDFT functions, the data type of a system/user
variable with GETVARTYP.
Read physical unit
Syntax:
<Result>=GETVARPHU(<name>)
Meaning:
<result>:
GETVARPHU: Reading of the physical unit of a system/user variable
<name>: Name of the system/user variables
Data type: STRING
Numeric value of the physical unit
Data type: INT
Range of
values:
See Table in "Attribute: Physical unit (PHU) (Page 37)"
In case of fault
- 2 The specified <name> has not been assigned to a
system parameter or a user variable.
Example:
The NCK 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
variables.
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.
Job Planning
56Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.1 Variables
Read access right
Syntax:
<Result>=GETVARAP(<name>,<access>)
Meaning:
<result>:
GETVARAP: Reading of the access right to a system/user variable
<access>:
Protection level for the specified <access>
Data type: INT
Range of
values:
0 ... 7 See "Attribute: Access rights (APR, APW, APRP,
APWP, APRB, APWB) (Page 39)".
In case of fault
- 2 The specified <name> has not been assigned to a system
parameter or a user variable.
- 3 Incorrect value for
Name of the system/user variables <name>:
Data type: STRING
Type of access
Data type: STRING
Range of
values:
"RP": Read via part program
"WP": Write via part program
"RB": Read via OPI
"WB": Write via OPI
<access>
Example:
Program code Comment
DEF INT result=0
result=GETVARAP("$TC_MAP8","WB") ; Determine the access protection for
the system 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.
GETVARDFT: Reading of the default value of a system/user variable
<result>:
<index_1>:
<index_2>:
<index_3>:
Function status
Data type: INT
Range of
values:
Name of the system/user variables <name>:
Data type: STRING
Return of the default value
Data type:
Index to the first dimension (optional)
Data type: INT
Not programmed means = 0
Index to the second dimension (optional)
Data type: INT
Not programmed means = 0
Index to the third dimension (optional)
Data type: INT
Not programmed means = 0
1 OK
-1 No default value available
(e.g. because <result> has the wrong type for <name>)
-2 The specified <name> has not been assigned to a system
parameter or a user variable.
-3 Incorrect value for <index_1>, dimension less than one (=
no array = scalar)
-4 Incorrect value for <index_2>
-5 Incorrect value for <index_3>
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)
CALL "L" << R10 ; Call the program, whose number is located in R10
(string cascading).
1.2.2 Indirectly programming G codes
Function
Indirect programming of G codes permits cycles to be effectively programmed.
Syntax
G[<group>]=<number>
Meaning
G[...]: G command with extension (index)
<group>:
Index parameter: G function group
Type: INT
<number>:
Variable for the G code number
Type: INT or REAL
Note
Generally, only G codes that do not determine the syntax can be indirectly programmed.
Only G function group 1 is possible from the G codes that determine the syntax.
The syntax-determining G codes of G function groups 2, 3 and 4 are not possible.
Note
Arithmetic functions are not permitted in the indirect G code programming. If it is necessary
to calculate the G code number, this must be done in a separate part program line before the
indirect G code programming.
Job Planning
64Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.2 Indirect programming
Examples
Example 1: Settable zero offset (G function 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 code calculation
N1110 G[8]=INT_VAR G1 X0 Y0 ; G55
Example 2: Level selection (G function group 6)
Program code Comment
N2010 R10=$P_GG[6] ; read active G function of G function
group 6
...
N2090 G[6]=R10
References
For information on the G function groups, see:
Programming Manual, Fundamentals; Section "G function groups"
1.2.3 Indirectly programming position attributes (GP)
Function
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
Application
The indirect programming of 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
would otherwise branch for all possible position attributes.
<POSITIONING COMMAND>[]: The following positioning commands can be programmed
together 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
<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, ...)
AX
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
14 CDC POS, POSA
15 CACP POS, POSA
16 CACN POS, POSA
Job Planning
66Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.2 Indirect programming
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 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
1.2.4 Indirectly programming part program lines (EXECSTRING)
Function
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
Example
With
EXECSTRING all part program constructions that can be programmed in the program
section of a part program can be extracted. This means that
PROC and DEF instructions are
excluded as well as the general use in INI and DEF files.
Program code Comment
N100 DEF STRING[100] BLOCK ; Definition of string variables to
accept the part program line to be
executed.
N110 DEF STRING[10] MFCT1="M7"
...
N200 EXECSTRING(MFCT1 << "M4711") ; Execute part program line "M7 M4711".
...
N300 R10=1
N310 BLOCK="M3"
N320 IF(R10)
N330 BLOCK = BLOCK << MFCT1
N340 ENDIF
N350 EXECSTRING(BLOCK) ; Execute part program line "M3 M7".
Job Planning
68Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.3 Arithmetic functions
1.3 Arithmetic functions
Function
The arithmetic functions are primarily for R parameters and variables (or constants and
functions) of type REAL. The types INT and CHAR are also permitted.
(type INT)/(type INT)=(type REAL); example: 3/4 = 0.75
Division, for variable type INT and REAL
Notice:
(type INT)DIV(type INT)=(type INT); example: 3 DIV 4 = 0
Modulo division (only for type INT) supplies remainder of an
INT division
Example: 3 MOD 4 = 3
Chain operator (for FRAME variables)
Sine
Cosine
Tangent
Arc sine
Arc cosine
Arc tangent 2
Square root
Absolute value
2nd power (square)
Integer component
The accuracy for comparison commands can be set using
TRUNC (see "Precision correction on comparison errors
RUNC) (Page 73)")
(T
Round to integer
Natural logarithm
Exponential function
Lower value of two variables
(see "Variable minimum, maximum and range (MINVAL,
MAXVAL and BOUND) (
Page 74)")
Larger value of two variables
(see "Variable minimum, maximum and range (MINVAL,
Variable value within the defined value range
(see "Variable minimum, maximum and range (MINVAL,
CTRANS()
CROT ()
CSCALE()
CMIRROR()
MAXVAL and BOUND) (
Offset
Rotation
Change of scale
Mirroring
Page 74)")
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°).
Example 1: ATAN2
The arithmetic function
ATAN2 calculates the angle
5 $7$1
of the total vector from two
mutually perpendicular
vectors.
The result is in one of four
VWYHFWRU
QGYHFWRU
$QJOH r
quadrants (-180° < 0 <
+180°).
The angular reference is
5 $7$1
$QJOH r
always based on the 2nd
value in the positive direction.
VWYHFWRU
QGYHFWRU
Example 2: Initializing complete variable arrays
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.
Job Planning
70Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.4 Comparison and logic operations
Program code Comment
R14=(R1+R2)*R3 ; Parentheses are calculated first.
R15=SQRT(POT(R1)+POT(R2)) ; Inner parentheses are resolved first:
R15 = square root of (R1+R2)
RESFRAME=FRAME1:FRAME2
FRAME3=CTRANS(…):CROT(…)
; The concatenation operator links frames
to form a resulting frame or assigns values
to frame components.
1.4 Comparison and logic operations
Function
Comparison operations can be used, for example, to formulate a jump condition. Complex
expressions can also be compared.
Programming
The comparison operations are applicable to variables of type
code value is compared with the
For types
for
STRING, AXIS and FRAME, the following are possible: == and <>, which can be used
STRING type operations, even in synchronous actions.
The result of comparison operations is always of
CHAR type.
BOOL type.
Logic operators are used to link truth values.
The logical operations can only be applied to type
applied to the
CHAR, INT and REAL data types via internal type conversion.
BOOL variables. However, they can also be
For the logic (Boolean) operations, the following applies to the
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.
Relational operator Meaning
==
<>
>
<
>=
<=
Equal to
Not equal to
Greater than
Less than
Greater than or equal to
Less than or equal to
Bit-by-bit AND
Bit-by-bit OR
Bit-by-bit negation
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
Examples
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.
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
Job Planning
72Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.5 Precision correction on comparison errors (TRUNC)
1.5 Precision correction on comparison errors (TRUNC)
Function
The TRUNC command truncates the operand multiplied by a precision factor.
Settable precision for comparison commands
Program data of type REAL are 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 for relative equality.
Syntax
Precision correction on comparison errors
Significance
TRUNC (R1*1000)
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.
1.6 Variable minimum, maximum and range (MINVAL, MAXVAL and BOUND)
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
rRetVar=BOUND(rVar1,rVar2,rVar3) ; rVar3 is within the limits, rRetVar is set to 19.7.
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.
1.7 Priority of the operations
Function
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
Job Planning
76Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.8 Possible type conversions
1.8 Possible type conversions
Function
Type conversion on assignment
The constant numeric value, the variable, or the expression assigned to a variable must be
compatible with the variable type. If this is this 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) Yes
BOOL yes yes yes yes yes – –
CHAR yes yes Yes
STRING – – Yes
1)
yes yes – –
4)
Yes
AXIS – – – – – yes –
FRAME – – – – – – yes
2)
– – –
3)
yes – –
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".
In addition to the classic operations "assign" and "comparison" the following string
operations are possible:
● Type conversion to STRING (AXSTRING) (Page 78)
● Type conversion from STRING (NUMBER, ISNUMBE
● Concatenation of strings (<<) (Page 81)
● Conversion to lower/upper case letters
● Determine length of string (STRLEN) (Page 83)
● Search for character/string in the s
● Selection of a substring (SUBSTR) (Page 85)
● Reading and writing of individual characters (Page 85)
● Formatting a string (SPRINT) (Page 87)
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
STRG[6]=0
MSG(STRG) ; Supplies the message "axis".
R, AXNAME) (Page 79)
(TOLOWER,
ring (INDEX, RINDEX, MINDEX, MATCH) (Page 83)
t
TOUPPER) (Page 82)
stationary".
1.9.1 Type conversion to STRING (AXSTRING)
Function
Using the function "type conversion to STRING" variables of different types can 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 81)")..
An INT value is converted to
decimal places.
Type AXIS variables can be converted to STRING using the
Job Planning
78Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
normal readable format. REAL values convert with up to 10
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>
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>
Examples
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]<<BAUSTEIN_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 "<<".
TOUPPER: Using the TOUPPER command, all of the letters in a character string are
converted into upper case letters.
TOLOWER: Using the TOLOWER command, all of the letters in a character string are
converted into lower case letters.
<string>:
Character string that is to be converted
Type: STRING
<STRING_ERG>:
Variable for the result of the conversion
Type: STRING
Because user inputs can be initiated on the operator interface, they can be given standard
capitalization (upper or lower case):
Program code
DEF STRING [29] STRG
...
IF "LEARN.CNC"==TOUPPER(STRG) GOTOF LOAD_LEARN
Job Planning
82Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
1.9.5 Determine length of string (STRLEN)
Function
The STRLEN command can be used to determine the length of a character string.
Syntax
<INT_ERG>=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>:
<INT_ERG>:
Character string whose length is to be determined
Type: STRING
Variable for the result of the determination
Type: INT
Example
In conjunction with the single character access, this function allows the end of a character
string to be determined:
Program code
IF (STRLEN(BAUSTEIN_NAME)>10) GOTOF ERROR
1.9.6 Search for character/string in the string (INDEX, RINDEX, MINDEX, MATCH)
Function
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.
Search functions: It supplies the position in the string (fist 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 transferred (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 ("/").
<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
...
EXTERN UP_VAL(ACHSE) ; Definition of subprogram with
"call by value" parameters
Job Planning
86Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
Program code Comment
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"
1.9.9 Formatting a string (SPRINT)
Function
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
%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
variable 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 character string "CONTENT OF REAL_VAR:-1234.123400" is written
to the string variable RESULT.
Job Planning
88Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
%<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 roundedoff 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 character string "CONTENT OF REAL_VAR: xx-1234.123457" is
written to the string variable RESULT ("x" in the example represents spaces).
%.<n>F: Conversion into a string with a decimal number with <n> decimal places. Where
relevant, 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 roundedoff 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.
: 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 written to the string variable RESULT ("x" in the example represents spaces).
%.<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).
Job Planning
90Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
%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.
%<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).
: 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 selected, 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).
Job Planning
92Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
%.<n>P
: Converting a REAL value into an INTEGER value taking into account <n> decimal
places. 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 instruction
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
complete 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.
%<m>S: Inserting a string with a minimum of <m> characters. The missing places are filled
: 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.
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.
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).
Job Planning
94Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.9 String operations
%.<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 upper case and
lower case letters for identifiers and keywords, also applies to the format descriptions. As a
consequence, you can program using either lower case or upper case 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 (Pag
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.
1.10 Program jumps and branches
1.10.1 Return jump to the start of the program (GOTOS)
Function
The GOTOS command can be used to jump back to the beginning of a main or sub program in
order to repeat the program.
Machine data can be used to set that for every return jump to the beginning of the program:
● The program runtime is set to "0".
● Workpiece counting is incremented by the value "1".
Syntax
GOTOS
Job Planning
96Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.10 Program jumps and branches
Meaning
GOTOS:
Jump instruction 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 resumed 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
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.
Example
Program code Comment
N10 ... ; Beginning of the program
...
N90 GOTOS ; Jump to beginning of the program
...
1.10.2 Program jumps to jump markers (GOTOB, GOTOF, GOTO, GOTOC)
Function
Jump markers (labels) can be set in a program, that can be jumped to from another location
within the same program using the commands
execution is resumed with the instruction that immediately follows the destination marker.
This means that branches can be realized within the program.
GOTOF, GOTOB, GOTO or GOTOC. Program
GOTOS
In addition to jump markers, main and sub-block numbers are possible as jump designation.
If a jump condition (
IF ...) is formulated before the jump instruction, the program jump is
GOTOB: Jump instruction with jump destination towards the beginning of the
program.
GOTOF: Jump instruction with jump destination towards the end of the program.
GOTO: Jump instruction 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 following the GOTOC command.
<jump destination>:
IF: Keyword to formulate the jump condition.
Jump destination parameter
Possible data include:
<jump marker>: Jump destination is the jump marker (label) set
in the program with a user-defined name: <
marker>:
jump
<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 marker or a block number.
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.
Job Planning
98Programming Manual, 03/2013, 6FC5398-2BP40-3BA1
Flexible NC programming
1.10 Program jumps and branches
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 (":").
Supplementary conditions
● The jump destination can only be a block with jump marker or block number, that is
located within the program.
● A jump instruction without jump condition must be programmed in a separate block. This
restriction does not apply to jump instructions with jump conditions. In this case, several
jump instructions can be formulated in a block.
● For programs with jump instructions without jump conditions, the end of the program
M2/M30 doesn't necessarily have to be be at the end of the program.
Examples
Example 1: Jumps to jump markers
Program code Comment
N10 …
N20 GOTOF Label_1 ; Jump towards the end of the program to the jump
1.10.3 Program branch (CASE ... OF ... DEFAULT ...)
Function
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.
fulfilled, then a jump in the
direction of the beginning of the
program to jump marker LA1.