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.

Subrange Types

A subrange type restricts an integer type to a specified range of values.

IEC 61131-3

Section 2.3.3.1

Support

Partial

Syntax

TYPE
    type_name : base_type ( lower_bound .. upper_bound ) ;
END_TYPE

The base type must be an integer type (SINT, INT, DINT, LINT, USINT, UINT, UDINT, or ULINT).

Example

TYPE
    Percent : INT (0 .. 100);
    Byte_Range : USINT (0 .. 255);
END_TYPE

PROGRAM main
    VAR
        level : Percent := 50;
    END_VAR

    level := level + 10;
END_PROGRAM

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.

With the --allow-constant-type-params flag (or --allow-all), you can use global constants for the subrange bounds:

VAR_GLOBAL CONSTANT
    MIN_PERCENT : INT := 0;
    MAX_PERCENT : INT := 100;
END_VAR

TYPE
    Percent : INT (MIN_PERCENT .. MAX_PERCENT);
END_TYPE

See Also