Literals according to IEC 61131-3
Where constant numeric values, character strings or time data values are to be used in the code, for example, for connecting them to a formal parameter of a function/function block, literals can be used instead of constant variables. Literals are directly entered "hard-coded" constant values or strings. The IEC 61131-3 standard designates literals as "external representation of data". Literals can directly be entered in the code. It is not necessary to specify a declaration.
The IEC 61131-3 standard describes different literal types, according to the basic data types.
Furthermore, safety-related literals can be used according to the safety-related data types.
This topic contains the following sections:
Numeric literals
Type | Examples | |
---|---|---|
Integer literals | -12 0 123_456 +986
|
|
Real literals | -12.0 0.0 0.4560 3.14159_26 | |
Real literals with exponent | -1.34E-12 -1.34e-12 1.0E+6 | |
Long Real literals | LREAL#-12.0Observe the 2nd note below this table. | |
Long Real literals with exponent | LREAL#2.3E-89Observe the 2nd note below this table. | |
Base 2 literals | INT#2#1111_1111 | |
Base 8 literals | INT#8#377 | |
Base 16 literals | INT#16#FF SINT#16#ff | |
Boolean FALSE and TRUE | FALSE, TRUESAFEFALSE, SAFETRUE | |
Boolean 0 and 1 | 0, 1For SAFEBOOL literals, always SAFEFALSE, SAFETRUE has to be used. |
Note
INT literals can be used without keyword. Example: for INT#16#ff, you can use 16#ff. BOOL/SAFEBOOL literals can also be used without keyword. Examples: for BOOL#FALSE, you can use FALSE and for SAFEBOOL#FALSE, you can use SAFEFALSE. |
Note
If you are using PLCnext Engineer in another user interface language and/or with another Windows system locale than English you must enter numeric values with a '.' as decimal separator (always according to the English standard). This applies, for example, when entering initial values in variables tables or REAL/LREAL literals in the code. |
Character string literals
Character string literals include single-byte or double-byte encoded characters.
A single-byte character string literal is a sequence of zero or more characters enclosed in single quote characters (''). A double-byte character string literal is a sequence of zero or more characters enclosed in double quote characters ("").
Type | Examples |
---|---|
Single-byte character strings | |
Empty string | '' |
String with one space character | ' ' |
Not empty string | 'this is a text' |
Double-byte character strings | |
Empty string | "" |
String with one space character | " " |
Not empty string | "this is a text" |
Date and time literals
Duration data can be represented in hours, minutes, seconds, milliseconds and in combination of these formats.
Type | Examples | |
---|---|---|
Short prefix | TIME data type: T#14ms t#14ms t#12m18s3.5ms T#25h_15m t#25h_15m
|
|
Long prefix | TIME data type: TIME#14 ms time#14ms TIME#25h_15m time#25h_15mSAFETIME data type: SAFETIME#14 ms safetime#14ms SAFETIME#25h_15m safetime#25h_15mLTIME data type: LTIME#14 ms time#14ms TIME#25h_15m time#25h_15m |
Further Info
See the section "Constant (Literal)" for information how to edit literals in the programming languages FBD/LD/SFC. |