Derived (user) data types

Derived data types are declared using a text construct TYPE … END_TYPE. Names of derived data types, their data types, and their initialisation values, are defined within this construct. Derived data types may be used together with elementary data types in variable declarations. Definition of a derived data type is global, i.e. it may be used in any part of the program. A derived data type inherits the properties of the type it has been derived from.

Declaration of an enumeration type specifies that the value of every data element of this type will only use one value from the values stated in the respective identificator list. An enumeration list defines a sorted set of enumerated values, starting with the first identificator in the list, and ending with the last one.

Example:

TYPE
  Traffic_light:  (Red, Yellow, Green);
  Painting_color: (Red, Yellow, Green, Blue) := Blue;  
END_TYPE

Coincides with the simple enumeration data type (where the values of identificator enumeration are not known to the user); this type has specified the values of the enumerated elements.

If an unique identification for context-specific usage should be allowed, the named values may be qualified by a prefix consisting of their attached data name and the hash character  “#”, similar to the entered literals.

Example:

TYPE
  Traffic_light:  (Red, Yellow, Green);
  Painting_color: (Red, Yellow, Green, Blue) := Blue;
END_TYPE

VAR
  My_Traffic_light: Traffic_light;
END_VAR

IF My_Traffic_light = Traffic_light#Red THEN ...

Declaration of a subinterval specifies that every data element may only be assigned a value between (and inclusive) minimum and maximum limits.

Example:

TYPE
  ANALOG_DATA: INT(-4095 .. 4095):= 0;
END_TYPE

An array is a set of data elements of the same type. Basic and user-defined data types, function block types, and classes may be used as array element types.

Example:

TYPE
  TArray1: ARRAY[0..9] OF INT := [1,2,3,4,5,6,7,8,9,10];
  TArray2: ARRAY[1..2, 1..2] OF USINT := [11,12,21,22];
END_TYPE

Declaration of structure data type (STRUCT) specifies that this data type shall contain a collection of particular elements of the specified types, which may be accessed using the specified names. An element of a structure data type must be represented by two or more identifiers or by an array separated by '.'. The first identifier is a name of the structured element, and following identifiers are sequences of element names for access to a particular data element in the data structure. Basic and user-defined data types, function block types, and classes may be used as structure element types.

Structures and arrays may be combined deliberately.

Example:

TYPE
  ANALOG_SIGNAL_RANGE: (BIPOLAR_10V, UNIPOLAR_10V);
  ANALOG_DATA: INT (-4095 .. 4095);

  ANALOG_CHANNEL_CONFIGURATION:
    STRUCT
      RANGE: ANALOG_SIGNAL_RANGE;
      MIN_SCALE: ANALOG_DATA;
      MAX_SCALE: ANALOG_DATA;
    END_STRUCT
END_TYPE

VAR
  MODULE_CONFIG: ANALOG_CHANNEL_CONFIGURATION;
  MODULE_8_CONF: ARRAY [1..8] OF ANALOG_CHANNEL_CONFIGURATION;
END_VAR

MODULE_CONFIG.MIN_SCALE:= -2047;
MODULE_8_CONF[5].RANGE:= BIPOLAR_10V;
  • © Energocentrum Plus, s.r.o. 2017 - 2021