-

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

TypeExamples
Integer literals-12 0 123_456 +986

Note
For SAFEINT literals, always the data type must be entered (SAFEINT#).

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 literalsLREAL#-12.0

Observe the 2nd note below this table.
Long Real literals with exponentLREAL#2.3E-89

Observe the 2nd note below this table.
Base 2 literalsINT#2#1111_1111
Base 8 literalsINT#8#377
Base 16 literalsINT#16#FF SINT#16#ff
Boolean FALSE and TRUEFALSE, TRUE

SAFEFALSE, SAFETRUE
Boolean 0 and 10, 1

For 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 ("").

TypeExamples
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 sequenceMeaning
\\Insert a backslash character in the string.
\n or \NInsert a new line in the string.
\t or \TInsert 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:

Escape sequenceOnline value
\\\
\n or \N (Unicode U+21B5)
(HMI shows text in multiline.)
\t or \T (Unicode U+2192)
(HMI shows ? character.)

The default tab size can be configured in the 'Extras > Options' dialog under the category 'Online | Online values'.
\''
\""

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.

TypeExamples
Short prefixTIME data type: T#14ms t#14ms t#12m18s3.5ms T#25h_15m t#25h_15m

Note
The short prefix representation is not allowed for SAFETIME literals.

LTIME data type: LT#14ms t#14ms t#12m18s3.5ms T#25h_15m t#25h_15m
Long prefixTIME data type: TIME#14 ms time#14ms TIME#25h_15m time#25h_15m

SAFETIME data type: SAFETIME#14 ms safetime#14ms SAFETIME#25h_15m safetime#25h_15m

LTIME data type: LTIME#14 ms time#14ms TIME#25h_15m time#25h_15m

Date and time of day literals

TypeExamples
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.