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
with a safety alert symbol, indicates that minor personal injury can result if proper precautions are not taken.
CAUTION
without a safety alert symbol, indicates that property damage can result if proper precautions are not taken.
NOTICE
indicates that an unintended result or situation can occur if the corresponding information is not taken into account.
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 for the specific task, 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 adhered to. The information in the relevant documentation must be observed.
Trademarks
All names identified by ® are registered trademarks of the SiemensAG. 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
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
Technical Support
This Programming Guide 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.
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, 02/2011, 6FC5398-2BP40-1BA0
Information on structure and contents
"Fundamentals" and "Advanced" Programming Manual
The description of the NC programming is divided into two manuals:
1. Fundamentals
This "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
The Programming Manual "Advanced" 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.
Preface
Availability of the described NC language elements
All NC language elements described in the manual are available for the SINUMERIK 840Dsl.
The availability regarding SINUMERIK828D can be found in table"Operations: Availability for
SINUMERIK 828D [Page 877]" of the "".
2.3Structuring instruction in step editor (SEFORM) ..................................................................... 227
3Protection zones .....................................................................................................................................229
3.1Definition of the protection zones (CPROTDEF, NPROTDEF) ............................................... 229
3.2Activating/deactivating protection zones (CPROT, NPROT)................................................... 233
3.3Checking for protection zone violation, working area limitation and software limits
11.2Oscillation controlled by synchronized actions (OSCILL) ........................................................ 657
12Punching and nibbling .............................................................................................................................665
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. For this
purpose the system makes three different types of variable available.
•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, to a large extent, predefined by the system and its
properties are fixed. 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 commands (REDEF) [Page 31]".
•User variables
1
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:
-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 commands
(REDEF) [Page 31]".
-User-defined variables
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 25]".
Attribute: Physical unit (PHU) Attribute: Physical unit (PHU) [Page 39]
Attribute: Access rights (APR, APW, APRP, APWP, APRB, APWB) Attribute: Access rights
(APR, APW, APRP, APWP, APRB, APWB) [Page 41]
Overview of definable and redefinable attributes Overview of definable and redefinable
attributes [Page 46]
Definition and initialization of array variables (DEF, SET, REP) Definition and initialization of
array variables (DEF, SET, REP) [Page 47]
Data types Data types [Page 55]
1.1.2System variables
System variables are variables which are predefined in the system and provide access to the
actual parameter settings associated with the control, as well as machine, control, and
process statuses, in part programs and cycles.
Preprocessing variables
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)
Job planning
18Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Prefix system
Flexible NC programming
1.1 Variables
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.
$ + 1. LetterSignificance: Data type
System variables which are read/written during preprocessing
$M
$S
Machine data
Setting data, protection zones
$TTool management data
$PProgrammed values
$CCycle variables of ISO envelope cycles
$OOption data
R
R-parameters (arithmetic parameters)
System variables which are read/written during the main run
$$M
$$S
Machine data
Setting data
$AUp-to-date main run data
$VServo data
$R
1)
When machine and setting data are used in the part program/cycle as preprocessing variables, the
R-parameters (arithmetic parameters)
prefix is written with one $ sign. When they are used in synchronized actions as main run variables,
the prefix is written with two $ signs.
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.
Use of machine and setting data in synchronized actions
When machine and setting data are 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.
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:
Program code
ID=1 WHENEVER G710 $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:
Program code
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.
References
See also
A list of the properties of all system variables appears in:
List Manual, system variable
General information about variables General information about variables [Page 17]
Job planning
20Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.1.3Predefined 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.
When using synchronized actions, the $ sign must be included as a prefix, e.g. $R10.
Syntax
When used as a preprocessing variable:
R<n>
R[<expression>]
When used as a main run variable:
$R<n>
$R[<expression>]
Flexible NC programming
1.1 Variables
Significance
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 to 9999 9999)
Note:
A maximum of 8 decimal places are permitted.
For an exponential notation:
± (1*10
-300
to 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.
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 into the INT data type (INT, REAL,
BOOL, CHAR).
Example
Assignments to R-parameters and use of R-parameters in mathematical functions:
Program codeComment
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
See also
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)
General information about variables General information about variables [Page 17]
Job planning
22Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.1.4Predefined 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 control as
additional global user variables alongside global user variables (GUD).
<index>: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, etc.
– $A_DLW[i]: i = 0, 2, 4, etc.
– $A_DLD[i]: i = 0, 4, 8, etc.
– $A_DLR[i]: i = 0, 8, 16, etc.
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.
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]
Job planning
24Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
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.
Program code
N222 IDS=1 WHEN $A_DLR[16] > 23.0 DO SETAL(61000)
See also
General information about variables General information about variables [Page 17]
1.1.5Definition of user variables (DEF)
Function
Flexible NC programming
1.1 Variables
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 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.
•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.
DEF:Command for defining GUD, PUD, LUD user variables
<range>:Range of validity, only relevant for GUD:
NCK:NC-global user variable
CHAN:Channel-global user variable
<type>: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 55]"
<PP_stop>:Preprocessing stop, only relevant for GUD (optional)
SYNR:Preprocessing stop while reading
SYNW:Preprocessing stop while writing
SYNRW:Preprocessing stop while reading/writing
Job planning
26Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
<init_time>:Point in time at which the variable is reinitialized (optional)
INIPO:PowerOn
INIRE:End of main program, NC reset or PowerOn
INICF:NewConfig or end of main program, NC reset or
PowerOn
PRLOC:End of main program, NC reset following local
change or PowerOn
See "Attribute: Initialization value [Page 34]"
<phys_unit>:Physical unit (optional)
PHU <unit>:
See "Attribute: Physical unit (PHU) [Page 39]"
<limit values>:Lower and upper limit value (optional)
LLI <limit value>:Lower limit value (lower limit)
ULI <limit value>:Upper limit value (upper limit)
See "Attribute: Limit values (LLI, ULI) [Page 37]"
<access rights>: Access rights 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
See "Attribute: Access rights (APR, APW, APRP, APWP, APRB,
APWB) [Page 41]"
<name>: Name of variable
Note
•A maximum of 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>,
Specification of array sizes for 1- to max. 3-dimensional array
variables (optional)
<value_3>]:
<init_value>:Initialization value (optional)
See "Attribute: Initialization value [Page 34]"
For the initialization of array variables:
See "Definition and initialization of array variables (DEF, SET, REP)
In the context of the definition of global user variables (GUD), the following machine data has
to be taken into account:
No.Identifier: $MN_Significance
11140GUD_AREA_ SAVE_TABAdditional save for GUD blocks
1)
18118
18120
18130
18140
18150
18660
18661
18662
18663
18664
18665
MM_NUM_GUD_MODULESNumber of GUD files in the active file system
1)
MM_NUM_GUD_NAMES_NCKNumber of global GUD names
1)
MM_NUM_GUD_NAMES_CHANNumber of channel-spec. GUD names
1)
MM_NUM_GUD_NAMES_AXISNumber of axis-spec. GUD names
1)
MM_GUD_VALUES_MEMMemory location for global GUD values
1)
MM_NUM_SYNACT_GUD_REALNumber of configurable GUD of the REAL data
type
1)
MM_NUM_SYNACT_GUD_INTNumber of configurable GUD of the INT data
type
1)
MM_NUM_SYNACT_GUD_BOOLNumber of configurable GUD of the BOOL data
type
1)
MM_NUM_SYNACT_GUD_AXISNumber of configurable GUD of the AXIS data
type
1)
MM_NUM_SYNACT_GUD_CHARNumber of configurable GUD of the CHAR data
type
1)
MM_NUM_SYNACT_GUD_STRINGNumber of configurable GUD of the STRING
data type
1)
For SINUMERIK 828D, MD can only be read!
Program-global user variables (PUD)
NOTICE
Visibility of program-local user variables (PUD)
Program-local 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-local 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.
Job planning
30Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
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 (see "") has to be used.
Program codeComment
DEF NCK STRING[5] ACHSE="X"; Definition in the data block
N100 AX[AXNAME(ACHSE)]=111 G00; Use in the part program
See also
General information about variables General information about variables [Page 17]
1.1.6Redefinition of system variables, user variables, and NC language commands
(REDEF)
Function
Syntax
The REDEF command can be used to change system variable, user variable and NC
language command attributes. 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 REDEF
operation 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.
Redefinable attributes
See "Overview of definable and redefinable attributes [Page 46]".
Local user variables (PUD/LUD)
Redefinitions are not permitted for local user variables (PUD/LUD).
REDEF:Command for the redefinition of a specific system variable, user
variable, and NC language command attribute
<name>: Name of a predefined variable or an NC language command
<PP stop>:Preprocessing stop
SYNR:Preprocessing stop while reading
SYNW:Preprocessing stop while writing
SYNRW:Preprocessing stop while reading/writing
<phys_unit>:Physical unit
PHU <unit>:
See "Attribute: Physical unit (PHU) [Page 39]"
Note
Cannot be redefined for:
•System variables
•Global user data (GUD)
•Data types: BOOL, AXIS, STRING, FRAME
<limit values>: Lower and/or upper limit value
LLI <limit value>:Lower limit value (lower limit)
ULI <limit value>:Upper limit value (upper limit)
See "Attribute: Limit values (LLI, ULI) [Page 37]"
Note
Cannot be redefined for:
•System variables
•Global user data (GUD)
•Data types: BOOL, AXIS, STRING, 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
See "Attribute: Access rights (APR, APW, APRP, APWP, APRB,
APWB) [Page 41]"
Range of values: 0 to 7
Job planning
32Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
<init_time>:Point in time at which the variable is reinitialized
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 34]"
<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 34]"
For the initialization of array variables:
See "Definition and initialization of array variables (DEF, SET, REP)
[Page 47]"
Note
Cannot be redefined for:
•System variables, with the exception of setting data
1.1 Variables
Example
Redefinitions of system variable $TC_DPC1 in the data block for machine manufacturers
Program code
%_N_MGUD_DEF; GUD block: Machine manufacturer
$PATH=/_N_DEF_DIR
REDEF $TC_DPC1 APWB 2 APWP 3
REDEF $TC_DPC1 PHU 21
REDEF $TC_DPC1 LLI 0 ULI 200
REDEF $TC_DPC1 INIPO (100, 101, 102, 103)
; Description
Write access right: 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.
;
; Physical unit = [ % ]
; Limit values: lower = 0, upper = 200
; The array variable is initialized with the 4 values at POWER ON.
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.
See also
General information about variables General information about variables [Page 17]
1.1.7Attribute: 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)
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)
Job planning
34Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
Reinitialization time
During redefinition a 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
(see the table below).
1) This G command is used to address the setting data.
G command
OSB
1)
Initialization value: Global user variables (GUD)
•Only INIPO (POWER ON) can be defined as the initialization time for global user
variables (GUD) with the NCK range of validity.
•In addition to INIPO (POWER ON), INIRE (reset) or INICF (NewConfig) can be defined
as the initialization time for global user variables (GUD) with the CHAN range of validity.
•In the case of global user variables (GUD) with the CHAN range of validity and INIRE
(reset) or INICF (NewConfig) initialization time, for an NC reset, mode group reset and
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 FRAME data type.
Variables of the FRAME data type are initialized implicitly and always with the default frame.
Initialization value: CHAR data type
For variables of the CHAR data type, instead of the ASCII code (0...255), the corresponding
ASCII character can be programmed in quotation marks, e.g. "A".
Initialization value: STRING data type
In the case of variables of the STRING data type, the character string must be enclosed in
quotation marks, e.g. ...= "MACHINE_1"
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).
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.
Job planning
36Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
Implicit initialization value: AXIS data type
For variables of the AXIS data type the following implicit initialization value is used:
Axis identifier from machine data: MD20082 $MC_AXCONF_CHANAX_DEFAULT_NAME
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
NOTICE
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.
See also
General information about variables General information about variables [Page 17]
1.1.8Attribute: 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 codeComment
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
General information about variables General information about variables [Page 17]
Job planning
38Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.1.9Attribute: 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>MeaningPhysical unit
0Not a physical unit1
2
3Angular position [ degree ]
4
5
6Angular velocity [ rpm ]
7
8
9Angular acceleration
10
11
12Angular jerk
13Time[ s ]
14Position controller gain[ 16.667/s ]
15
16
18Force [ N ]
19Mass [ kg ]
20
21Percent[ % ]
22Frequency [ Hz ]
23Voltage [ V ]
24Current [ A ]
25Temperature[ °C ]
26Angle [ degree ]
27KV [ 1000/min ]
28
1) The physical unit is dependent 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.
2)
[ m/s], [ feet/s ]
[ Nm ]
3)
3)
3)
[ Nm/A ]
[ Nm/(rad*s) ]
[ μNm ]
[ cm3 ]
3)
3)
3)
[ mm/(V*min) ]
[ mm/rev ], [ inch/rev ]
[ mm/rev / rev ], [ inch/rev / rev ]
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
40Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
NOTICE
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
General information about variables General information about variables [Page 17]
1.1.10Attribute: 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 rightProtection level
System password0
Machine manufacturer password1
Service password2
End user password3
Key-operated switch position 34
Key-operated switch position 25
Key-operated switch position 16
Key-operated switch position 07
1.1 Variables
Definition (DEF) of user variables
Access rights (APR.../APW...) can be defined for the following variables:
The cycle must be saved in a cycle directory and must contain a PROC operation.
Access rights in relation to part programs and cycles (APRP, APWP)
The various access rights facilitate the following with regard to access in a part program or
cycle:
•APRP 0/APWP 0
-During part program processing the system password has to be set.
-The cycle has to be stored in the _N_CST_DIR directory (system).
-The execution right must be set to system for the _N_CST_DIR directory in MD11160
$MN_ACCESS_EXEC_CST.
•APRP 1/APWP 1 or APRP 2/APWP 2
-During part program processing the machine manufacturer or service password has to
be set.
-The cycle has to be stored in the _N_CMA_DIR (machine manufacturer) or
_N_CST_DIR (system) directory.
-The execution rights must be set to at least machine manufacturer for the
_N_CMA_DIR or _N_CST_DIR directories in machine data MD11161
$MN_ACCESS_EXEC_CMA or MD11160 $MN_ACCESS_EXEC_CST respectively.
-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.).
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.
APR/APW access attributes
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
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.
Job planning
44Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
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.
References
/BAD/ Operating Manual, HMI Advanced,
Chapter: Services operating area > Data administration > Modify properties
Subprogram calls in ACCESS files
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
General information about variables General information about variables [Page 17]
1.1.11Overview 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 typeInit. valueLimit valuesPhysical unitAccess rights
Machine data--------Setting data
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---------
REDEF
------
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
REDEF
User data
Data typeInit. valueLimit valuesPhysical unitAccess 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)
REDEFREDEFREDEFREDEF
REDEFREDEFREDEFREDEF
REDEFREDEFREDEFREDEF
REDEFREDEFREDEFREDEF
REDEFREDEFREDEFREDEF
REDEFREDEFREDEFREDEF
DEF/REDEFDEFDEFDEF/REDEF
DEFDEFDEF
---
See also
General information about variables General information about variables [Page 17]
Job planning
46Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1.12Definition and initialization of array variables (DEF, SET, REP)
Function
A user variable can be defined as a 1- up to a maximum of a 3-dimensional array.
<string length>:Maximum number of characters for a STRING data
type
Job planning
48Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
<variable name>:Variable name.
[<n>,<m>,<o>]:Array sizes or array indices
<n>: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
<m>: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
<o>: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
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 initializing with REP.
<number_array_elements>:Number of array elements to be written with the
specified <value>. The following apply to the
remaining array elements, dependent on the point in
time:
•initialization when defining the array:
→ Zero is written to the remaining array elements.
•Assignment during program execution:
→ 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:
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:
DEF INT FELD[2,3,4] = REP(1,24)
FELD[0,0,0] = 1
FELD[0,0,1] = 1
FELD[0,0,2] = 1
FELD[0,0,3] = 1
...
FELD[0,1,0] = 1
FELD[0,1,1] = 1
...
FELD[0,2,3] = 1
FELD[1,0,0] = 1
FELD[1,0,1] = 1
...
FELD[1,2,3] = 1
1st array element
2nd array element
3rd array element
4th array element
5th array element
6th array element
12th array element
13th array element
14th array element
24th array element
corresponding to:
FOR n=0 TO 1
FOR m=0 TO 2
FOR o=0 TO 3
FELD[n,m,o] = 1
ENDFOR
ENDFOR
ENDFOR
Job planning
50Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Example: Initializing complete variable arrays
For the actual assignment, refer to the diagram.
Program code
N10 DEF REAL FELD1[10,3]=SET(0,0,0,10,11,12,20,20,20,30,30,30,40,40,40,)
Definition and initialization of array variables (DEF, SET, REP): Further Information Definition
and initialization of array variables (DEF, SET, REP): Further Information [Page 52]
General information about variables General information about variables [Page 17]
1.1.13Definition 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.
Value assignment in program execution
In the case of value assignment in program execution, the rules described above for definition
apply. The following options are also supported:
•Expressions are also permitted as elements in the value list.
•Value assignment starts with the programmed array index. Values can be assigned
selectively to subarrays.
Example:
Program codeComments
DEF INT ARRAY[5,5]; Array definition
ARRAY[0,0]=SET(1,2,3,4,5); Value assignment to the first 5 array
FELD[0,0]=SET(1,2, , ,5); Value assignment with gap to the first 5
ARRAY[2,3]=SET(VARIABLE,4*5.6); Value assignment with variable and
elements [0,0] - [0,4]
array elements [0,0] - [0,4], array
elements[0,2] and [0,3] = 0
expression starting at array index [2,3]:
[2,3] = VARIABLE
[2,4] = 4 * 5.6 = 22.4
Job planning
52Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Further information (REP)
initialization during definition
•All or the optionally specified number of array elements are initialized with the specified
value (constant).
•Variables of the FRAME data type cannot be initialized.
Example:
Program codeComments
DEF REAL varName[10]=REP(3.5,4); Initialize array definition and array
Value assignment in program execution
In the case of value assignment in program execution, the rules described above for definition
apply. The following options are also supported:
•Expressions are also permitted as elements in the value list.
•Value assignment starts with the programmed array index. Values can be assigned
selectively to subarrays.
Flexible NC programming
1.1 Variables
elements [0] to [3] with value 3.5.
Examples:
Program codeComments
DEF REAL varName[10]; Array definition
varName[5]=REP(4.5,3); Array elements [5] to [7] = 4.5
R10=REP(2.4,3); R-parameters R10 to R12 = 2.4
DEF FRAME FRM[10]; Array definition
FRM[5] = REP(CTRANS (X,5)); Array elements [5] to [9] = CTRANS(X,5)
Further information (general)
Value assignments to axial machine data
In principle axial machine data have an array index of the AXIS data type. In the case of value
assignments to an axial item of machine data using SET or REP, this array index is ignored or
not processed.
Example: Value assignment to machine data MD36200 $MA_AX_VELO_LIMIT
NOTICE
Value assignments to axial machine data
In the case of value assignments to axial machine data using SET or REP, the AXIS data type
array index is ignored or not processed.
Memory requirements
Data typeMemory requirement per element
BOOL
CHAR
INT
REAL
STRING
FRAME
AXIS
1 byte
1 byte
4 bytes
8 bytes
(string length + 1) bytes
∼ 400 bytes, depending on the number of axes
4 bytes
See also
Definition and initialization of array variables (DEF, SET, REP) Definition and initialization of
array variables (DEF, SET, REP) [Page 47]
Job planning
54Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.1 Variables
1.1.14Data types
The following data types are available in the NC:
Data typeSignificanceValue Range
INTInteger with sign-2147483648 ... +2147483647
REALReal number (LONG REAL to IEEE)
BOOLTruth value TRUE (1) and FALSE (0)1, 0
CHARASCII characterASCII code 0 to 255
STRINGCharacter string of a defined lengthMaximum of 200 characters (no special characters)
AXISAxis/spindle identifierChannel axis identifier
FRAMEGeometric 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 →REALINTBOOL
REALxo&
INTxx&
BOOLxxx
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
General information about variables General information about variables [Page 17]
DEF AXIS AXVAR1=X; Defining a variable, type AXIS and value
assignment.
G2 X100 IP[AXVAR1]=20; Indirect programming the center point data for
the axis, whose address name is saved in the
variable with the name AXVAR1.
Example 6: Indirectly programming array elements
Direct programming:
Program codeComments
DEF INT ARRAY1[4,5]; Defining array 1
Indirect programming:
Program codeComments
DEFINE DIM1 AS 4; For array dimensions, array sizes must be
specified as fixed values.
DEFINE DIM2 AS 5
DEF INT ARRAY[DIM1,DIM2]
ARRAY[DIM1-1,DIM2-1]=5
Example 7: Indirect subprogram call
Program codeComments
CALL "L" << R10; Call the program, whose number is located in R10
(string cascading).
Job planning
58Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.2.2Indirectly 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
Flexible NC programming
1.2 Indirect programming
Examples
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.
Example 1: Settable zero offset (G function group 8)
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, refer to:
Programming Manual, Fundamentals; Chapter "G function groups"
1.2.3Indirectly programming position attributes (BP)
Function
Application
Syntax
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 BP.
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 CASE instruction is required, which
would otherwise branch for all possible position attributes.
For an active synchronous spindle coupling between the leading spindle S1 and the following
spindle S2, the following replacement cycle to position the spindle is called using the SPOS
command in the main program.
Positioning is realized using the instruction in N2230:
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 codeComments
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
•The indirect programming of position attributes is not possible in synchronized actions.
References
Function Manual Basic Functions; BAG, Channel, Program Operation, Reset Response (K1),
Chapter: Replacement of NC functions by subprograms
Job planning
62Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.2.4Indirectly 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
Flexible NC programming
1.2 Indirect programming
Example
Note
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 codeComment
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".
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)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
Arcsine
Arccosine
Arctangent2
Square root
Absolute value
2. power (square)
Truncate to integer
The accuracy for comparison commands can be set using
TRUNC (see "Precision correction on comparison errors
(TRUNC) [Page 69]")
Round to integer
Natural logarithm
Exponential function
Lower value of two variables
(see "Variable minimum, maximum and range (MINVAL,
MAXVAL and BOUND) [Page 71]")
Larger value of two variables
(see "Variable minimum, maximum and range (MINVAL,
MAXVAL and BOUND) [Page 71]")
Job planning
64Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
5 $7$1
5 $7$1
QGYHFWRU
QGYHFWRU
$QJOH r
$QJOH r
VWYHFWRU
VWYHFWRU
1.3 Arithmetic functions
Programming
Examples
BOUND ()
Variable value within the defined value range
(see "Variable minimum, maximum and range (MINVAL,
MAXVAL and BOUND) [Page 71]")
CTRANS()
CROT ()
CSCALE()
CMIRROR()
Translation
Rotation
Change of scale
Mirroring
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 of the total
vector from two mutually
perpendicular vectors.
The result is in one of four
quadrants (-180° < 0 < +180°).
The angular reference is always
based on the 2nd value in the
positive direction.
R14=R1*R2+R3; Multiplication or division takes precedence over
addition or subtraction.
R14=(R1+R2)*R3; Parentheses are calculated first.
R15=SQRT(POT(R1)+POT(R2)); Inner parentheses are resolved first:
RESFRAME=FRAME1:FRAME2
FRAME3=CTRANS(…):CROT(…)
R15 = square root of (R1+R2)
; The concatenation operator links frames
to form a resulting frame or assigns values
to frame components.
Job planning
66Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.4Comparison and logic operations
Function
Comparison operations can be used , for example, to formulate a jump condition. Complex
expressions can also be compared.
The comparison operations are applicable to variables of type CHAR, INT, REAL and BOOL.
The code value is compared with the CHAR type.
For types STRING, AXIS and FRAME, the following are possible: == and <>, which can be
used for STRING type operations, even in synchronous actions.
The result of comparison operations is always of BOOL type.
Logic operators are used to link truth values.
The logical operations can only be applied to type BOOL variables. However, they can also be
applied to the CHAR, INT and REAL data types via internal type conversion.
For the logic (Boolean) operations, the following applies to theBOOL, CHAR,INT and REAL
data types:
Flexible NC programming
1.4 Comparison and logic operations
Programming
•0 corresponds to: FALSE
•not equal to 0 means: TRUE
Bit logic operators
Logic operations can also be applied to single bits of types CHAR and INT. Type conversion is
automatic.
Relational operatorSignificance
==
<>
>
<
>=
<=
equal to
not equal to
greater than
less than
greater than or equal to
less than or equal to
Bit-serial AND
Bit-serial OR
Bit-serial negation
Bit-serial exclusive OR
Note
In arithmetic expressions, the execution order of all the operators can be specified by
parentheses, in order to override the normal priority rules.
Note
Spaces must be left between BOOLEAN operands and operators.
Note
The operator B_NOT only refers to one operand. This is located after the operator.
Examples
Example 1: Relational 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
68Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.5 Precision correction on comparison errors (TRUNC)
1.5Precision 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
TRUNC (R1*1000)
Flexible NC programming
Significance
TRUNC:Truncate decimal places
Relative quality of 10
•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.
-12
taken into account for
Synchronized actions
The response described for the comparison commands also applies to synchronized actions.
IF ABS(R12-R11) > R13 GOTOF ERROR; Jump is no longer executed
M30; End of program
ERROR: SETAL(66000);
Example 2: Calculate and evaluate the quotient of both operands
Program codeComments
R1=61.01 R2=61.02 R3=0.01; Assignment of initial values
IF ABS((R2-R1)/R3)-1) > 10EX-5 GOTOF ERROR; Jump is not executed
M30; End of program
ERROR: SETAL(66000);
; Accuracy correction
Job planning
70Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.6 Variable minimum, maximum and range (MINVAL, MAXVAL and BOUND)
1.6Variable minimum, maximum and range (MINVAL, MAXVAL and
BOUND)
Function
The MINVAL and MAXVAL commands can be used to compare the values of two variables.
The smaller value (in the case of MINVAL) or the larger value (in the case of MAXVAL)
respectively is delivered as a result.
The BOUND command can be used to test whether the value of a test variable falls within a
defined range of values.
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.
1.6 Variable minimum, maximum and range (MINVAL, MAXVAL and BOUND)
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 codeComments
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.
rVar3=1.8
rRetVar=BOUND(rVar1,rVar2,rVar3); rVar3 is below the minimum limit, rRetVar is set to
10.5.
rVar3=45.2
rRetVar=BOUND(rVar1,rVar2,rVar3); rVar3 is above the maximum limit, rRetVar is set to
33.7.
Job planning
72Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.7Priority 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_NOTNegation, bit-serial negation
2.*, /, DIV, MODMultiplication, division
3.+, –Addition, subtraction
4.B_ANDBit AND
5.B_XORBit-serial exclusive OR
6.B_ORBit-serial OR
7.ANDAND
8.XORExclusive OR
9.OROR
10.<<Concatenation of strings, result type STRING
11.==, <>, >, <, >=, <=Comparison operators
Flexible NC programming
1.7 Priority of the operations
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.
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 REALINTBOOLCHARSTRINGAXISFRAME
from
REALyesyes*
INTyesyes
BOOLyesyesyesyesyes––
CHARyesyes
STRING––
AXIS–––––yes–
FRAME ––––––yes
1
)
Yes
1
)Yes
Yes
1)
Yes
4)
Yes
yes*–––
2)
yesyes––
3)
Yes
–––
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".
Job planning
74Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.9String operations
Sting operations
In addition to the classic operations "assign" and "comparison" the following string operations
are possible:
•Type conversion to STRING (AXSTRING) [Page 76]
•Type conversion from STRING (NUMBER, ISNUMBER, AXNAME) [Page 77]
•Concatenation of strings (<<) [Page 78]
•Conversion to lower/upper case letters (TOLOWER, TOUPPER) [Page 79]
•Determine length of string (STRLEN) [Page 80]
•Search for character/string in the string (INDEX, RINDEX, MINDEX, MATCH) [Page 81]
•Selection of a substring (SUBSTR) [Page 82]
•Selection of a single character (STRINGVAR, STRINGFELD) [Page 83]
•Formatting a string (SPRINT) [Page 84]
Flexible NC programming
1.9 String operations
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.
The function "concatenation strings" allows a string to be configured from individual
components.
Syntax
Significance
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.
<any_type> << <any_type>
<any_type>:Variable, type CHAR, BOOL, INT, REAL or STRING
<< :Operator to chain variables (<any_type>) to configure a character string
(type STRING).
This operator is also available alone as a so-called "unary" variant. This
can be used for explicit type converter to STRING (not for FRAME and
AXIS):
<< <any_type>
For example, such a message or a command can be configured from text lists and
parameters can be inserted (for example a block name):
MSG(STRG_TAB[LOAD_IDX]<<BAUSTEIN_NAME)
CAUTION
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 "<<".
Job planning
78Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Examples
Flexible NC programming
1.9 String operations
Example 1: Concatenation of strings
Program codeComments
DEF INT IDX=2
DEF REAL VALUE=9.654
DEF STRING[20] STRG="INDEX:2"
IF STRG=="Index:"<<IDX GOTOF NO_MSG
MSG("Index:"<<IDX<<"/value:"<<VALUE); Didplay:
"Index:2/value:9.654"
NO_MSG:
Example 2: Explicit type conversion with <<
Program codeComments
DEF REAL VALUE=3.5
<<VALUE; The specified type REAL variable is converted into a
STRING type.
1.9.4Conversion to lower/upper case letters (TOLOWER, TOUPPER)
Function
The "conversion to lower/upper case letters" function allows all of the letters of a string to be
converted into a standard representation.
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
1.9.5Determine length of string (STRLEN)
Function
The STRLEN command can be used to determine the length of a character string.
Syntax
<INT_ERG>=STRLEN("<STRING>")
Significance
Example
STRLEN:TheSTRLEN command determines the length of the specified character
string.
The number of characters that are not the 0 character, counting from the
beginning of the string is returned.
<string>:Character string whose length is to be determined
Type:STRING
<INT_ERG>:Variable for the result of the determination
Type:INT
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
Job planning
80Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.9 String operations
1.9.6Search 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.
Syntax
INT_ERG=INDEX(STRING,CHAR) ; Result type: INT
INT_ERG=RINDEX(STRING,CHAR) ; Result type: INT
INT_ERG=MINDEX(STRING,STRING) ; Result type: INT
INT_ERG=MATCH(STRING,STRING) ; Result type: INT
Semantics
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.
Significance
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 ("/").
Example
Breaking up an input into path and block names
Program codeComments
DEF INT PFADIDX, PROGIDX
DEF STRING[26] INPUT
DEF INT LISTIDX
INPUT = "/_N_MPF_DIR/_N_EXECUTE_MPF"
LISTIDX = MINDEX (INPUT, "M,N,O,P") + 1; The value returned in LISTIDX is 3;
because "N" is the fist character in
the parameter INPUT from the
selection list starting from the
beginning.
PFADIDX = INDEX (INPUT, "/") +1; Therefore the following applies:
PFADIDX = 1
PROGIDX = RINDEX (INPUT, "/") +1; Therefore the following applies:
PROGIDX = 12
The SUBSTR function introduced in the
next section can be used to break-up
variable INPUT in the components
"path" and "module":
VARIABLE = SUBSTR (INPUT, PFADIDX, PROGIDX-PFADIDX-1); Then returns "_N_MPF_DIR"
VARIABLE = SUBSTR (INPUT, PROGIDX); Then returns "_N_EXECUTE_MPF"
1.9.7Selection of a substring (SUBSTR)
Function
This functionality extracts a substring from a string. For this purpose, the index of the first
character and the desired string length (if applicable) are specified. If no length information is
specified, then the string data refers to the remaining string.
Syntax
Example
STRING_ERG = SUBSTR (STRING,INT) ; Result type: INT
STRING_ERG = SUBSTR(STRING,INT, INT) ; Result type: INT
Semantics
In the first case, the substring from the position specified by the second parameter is returned
up to the end of the string.
In the second case, the result string is limited to the maximum length, specified by the third
parameter.
If the initial position is after the end of the string, the empty string (" ") will be returned.
If the initial position or the length is negative, an alarm is output.
Program codeComments
DEF STRING[29] ERG
ERG = SUBSTR ("ACK:10 to 99", 10, 2); Therefore the following
applies: ERG == "10"
Job planning
82Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.9 String operations
1.9.8Selection of a single character (STRINGVAR, STRINGFELD)
Function
This functionality selects a single character from a string. This applies both to read access
and write access operations.
Syntax
CHAR_ERG = STRINGVAR [IDX] ; Result type: CHAR
CHAR_ERG = STRINGFELD [IDX_FELD, IDX_CHAR] ; Result type: CHAR
Semantics
The character at the specified position is read/written within the string. If the position
parameter is negative or greater than the string, then an alarm is output.
Example messages:
Insertion of an axis identifier into a prepared string.
Program codeComments
DEF STRING [50] MESSAGE = "Axis n has reached position"
MESSAGE [6] = "X"
MSG (MESSAGE); Returns the message "axis X has
reached position"
Parameters
Examples
Single character access is possible only to user-defined variables (LUD, GUD, and PUD
data).
This type of access is also possible only for "call-by-value" type parameters in subprogram
calls.
Example 1: Single character access to system data, machine data, etc.
Using the pre-defined SPRINT function, character strings can be formatted and e.g. prepared
for output on external devices (also see "Output to an external device/file (EXTOPEN,
WRITE, EXTCLOSE) [Page 710]").
"<Format_String>":Character string that contains fixed and
variable elements. The variable elements
are defined using the format control
character % and a subsequent format
description.
<value_1>,<value_2>,…,<value_n>:Value in the form of a constant or NC
variables, which is inserted at the location
where the nth format control character % is
located, corresponding to the format
description in the <format_string>.
"<result_string>":Formatted character string (maximum 400
bytes)
Job planning
84Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Format descriptions available
%B:Conversion into the "TRUE" string, if the value to be converted:
%C:Conversion into an ASCII character.
%D:Conversion into a string with an integer value (INTEGER).
%<m>D:Conversion into a string with an integer value (INTEGER). The string has a
%F:Conversion into a string with a decimal number with 6 decimal places. Where
Flexible NC programming
1.9 String operations
•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.
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.
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.
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).
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.
%<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.
%<m>E:Conversion into a string with a decimal number in the exponential representation
and a total length of at least <m> characters. The missing characters are filled with
spaces, left-justified. The mantissa is saved, normalized with one pre-decimal
place and 6 decimal places. Where relevant, the decimal places are rounded-off or
filled with 0. The exponent starts with the keyword "EX". It is followed by the sign
("+" or "-") and a two or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%20E",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxxxxx-1.234500EX+03"
is written to the string variable RESULT ("x" in the example represents spaces).
Job planning
86Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.9 String operations
%.<n>E:Conversion into a string with a decimal number in the exponential representation.
The mantissa is saved, normalized with one pre-decimal place and <n> decimal
places. Where relevant, the decimal places are rounded-off or filled with 0. The
exponent starts with the keyword "EX". It is followed by the sign ("+" or "-") and a
two or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5678
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%.2E",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:-1.23EX+03" is written to
the string variable RESULT.
%<m>.<n>E:Conversion into a string with a decimal number in the exponential representation
and a total length of at least <m> characters. The missing characters are filled with
spaces, left-justified. The mantissa is saved, normalized with one pre-decimal
place and <n> decimal places. Where relevant, the decimal places are rounded-off
or filled with 0. The exponent starts with the keyword "EX". It is followed by the sign
("+" or "-") and a two or three-digit number.
Example:
N10 DEF REAL REAL_VAR=-1234.5678
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%12.2E", REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xx-1.23EX+03" is written
to the string variable RESULT ("x" in the example represents spaces).
%G:Conversion into a string with a decimal number – depending on the value range – in
a decimal or exponential representation: If the absolute value to be represented is
less than 1.0EX-04 or greater than/equal to 1.0EX+06, then the exponential
notation is selected, otherwise the decimal notation. A maximum of six significant
places are displayed or if required, rounded-off.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:0.000123457" is written to
the string variable RESULT.
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+06
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:1.23457EX+06" is written
to the string variable RESULT.
%<m>G:Conversion into a string with a decimal number – depending on the value range – in
a decimal or exponential notation (like %G). The string has a total length of at least
<m> characters. The missing characters are filled with spaces, left-justified.
Example with decimal notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX-04
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%15G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxxx0.000123457" is
written to the string variable RESULT ("x" in the example represents spaces).
Example with exponential notation:
N10 DEF REAL REAL_VAR=1.234567890123456EX+06
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF REAL_VAR:%15G",REAL_VAR)
Result: The character string "CONTENT OF REAL_VAR:xxx1.23457EX+06" is
written to the string variable RESULT ("x" in the example represents spaces).
%.<n>G:Conversion into a string with a decimal number – depending on the value range – in
a decimal or exponential representation. A maximum of <n> significant places are
displayed or if required, rounded-off. If the absolute value to be represented is less
than 1.0EX-04 or greater than/equal to 1.0EX(+<n>), then the exponential notation
is 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
88Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
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 %.<n>P can also
contain binary zeroes, then the total string that is generated in this way no longer
corresponds to the conventions of the NC data type STRING. As a consequence, it
can neither be saved in a variable, type STRING, nor be further processed using
the string commands of the NC language. The only possible use is to transfer the
parameter to the WRITE command with output at an appropriate external device
(see the following example).
As soon as the <Format_String> contains a format description, type %P then the
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>.<n>P:Conversion of a REAL value corresponding to the setting in machine data
MD10751$MN_SPRINT_FORMAT_P_DECIMAL into a string with:
•an integer number of <m> + <n> places or
•a decimal number with a maximum of <m> pre-decimal places and precisely
<n> decimal places.
Just the same as for the format description %.<n>P, the complete string is saved in
the character code defined by MD10750 $MN_SPRINT_FORMAT_P_CODE.
Conversion for MD10751 = 0:
The REAL value is converted into a string with an integer number of <m> + <n>
places. If required, decimal places are rounded-off to <n> places or filled with 0.
The missing pre-decimal places are filled with spaces. The minus sign is attached,
left-justified; a space is entered instead of the plus sign.
Example:
N10 DEF REAL REAL_VAR=-123.45
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("PUNCHED TAPE FORMAT:%5.3P",REAL_VAR)
Result: The character string "PUNCHED TAPE FORMAT:-xx123450" is written to
the string variable RESULT ("x" in the example represents spaces).
Conversion for MD10751 = 1:
The REAL value is converted into a string with a decimal number with a maximum
of <m> pre-decimal places and precisely <n> decimal places. Where necessary,
the pre-decimal places are cut-off and the decimal places are rounded-off or filled
with 0. If <n> is equal to 0, then the decimal point is also omitted.
Example:
N10 DEF REAL REAL_VAR1=-123.45
N20 DEF REAL REAL_VAR2=123.45
N30 DEF STRING[80] RESULT
N40 RESULT=SPRINT("PUNCHED TAPE FORMAT:%5.3P VAR2:%2.0P",
REAL_VAR1,REAL_VAR2)
Result: The character string "PUNCHED TAPE FORMAT:-123.450 VAR2:23" is
written to the string variable RESULT.
%S:Inserting a string.
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%S",STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:ABCDEFG" is written
to the string variable RESULT.
%<m>S:Inserting a string with a minimum of <m> characters. The missing places are filled
with spaces.
Example:
N10 DEF STRING[16] STRING_VAR="ABCDEFG"
N20 DEF STRING[80] RESULT
N30 RESULT=SPRINT("CONTENT OF STRING_VAR:%10S",STRING_VAR)
Result: The character string "CONTENT OF STRING_VAR:xxxABCDEFG" is
written to the string variable RESULT ("x" in the example represents spaces).
%.<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.
Job planning
90Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.9 String operations
%<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 [Page 55]").
Note
The table indicates that the NC data types AXIS and FRAME cannot be directly used in the
SPRINT function. However it is possible:
•to convert the AXIS data type into a string using the AXSTRING function – which can then
be processed with SPRINT.
•to read the individual values of the FRAME data type per frame component access. As a
consequence, a REAL data type is obtained, which can be processed with SPRINT.
Job planning
92Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
1.10Program jumps and branches
1.10.1Return 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
Flexible NC programming
1.10 Program jumps and branches
Significance
GOTOS:Jump instruction where the destination is the beginning of the program.
Supplementary conditions
•GOTOS internally initiates a STOPRE (pre-processing stop).
•For a subprogram with data definitions (LUD variables) with the GOTOS a jump is made to
the first program block after the definition section, i.e. data definitions are not executed
again. This is the reason that the defined variables retain the value reached in the GOTOS
block and are not reset to the standard values programmed in the definition section.
•The GOTOS command is not available in synchronized actions and technology cycles.
The execution is controlled via the NC/PLC interface signal:
DB21, to DBX384.0 (control program branching)
Value:Significance:
0No return jump to the beginning of the program. Program
execution is resumed with the next part program block after
GOTOS.
1Return jump to the beginning of the program. The part program is
1.10.2Program 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 GOTOF, GOTOB, GOTO or GOTOC. Program
execution is resumed with the instruction that immediately follows the destination marker.
This means that branches can be realized within the program.
In addition to jump markers, main and sub-block numbers are possible as jump designation.
Syntax
Significance
If a jump condition (IF ...) is formulated before the jump instruction, the program jump is
only executed if the jump condition is fulfilled.
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.
Job planning
94Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.10 Program jumps and branches
<jump
destination>:
Jump destination parameter
Possible data include:
<jump marker>:Jump destination is the jump marker (label) set
in the program with a user-defined name:
<jump marker>:
<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.
IF:Keyword to formulate the jump condition.
The jump condition permits all comparison and logical operations
(result: TRUE or FALSE). The program jump is executed if the result of
this operation is TRUE.
Note
Jump markers (labels)
Jump markers (labels) 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:
– At least 2
– A maximum of 32
•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.
1.10.3Program 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.
Flexible NC programming
1.10 Program jumps and branches
fulfilled, then a jump in the
direction of the beginning of the
program to jump marker LA1.
CASE:Jump statement
<expression>:Variable or arithmetic function
OF:Keyword to formulate conditional program branches.
<constant_1>:First specify constant value for the variable or arithmetic function
Type:INT
<constant_2>:Second specified constant value for the variable or arithmetic
function
Type:INT
DEFAULT:For the cases where the variable or arithmetic function does not
assume any of the specified constant values, the DEFAULT
instruction can be used to determine the branch destination.
Note:
If the DEFAULT instruction is not programmed, then in these
cases, the block following the CASE instruction is the jump
destination.
The CASE instruction from N30 defines the following program branch possibilities:
1. If the value of the arithmetic function VAR1+VAR2-VAR3=7, then jump to the block with
the jump marker definition "Label_1" ( → N40).
2. If the value of the arithmetic function VAR1+VAR2-VAR3=9, then jump to the block with
the jump marker definition "Label_2" ( → N50).
3. If the value of the arithmetic function VAR1+VAR2-VAR3 is neither 7 nor 9, then jump to
the block with the jump marker definition "Label_3" ( → N60).
Job planning
98Programming Manual, 02/2011, 6FC5398-2BP40-1BA0
Flexible NC programming
1.11 Repeat program section (REPEAT, REPEATB, ENDLABEL, P)
1.11Repeat program section (REPEAT, REPEATB, ENDLABEL, P)
Function
Program section repetition allows you to repeat existing program sections within a program in
any order.
The program lines or program sections to be repeated are identified by jump markers (labels).
Note
Jump markers (labels)
Jump markers are always located at the beginning of a block. If a program number exists, the
jump marker is located immediately after the block number.
The following rules apply when naming jump markers:
•Number of characters:
–Minimum 2
–Maximum 32
•The following characters are permitted:
–Letters
– Numbers
– Underscores
•The first two characters must be letters or underscores.
•The name of the jump marker is followed by a colon (":").
Syntax
1. Repeat individual program line:
<jump marker>: ...
...
REPEATB <jump marker> P=<n>
...
2. Repeat program section between jump marker and REPEAT statement: