Declaration of a directly derived data type in ST

Syntax
TYPE
name_1 : data-type (* optional_begin *) {SIZE := value} (* optional_end *) := initial-value;
name_2 : ARRAY [x..y] OF data-type := [initial-value_1, initial-value_2, .., initial-value_n];
... 
END_TYPE

Meaning

Declaration of one or more directly →derived data types, name_1, name_2 must be →IEC-identifiers.
Use such declarations to define new type-specific initial values. If you require e.g INT variables with the intial value 5 in →assignments, declare a derived data type (see example myINT below) and then use myINT as data type for the variables used in the assignments.

This declaration is possible within the declaration of a user-defined data type (TYPE ... END_TYPE).
The →base type (data-type) of the derived data type must be an elementary or user-defined data type (see "Supported data types (in ST)").

Use the optional →initial value := initial-value to assign a value to the derived data type. This value has priority, i.e. the initial value of the base type is "overwritten". If there is no initial value for the derived data type, the initial value of the base type is applied.
:= starts the initialization. The required input for the initialization depends on the base type. For instance, := initial-value assigns a value in case of an elementary base type. But an array data type or a structured data type as base type requires a slightly different input for the initialization. See the description of the corresponding data type for the required syntax for the initialization.

Current restrictions

The optional attribute SIZE for the bit size is only allowed, if the base type is one of particular elementary data types. The allowed range depends on this data type. Use this attribute to define the bits that will be copied between IO-segment and variable (see the example for data type bit5 in the following).

Enhancement to IEC-standard

The attribute SIZE is an enhancement to the →IEC-standard.

The attribute SIZE is possible for these elementary data types:

The allowed range is:

BOOL

1 bit

SINT, USINT, BYTE

1 to 8 bit

INT, UINT, WORD

1 to 16 bit

DINT, UDINT, DWORD

1 to 32 bit

LINT, ULINT, LWORD

1 to 64 bit

The attribute SIZE is also allowed for a directly derived data type, if the base type is one of the above listed data types (see the example for data type myBit5_v1 in the following). Direct derivations of a data type with attribute SIZE are allowed without and with attribute SIZE (see the examples for data types myBit5_v2 and myBit3 in the following).

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg It is possible to use a directly derived data type in all places where it is possible to use the elementary base type. Example: It is possible to use the data type myINT of the following example as input data type for the ADD block, but it is not possible to use the data type typeScalings.

Moreover, logi.CAD 3 allows you to specify additional data for the declaration . See " Defining description, comment, JSON string or type for variables or data types " for details.

Example
TYPE
myINT : INT := 5; (* data type that is derived from the elementary data type 'INT'. It is initialized with value '5'. *)
Freq : REAL := 50.0; (* data type that is derived from the elementary data type 'REAL'. It is initialized with value '50.0'. *)
typeScalings : ARRAY [1..5] OF myINT := [2(3), 2(), 4];
(* declaring a data type with 5 elements of 'myINT' - the first 2 array elements are initialized with '3', *)
(* the next 2 array elements with initial value '5' of 'myINT', the last array element with '4' *)
RangeConf : RangeS := (scaleMin := -5, scaleMax := 5);
(* data type that is derived from the structured data type 'RangeS'. There are 3 structure elements for 'RangeS'. *)
(* The elements 'scaleMin' and 'scaleMax' are initialized. These values have priority for 'RangeConf'. *)
(* As the element 'signal' is not initialized here, the initial value defined at 'RangeS' is valid for it. *)
END_TYPE

Example: Definition of data types with and without attribute
TYPE
bit5 : INT { SIZE := 5 }; (* 5 bits will be copied between IO-segment and variable. *)
myInt : INT;
myBit5_v1 : myInt { SIZE := 5 }; (* Similar to 'bit5': 5 bits will be copied. *)
myBit5_v2 : bit5; (* Similar to 'bit5': 5 bits will be copied. *)
myBit2 : myInt { SIZE := 2 }; (* 2 bits will be copied between IO-segment and variable. *)
myBit3 : myBit2 { SIZE := 3 }; (* 3 bits will be copied between IO-segment and variable. *)
END_TYPE
 
...
 
VAR_GLOBAL
Status AT %IB1.2.0 : bit5; (* usage of data type 'bit5' *)
...
END_VAR