Object: DUT Permalink

A DUT (Data Unit Type) declares a user-specific data type.

Symbol:

  • cds_icon_add_dut.png DUT

  • _cds_icon_textlist_dut.png Enumeration with text list support

You can add this kind of object below the application or in the POUs view.

When the object is created, the “Add DUT” dialog opens. There you can configure the new data type and choose from the constructs (structure, enumeration, alias, and union).

Syntax for the declaration of user-defined data types

TYPE <identifier> :

<data type declaration>

END_TYPE

DUT construct

A user-defined data type declaration is placed between the brackets TYPE and END_TYPE.

TYPE <identifier> :

STRUCT

    <member declaration>

END_STRUCT

END_TYPE

A structure encloses its members with STRUCT and END_STRUCT. Any number of members can be declared, but at least two.

STRUCT

TYPE <identifier> :

(

    <list of members>

) <base data type> := <initialization> ;

END_TYPE

An enumeration is a comma-separated list of member names in round brackets. All members have the same data type.

An enumeration can also have a text list assigned to it. This is used to localize the values of the enumeration. As a result, the object also has a localization view.

Enumeration

TYPE <identifier> : <data type name> ;

END_TYPE

An alias is an alternative identifier.

Alias

TYPE <identifier> :

UNION

    <member declaration>

END_UNION

END_TYPE

A union encloses its members with UNION and END_UNION. It is a data type with several members which share a the same memory location.

UNION

Example

Declaration of the structure S_POLYGONLINE with partial initialization of members

TYPE S_POLYGONLINE :
STRUCT
    aiStart : ARRAY[1..2] OF INT := [-99, -99];
    aiPoint1 : ARRAY[1..2] OF INT;
    aiPoint2 : ARRAY[1..2] OF INT;
    aiPoint3 : ARRAY[1..2] OF INT;
    aiPoint4 : ARRAY[1..2] OF INT;
    aiEnd : ARRAY[1..2] OF INT := [99, 99];
END_STRUCT
END_TYPE

Declaration of the structure S_PENTAGON as an extension of S_POLYGONLINE

TYPE S_PENTAGON EXTENDS S_POLYGONLINE :
STRUCT
    aiPoint5 : ARRAY[1..2] OF INT;
END_STRUCT
END_TYPE

Example

Declaration of the enumeration E_TRAFFICSIGNAL

{attribute 'qualified_only'}
{attribute 'strict'}
TYPE E_TRAFFICSIGNAL :
(
    eRed,
    eYellow,
    eGreen := 10
);
END_TYPE

Enumeration with text list support in the localization view

cds_enum_textlist_example_trafficsignal.png

The _cds_img_button_textual_view.png “Textual View” and _cds_img_button_tabular_view.png “Localization View” buttons are located on the right edge of the editor. Click the buttons to toggle between the views.

Example

Declaration of an alias

TYPE A_MESSAGE : STRING[50];
END_TYPE

Example

Declaration of a UNION

TYPE U_DATA :
UNION
    lrA : LREAL;
    liA : LINT;
    dwA : DWORD;
END_UNION
END_TYPE