Skip to main content

Object: DUT

A DUT (Data Unit Type) declares a user-defined data type which extends beyond the predefined standard types.

. Symbol:

You can add these kinds of objects below the application or in the POUs view. When you create the object, the Add DUT dialog opens. There you can name the new data type and choose from the categories (structure, enumeration, alias, and union).

Categories of user-defined data types

Table 30. Syntax
TYPE <identifier> :
    <data type declaration>
END_TYPE

A DUT declaration is enclosed between TYPE and END_TYPE.

TYPE <identifier> :
STRUCT
    <member deklaration>
END_STRUCT
END_TYPE

Declaration of a structure

In the case of a structure, the (at least) two members are enclosed between STRUCT and END_STRUCT.

TYPE <identifier> :
(
    <list of members>
) <base data type> := <inittialization> ;
END_TYPE

Declaration of an enumeration

In the case of an enumeration, the (at least) two members are enclosed in parentheses. The individual members are separated by commas. All members have the same data type. An enumeration can also be supported by a text list.

For more information, see the following: Enum with Text List Support

The text list is used to localize the values of the enumeration. As a result, the object also has a localization view.

TYPE <identifier> : <data type name> ;
END_TYPE

Declaration of an alias

An alias is an alternative identifier.

TYPE <identifier> :
UNION
    <member declaration>
END_UNION
END_TYPE

Declaration of a union

A union allows the simultaneous storage of multiple different data types in the same memory area. The size of a union corresponds to the size of the largest data type which it contains. Always the value of the last written member is stored in memory at any given time.

In the case of a union, the (at least) two members are enclosed between UNION and END_UNION.



Example 520. Example: STRUCT

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 521. Example: Enumeration

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_trafficsignal_localizationview.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 522. Example: Alias

Declaration of an alias

TYPE A_MESSAGE : STRING[50];
END_TYPE


Example 523. Example: UNION

Declaration of a UNION

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


Dialog: Add DUT

Function: The dialog is used to configure a new DUT object (Data Unit Type).

Call: ProjectAdd ObjectDUT menu; context menu of the application object

Name

Name of the new DUT data type

Example: S_POLYGONLINE

Table 31. Data Type

Structure

Creates an object which declares a structure that combines multiple variables with different data types into a logical unit

The variables declared within the structure are called members.

Example: S_POLYGONLINE

Advanced

standard icon: Extends an existing structure by more members

In the input field, specify an existing structure. The members of the existing structure are automatically available in the new structure.

Example: S_PENTAGON

Enumeration

Creates an object which declares an enumeration that combines multiple integer constants into a logical unit

The constants declared within an enumeration are also called enumeration values.

Example: E_TRAFFICSIGNAL

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

Add Text List Support

_cds_icon_option_deactivated.png: Adds an enumeration

standard icon: Adds an enumeration with text list support. The text list allows you to localize the names of the enumeration values.

Alias

Creates an object which declares an alias with which an alternative name is declared for a base type, data type, or function block

Example: A_MESSAGE

Union

Creates an object which declares a union that combines multiple members with mostly different data types into a logical unit

All members have the same offset so that they are occupy the same memory. The memory requirement of a union is determined by the memory requirement of its "largest" member.

Example: U_DATA

Add

Closes the dialog and creates the new object

The object is displayed with the cds_icon_add_dut.png symbol in the device tree or in the POUs view. When a text list is also stored for the object, the _cds_icon_textlist_dut.png symbol is displayed.