Attention
IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include structures and user defined function blocks.
Array Types¶
An array is a fixed-size indexed collection of elements of the same type.
IEC 61131-3 |
Section 2.3.3.1 |
Support |
Not yet supported |
Syntax¶
ARRAY [ lower_bound .. upper_bound ] OF element_type
Arrays can be declared inline in variable declarations or as named types.
Example¶
TYPE
TenInts : ARRAY [1..10] OF INT;
END_TYPE
PROGRAM main
VAR
values : ARRAY [0..9] OF DINT;
matrix : ARRAY [1..3, 1..3] OF REAL;
END_VAR
values[0] := 42;
values[5] := values[0] + 1;
END_PROGRAM
Multi-dimensional arrays use comma-separated ranges in the index specification.
Constant Bounds (Vendor Extension)¶
Note
This is a vendor extension not part of the IEC 61131-3 standard. See Enabling Dialects and Features for how to enable it.
Many PLC vendors allow global constants in place of literal values for
array bounds. IronPLC supports this with the --allow-constant-type-params
flag (or --allow-all). The constant must be declared in a
VAR_GLOBAL CONSTANT block.
See Also¶
Structure Types — record with named fields