Extended Identifiers as IEC 61131-3 Variable Names
According to the IEC 61131-3 standard, variable names can consist of letters, digits and underscores. The identifier has to begin with a letter or an underscore. The use of any other character causes the compiler error "Illegal identifier".
This naming convention has been expanded in PLCnext Engineer in a way that IEC variable names can also contain extended qualifiers.
This topic contains the following sections:
- Enabling extended identifiers in PLCnext Engineer
- Rules for using extended identifiers as IEC 61131-3 variable names
- Restriction: Extended identifiers vs. literals
- Extended identifiers vs. regular operators in ST
- Examples for extended identifiers
Enabling extended identifiers in PLCnext Engineer
To use extended identifiers as described in this topic, the feature must be activated in PLCnext Engineer as follows:
- Select 'Extras > Options'.
- Open the 'Compiler > IEC Compiler Settings' section, activate the 'Allows extended identifiers' checkbox and confirm the 'Options' dialog.
- Restart PLCnext Engineer to apply the settings.
The use of extended qualifiers applies to both standard (non-safety-related) and safety-related variables.
Rules for using extended identifiers as IEC 61131-3 variable names
If extended identifiers are activated in the 'Options' dialog, a variable name can be composed as follows: so-called "divider" characters can be mixed with Unicode letters and digits. Dividers are optionally possible at the beginning, in the middle and at the end of an identifier as shown in the following syntax scheme:
(Whitespaces as shown in this representation for reasons of clarity are not allowed.)
[DividerBegin] {UnicodeLetterOrDigit [DividerMiddle]} (UnicodeLetterOrDigit [DividerEnd])
Meaning of the bracket types in this scheme:
() | Exactly one element is required |
[] | Zero or one element is allowed |
{} | Zero or n elements are allowed |
This means that all dividers are optional but at least one Unicode letter/digit is mandatory.
Which character you may use as dividers depends on the position in the identifier (begin, middle, end):
DividerBegin | You can use one of the following list items as DividerBegin, combinations of these list items are not possible.
|
DividerMiddle | You can use one of the following list items as DividerMiddle, combinations of these list items are not possible.
|
DividerEnd | You can use one of the following list items as DividerEnd, combinations of these list items are not possible.
|
Restriction: Extended identifiers vs. literals
Although the "#" character is allowed as divider, variable names must not start like a constant with <literal_prefix>#.
literal_prefix is not case-sensitive and includes the following keywords: BOOL, SAFEBOOL, REAL, LREAL, SINT, SAFESINT, USINT, SAFEUSINT, INT, SAFEINT, UINT, SAFEUINT, DINT, SAFEDINT, UDINT, SAFEUDINT, LINT, ULINT, BYTE, SAFEBYTE, WORD, SAFEWORD, DWORD, SAFEDWORD, LWORD, TIME, SAFETIME, T, DATE, D, LTIME, LT, LDATE, LD, TIME_OF_DAY, TOD, DATE_AND_TIME, DT, STRING, TIMEDATE48, WEIGHT, ANALOG, UNIFRACT, BIFRACT200, FIXED, BOOLEAN2, BCD4, ENUM4.
Example:
buffer#value is allowed as variable name.
INT#MyVar is forbidden, since Integer literals start like this (e.g.,
INT#100).
- Binary: 2# (e.g. 2#10101010)
- Octal: 8# (e.g. 8#15)
- Decimal: 10# (e.g.10#125)
- Hexadecimal: 16# (e.g. 16#AB)
Regarding the use of time literals the following applies: If extended identifiers are enabled, time literals must always be specified with a type prefix ( T# or TIME# or SAFETIME# respectively). Otherwise, the literal will be interpreted as variable. 500ms would be considered as variable, whereas TIME#500ms is a correct time literal.
Extended identifiers vs. regular operators in ST
If the characters / * - + < > shall be used as regular operators in textual programming languages, they must be separated from their related operands by so-called whitespaces. Whitespaces are blanks, tabulators and line breaks. In this context, please observe the note "Possible impact ..."' below.
Examples:- a+b is considered as a variable
- a + b represents the addition of two variables
Note
Possible impact on already existing projects After activating the use of extended qualifiers while editing/compiling an already existing project (edited without this feature and thus with "traditional" IEC variable identifiers), you have to ensure that no unintended results occur. Verify that operators and operands are separated by whitespaces before compiling. Otherwise, these code parts are considered as IEC variables consisting of extended qualifiers. |
Examples for extended identifiers
Example | Description |
---|---|
:A12 | Valid because ":" is allowed as DividerBegin |
#_A12 | Invalid because the combination of "#" and "_" is not allowed as DividerBegin |
=A:12 | Valid because "=" is allowed as DividerBegin and ":" is allowed as DividerMiddle |
=A__12 | Valid because multiple "_" are allowed as DividerMiddle |
A--->A | Valid because one ">" is allowed after multiple "-" as DividerMiddle |
=A12<< | Valid because multiple "<" are allowed as DividerEnd |
=A12<> | Invalid because the combination of "<" and ">" is not allowed as DividerEnd |