Skip to main content

Object: DUT

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).

Table 28. 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 506. 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 507. 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 508. Example

Declaration of an alias

TYPE A_MESSAGE : STRING[50];
END_TYPE


Example 509. Example

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 29. 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: Enumeration which does not have any text list support

standard icon: Enumeration with additionally stored text list for the enumeration values

The text list allows you to localize the names of the enumeration values.

Example: ETL_TRAFFICSIGNAL

Note: In the case of an existing enumeration type, text list support can be added or removed at any time.

The commands in the context menu of the object are used for this:

Add Text List Support

Remove text list support

Hint: The localized texts can be displayed, for example, in a visualization. In this case, the text output of a visualization element displays the symbolic enumeration values in the current language instead of the numeric enumeration values. When an enumeration with text list support is specified in the Text variable property of a visualization element, it gets the following additional property:

< <enumeration name> >.

Example:

In a visualization, you use the variable PLC_PRG.eTrafficLight of type ETL_TRAFFICSIGNAL.

ETL_TRAFFICSIGNAL is an enumeration with text list support. Then the entry in the properties editor of the visualization element looks like this:

PLC_PRG.eTrafficLight <ETL_TRAFFICSIGNAL>.

For more information, see also: Using Texts

Hint: When you edit the enumeration type in the application, a prompt opens when you close the application and asks whether the affected visualizations should be updated automatically.

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.