Object DUT

Symbol:

A DUT (data unit type) describes a user-specific data type.

Creating an object DUT

1. Select a folder in the Solution Explorer in the PLC project tree.
2. In the context menu select the command Add > DUT...
The dialog Add DUT opens.
3. Enter a name and select a data type.
4. Click on Open.
The DUT is added to the PLC project tree and opens in the editor.

Dialog Add DUT

Object DUT 3:

Name

Name of the new DUT

Data type

Structure

Creates an object that declares a structure that combines several variables with different data types into one logical unit.

The variables declared within the structure are referred to as components.

Object DUT 4: Advanced: The structure extends an existing structure with additional components. Specify an existing structure in the input field next to it. The components of the existing structure are automatically available in the new one.

(See also: Structure)

Enumeration

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

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

Object DUT 5: Text list support: An enumeration without text list support is created. The DUT object appears in the PLC project tree in the Solution Explorer with the following symbol:
Object DUT 6:

Object DUT 7: Text list support: The text list allows you to locate the names of the enumeration values. The DUT object appears in the PLC project tree in the Solution Explorer with the following symbol:
Object DUT 8:

You can output the localized texts in a visualization, for example. Then, in the text output of a visualization element, the symbolic enumeration values appear in the current language instead of the numeric enumeration values. When a text list-supported enumeration variable is entered in the Text variable property of a visualization element, the supplement <enumeration name> is added.

The buttons at the right edge of the editor can be used to switch between Textual view (Object DUT 9:) and Localization view (text list) (Object DUT 10:).

Sample: The variable MAIN.eVar of type E_myEnum is used. E_myEnum is a text list-supported DUT. The entry in the properties editor then looks as follows: MAIN.eVar <E_myEnum>. If the enumeration name is changed in the PLC project, a prompt appears with the question whether TwinCAT should update the affected visualizations accordingly.

On an existing enumeration object, the text list support can be added or removed at any time afterwards: The commands Add text list support or Remove text list support in the context menu of the object can be used for this purpose.

(See also: Enumerations)

Alias

Creates an object that declares an alias that is used to declare an alternate name for a base type, data type, or function block.

You can enter the Base Type directly or select it via the input assistant or the array wizard.

(See also: Alias)

Union

Creates an object that declares a union that combines multiple components, usually of different data types, into a single logical unit.

All components have the same offset, so they occupy the same storage space. The memory footprint of a union is determined by the memory footprint of its “largest” component.

(See also: UNION)

Declaring a DUT

Syntax:

TYPE <identifier> : <data type declaration with optional initialization>
END_TYPE

The syntax of the data type declaration depends in detail on the selected data type (e.g. structure or enumeration).

Samples:

Declaration of a structure

The following section shows two DUTs, which define the structures ST_Struct1 and ST_Struct2. The structure ST_Struct2 extends the structure ST_Struct1, which means that ST_Struct2.nVar1 can be used to access the variable nVar1.

TYPE ST_Struct1 :
STRUCT
    nVar1 : INT;
    bVar2 : BOOL;
END_STRUCT
END_TYPE
TYPE ST_Struct2 EXTENDS ST_Struct1 :
STRUCT
    nVar3 : DWORD;
    sVar4 : STRING;
END_STRUCT
END_TYPE

Declaration of an enumeration

TYPE E_TrafficSignal :
(
    eRed,
    eYellow,
    eGreen := 10
);
END_TYPE

Declaration of an alias

TYPE T_Message : STRING[50];
END_TYPE

Declaration of a union of components with different data types

TYPE U_Name :
UNION
    fA : LREAL;
    nB : LINT;
    nC : WORD;
END_ UNION
END_TYPE