IEC 61131-3 Array Type

Help Contents

Introduction

You can use array types to declare a collection of elements that can be indexed by an integer value. For example:

Type
    FlowRates : Array [0..3] of LREAL;
End_Type

You access array elements using the array operator consisting of square bracket ([) and (]) characters. For example:

Var 
    Values : Array [0..3] of LREAL;
    TotalFlow : LREAL;
End_Var

    TotalFlow := Values[0] + Values[1] + Values[2] + Values[3];

The previous example could also be implemented with a FOR ... END_FOR loop:

Var 
    Values : Array [0..3] of LREAL;
    TotalFlow : LREAL;
    Index : INT;
End_Var

    TotalFlow := 0;
    For Index := 0 To 3 DO
        TotalFlow := TotalFlow + Values[ Index ];
    End_For;

Arrays with more than 1 dimension

Arrays can be declared with more than 1 dimension. For example:

Type
    FlowRates : Array [0..3, 0..1] of LREAL;
End_Type

To access elements of arrays with more than 1 dimension you need multiple indexes:

Var 
    Values : Array [0..3, 0..1] of LREAL;
    TotalFlow : LREAL;
    Index : INT;
End_Var

    TotalFlow := 0;
    For Index := 0 To 3 DO
        TotalFlow := TotalFlow + Values[ Index, 0 ] + Values[ Index, 1 ];
    End_For;

Standards Compliance

Table 12.4 - IEC 61131-3 Second Edition.

Table 11.4 - IEC 61131-3 Third Edition.

Further Information

Derived Data Types

To learn about other derived data types, for example STRUCT.

Elementary Types

To learn about the built-in elementary types for example LREAL, or INT.

Common Elements

To learn about other common language elements.

Character Codes

For a list of all Unicode character codes used in IEC 61131-3 code.

Glossary

For the meaning of terms used in Fernhill SCADA.