Create structures in a project as DUT (Data Type Unit) objects via the
dialog box.
They begin with the keywords TYPE
and STRUCT
and end with END_STRUCT
and END_TYPE
.
TYPE <structurename>:
STRUCT
<declaration of variables 1>
...
<declaration of variables n>
END_STRUCT
END_TYPE
<structurename> is a type that is recognized throughout the project and can be used like a standard data type.
Nested structures are allowed. The only restriction is that variables may not be assigned to addresses (the AT
declaration is not allowed).
Example for a structure definition named Polygonline
:
TYPE Polygonline:
STRUCT
Start:ARRAY [1..2] OF INT;
Point1:ARRAY [1..2] OF INT;
Point2:ARRAY [1..2] OF INT;
Point3:ARRAY [1..2] OF INT;
Point4:ARRAY [1..2] OF INT;
End:ARRAY [1..2] OF INT;
END_STRUCT
END_TYPE
Example:
Poly_1:polygonline := ( Start:=[3,3], Point1:=[5,2], Point2:=[7,3], Point3:=[8,5], Point4:=[5,7], End:= [3,5]);
Initializations with variables are not possible. For an example of the initialization of an array of a structure, refer to Arrays.
You can gain access to structure components using the following syntax:
<structurename>.<componentname>
For the previous example of the structure Polygonline
, you can access the component Start
by Poly_1.Start
.
The data type BIT is a special data type which can only be defined in structures. It consumes memory space of 1 bit and allows you to address single bits of a structure by name.
TYPE <structurename>:
STRUCT
<bitname bit1> : BIT;
<bitname bit2> : BIT;
<bitname bit3> : BIT;
...
<bitname bitn> : BIT;
END_STRUCT
END_TYPE
You can gain access to the structure component BIT
by using the following syntax:
<structurename>.<bitname>
BIT
variables is not possible. Furthermore, BIT
variables are not allowed in arrays.