Syntax for accessing variables
This chapter explains the syntax for accessing variables, field and structure elements and bits from integer variables.
This syntax is used both when specifying property values and at the programmatic level. The variable selection dialogue provides simple support when specifying property values. All linkable PLC values, i.e. the individual variables and the field and structure elements, are listed here for selection. Individual bits can also be selected from the selected identifier. The result is provided as a character string for transfer. So if, for example, you are writing a generator that compiles variable identifiers and problems arise with this at runtime, it is a good idea to select the variables addressed once in the variable selection dialogue and compare the character strings with your own result.
<Ch><VarAlias><element resolution>
with
<Ch>- The name of the channel ends with a dot (e.g.
Ch1.). This part is omitted for internal variables. <VarAlias>- The alias of the variable definition.
<element resolution>- Partially nested specification of field index, structure element name or bit number enclosed by curly brackets ({}).
The following rules apply to element resolution:
- A field element is specified using the 0-based index. The field element index is enclosed in square brackets ([]).
- A structure element is specified via the structure element name. The structure element name is identified by a leading dot and is not numerical.
- A bit number is specified via the 0-based bit index. The bit index is identified by a leading dot and is purely numerical.
- A bit range is specified via the 0-based bit indices of the start and end bit. The start bit is expected first, characterised by a leading dot, followed by the end bit, characterised by two leading dots.
Examples
The syntax examples shown below are interpreted from left to right:
MyInternalVar- Access to the internal variable
MyInternalVar. Ch1.MyVar-
Variable
MyVarin communication channelCh1. See notes below. Ch1.Simulation.MyVar-
Variable
Simulation.MyVarin communication channelCh1.Note: The variable name may contain dots that allow it to be divided into namespaces. The communication channel name must not contain a dot. Ch1..Simulation.Variable1-
Variable
.Simulation.MyVarin communication channelCh1.By specifying a dot at the beginning of the variable alias, an empty namespace is created. This is used with some PLC types to designate global variables.
Ch1.Simulation.MyVar{.7}-
Variable
Simulation.MyVarin communication channelCh1, access to bit7.Used for Boolean logic (e.g.: set a bit at the push of a button).
Ch1.Simulation.MyVar{.0..3}- Variable
Simulation.MyVarin communication channelCh1, access to bit group 0..3(4 bits). Ch1.Simulation.MyVar{[2]}- Variable
Simulation.MyVardefined as field in communication channelCh1(field size <> 0), access to field element2. Ch1.Simulation.MyVar{[2].7}-
Variable
Simulation.MyVardefined as a field in communication channelCh1(field size <> 0), access to field element2, bit7.Used for Boolean logic (e.g.: set a bit at the push of a button).
Ch1.MyStructVar{.Var1}-
Variable
MyStructVarin communication channelCh1, access to structure elementVar1.A structure is specified as the data type in
MyStructVar. Ch1.MyStructVar{.Var1.5}-
Variable
MyStructVarin communication channelCh1, access to bit 5 in structure elementVar1.A structure is specified as the data type in
MyStructVar. Ch1.MyStructVar{.Var1[2].5}-
Variable
MyStructVarin communication channelCh1, access to structure elementVar1, here access to field element2and in turn access to bit5.A structure is specified as the data type in
MyStructVar. A structure element can be a field or a structure itself. Ch1.MyStructVar{.Var1.SubVar1}-
Variable
MyStructVarin communication channelCh1, access to structure elementVar1and therein to structure elementSubVar1.A structure is specified as the data type in
MyStructVar. A structure element can be a field or a structure itself. Ch1.MyStructVar{.SS3[0].SubS2[10].15}-
Variable
MyStructVarin communication channelCh1, access to structure elementSS3therein to field element0, therein to structure elementSubS2, therein to field element10, therein to bit15.A structure is specified as the data type in
MyStructVar. A structure element can be a field or a structure itself. MyStructVar{.SS3[2].SubS2[22].0..8}-
Variable
MyStructVarin communication channelCh1, access to structure elementSS3therein to field element2, therein to structure elementSubS2, therein to field element22, therein to bit range 0..8.A structure is specified as the data type in
MyStructVar. A structure element can be a field or a structure itself.
The specification of variable names must be character-accurate, i.e. note the following
- Upper/lower case
- Space at the beginning or end of a variable identifier
The use of special characters in channel names, variable aliases and structure element names, which are used to resolve the syntax, is largely prevented by the development system. Nevertheless, an error may occur in the project when resolving a variable identifier if, for example, the project file is edited directly.
Another conflict that has not yet been resolved by the development environment is the assignment of aliases for internal variables. If the name of a channel is specified as the leading namespace here, an ambiguity arises that cannot be resolved by the system.
Example: Name of an internal variable Ch1.w0 leads to a conflict with the variable w0 in channel Ch1. Avoid such ambiguities!