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
- Character string literals
- Escape sequences
- Date and time literals
- Date and time of day literals
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" |
Escape sequences
PLCnext Engineer supports character escaping in strings. Escape sequences are a combination of the backslash (\) followed by a special character. The backslash is used to escape certain characters such as tabulators (\t) or new lines (\n) inside the text string. Escape characters are used as IEC init values or on constants in code worksheets.
Note
To ensure compatibility with other programming languages supported by PLCnext Technology, IEC 61131-3 style escaping using the $ character is not any longer supported. Older projects that use the $ character for escaping are automatically updated. |
The following table shows the escape sequences supported in PLCnext Engineer.
Escape sequence | Meaning |
---|---|
\\ | Insert a backslash character in the string. |
\n or \N | Insert a new line in the string. |
\t or \T | Insert a tabulator in the string. |
\' | Insert a single quote character in the string (only valid for STRING values). |
\" | Insert a double quote character in the string (only valid for WSTRING values). |
Note
For any unsupported escape sequence, a build error will be generated (for example, string 'aaa\'). |
Strings with escape sequences in online mode
In online mode, the following characters are shown for escape sequences:
Note
In the force/overwrite controls (online code worksheet, FORCELIST window etc.), the <new line> and <tab> characters in the current online value are shown as \n and \t (not as \N and \T). To use these characters for forcing/overwriting you can enter the escape sequences \n, \N, \t , and \T. |
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 |
Date and time of day literals
Type | Examples |
---|---|
Long date |
LDATE#1996-01-24 ldate#1996-01-24 LD#1996-01-24 ld#1996-01-24 |
Long time of day |
LTIME_OF_DAY#15:36:55.36 ltime_of_day#15:36:55.36 LTOD#15:36:55.36 ltod#15:36:55.36 |
Long date with time of day |
LDATE_AND_TIME#1996-01-24-15:36:55.36 ldate_and_time#1996-01-24-15:36:55.36 LDT#1996-01-24-15:36:55.36 ldt#1996-01-24-15:36:55.36 |
Further Info
See the section "Constant (Literal)" for information how to edit literals in the programming languages FBD/LD/SFC. |