Declaration of a directly derived data type in ST
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. This declaration is possible within the declaration of a user-defined data type (TYPE ... END_TYPE). 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. 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 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). 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.
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
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