Constant expressions
Constant expressions can be used in all languages for assigning a variable with a value. All constant expressions have a well defined data type according to their semantics. If you program an operation between variables and constant expressions having inconsistent data types, it will lead to syntactic errors when the program is compiled. Below are the syntactic rules for constant expressions according to possible data types:
BOOL: Boolean
There are only two possible boolean constant expressions. They are reserved keywords TRUE and FALSE.
SINT: Small (8 bit) Integer
Small integer constant expressions are valid integer values (between -128 and 127) and must be prefixed with SINT#. All integer expressions having no prefix are considered as DINT integers.
USINT / BYTE: Unsigned 8 bit Integer
Unsigned small integer constant expressions are valid integer values (between 0 and 255) and must be prefixed with USINT#. All integer expressions having no prefix are considered as DINT integers.
INT: 16 bit integer
16 bit integer constant expressions are valid integer values (between -32768 and 32767) and must be prefixed with INT#. All integer expressions having no prefix are considered as DINT integers.
UINT / WORD: Unsigned 16 bit integer
Unsigned 16 bit integer constant expressions are valid integer values (between 0 and 255) and must be prefixed with UINT#. All integer expressions having no prefix are considered as DINT integers.
DINT: 32 bit (default) integer
32 bit integer constant expressions must be valid numbers between -2147483648 to +2147483647. DINT is the default size for integers: such constant expressions do not need any prefix. You can use 2#, 8# or 16# prefixes for specifying a number in respectively binary, octal or hexadecimal basis.
UDINT / DWORD: Unsigned 32 bit integer
Unsigned 32 bit integer constant expressions are valid integer values (between 0 and 4294967295) and must be prefixed with UDINT#. All integer expressions having no prefix are considered as DINT integers.
LINT: Long (64 bit) integer
Long integer constant expressions are valid integer values and must be prefixed with LINT#. All integer expressions having no prefix are considered as DINT integers.
REAL: Single precision floating point value
Real constant expressions must be valid number, and must include a dot ("."). If you need to enter a real expression having an integer value, add .0 at the end of the number. You can use F or E separators for specifying the exponent in case of a scientist representation. REAL is the default precision for floating points: such expressions do not need any prefix.
LREAL: Double precision floating point value
Real constant expressions must be valid number, and must include a dot ("."), and must be prefixed with LREAL#. If you need to enter a real expression having an integer value, add .0 at the end of the number. You can use F or E separators for specifying the exponent in case of a scientist representation.
TIME: Time of day
Time constant expressions represent durations that must be t#49d17h2m47s295ms. Expressions must be prefixed by either TIME# or T#. They are expressed as a number of hours followed by h, a number of minutes followed by m, a number of seconds followed by s, and a number of milliseconds followed by ms. The order of units (hour, minutes, seconds, milliseconds) must be respected. You cannot insert blank characters in the time expression. There must be at least one valid unit letter in the expression.
STRING: Character string
String expressions must be written between single quote marks. The length of the string cannot exceed 255 characters. You can use the following sequences to represent a special or not printable character within a string:
Sequence |
Description |
$$ |
a "$" character |
WSTRING: UNICODE character string encoded as UTF16
WTRING expressions must be written between double quote marks (").You can use the following sequences to represent a special or not printable character within a UNICODE string:
|
|
|
||||||||
Sequence |
Description |
|
||||||||
$$ |
a "$" character |
|
||||||||
|
||||||||||
Below are some examples of valid constant expressions:
Below are some examples of typical errors in constant expressions:
|
Constant expressions |
IEC 61131-3 Automation platform > Programming - Reference guide > Constant expressions |
Created with the Personal Edition of HelpNDoc: Maximize Your Documentation Capabilities with a Help Authoring Tool