Reference programming Example: TRAFFIC_SIGNAL: (red, yellow, green); COLOR: (blue, white, red); Error: red may not be used for both TRAFFIC_SIGNAL and COLOR. 7.1.2.4 Structures (STRUCT) Structures are created as objects in the Object Organizer under the register card Data types. They begin with the keyword TYPE and end with END_TYPE.The syntax for structure declarations is as follows: TYPE : STRUCT . . END_STRUCT END_TYPE is a type that is recognized throughout the project and can be used like a standard data type. Interlocking structures are allowed. The only restriction is that variables may not be placed at 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 You can gain access to structure components using the following syntax: . For example, if you have a structure named "Week" that contains a component named "Monday", you can get to it by doing the following: Week.Monday NOTICE Different structures Due to different alignments, structures and arrays may have different configurations and sizes on different hardware platforms (e.g. CX1000 and CX90xx).
During data exchange the size and structure alignment must be identical! Example for a structure definition with name ST_ALIGN_SAMPLE: TYPE ST_ALIGN_SAMPLE: STRUCT _diField1 : DINT; _byField1 : BYTE; _iField : INT; _byField2 : BYTE; _diField2 : DINT; _pField : POINTER TO BYTE; END_STRUCT END_TYPE On CX90xx (RISC) platforms the member components of structure ST_ALIGN_SAMPLE have the following sizes and offsets:
_diField1 (DINT), Offset = 0 (16#0), Size = 4 _byField1 (BYTE), Offset = 4 (16#4), Size = 1 _iField (INT), Offset = 6 (16#6), Size = 2 _byField2 (BYTE), Offset = 8 (16#8), Size = 1 _diField2 (DINT), Offset = 12 (16#C), Size = 4 _pField (POINTER TO BYTE), Offset = 16 (16#10), Size = 4 TX1200 188 Version: 1.3