Use of user-defined data types

Creation of an EAP variable

There are two common methods in TwinCAT to create user-defined data types. On the one hand a data type of your own can be created via the System node of the project tree on the Data Types tab (see next but one illustration). Such a data type is then available to all modules of the TwinCAT project. It is thus a global data type.
On the other hand, users often create a data type of their own inside a PLC project by defining a DUT (Data Unit Type). Such a data type is initially only locally available to the PLC project. This data type is hidden to other modules such as the I/O configuration (and thus also the EAP device).

In the following illustration you can see that the data type MyType is defined in the PLC. This data type has additionally been used for an output variable of the PLC program. Nevertheless, the user-defined data type does not appear in the list of available data types if a variable of this data type is to be created in the Publisher Box of the EAP device.

Use of user-defined data types 1:

A corresponding note that a data type is used only locally can be found on the basis of the data type list on the Data Types tab via the System node. In the following illustration the data type with the name MyType appears in the list. However, there is a remark under the Type property that the data type concerned is a temporary one (Tmp). This means that the data type concerned is one that is not global.

Use of user-defined data types 2:

If it should be necessary to use a local data type from the PLC in a global context, the corresponding DUT can be converted into a global data type (see following illustration).

Use of user-defined data types 3:
1. Click on the command [Convert to Global Data Type] in the context menu of the DUT.
  • The node of the DUT is automatically removed from the PLC project and a global declaration of the type is created (see following illustration).

The description for one and the same data type must be unique in TwinCAT. For this reason the definition of the data type (the original DUT) is removed from the PLC. Instead of that, the definition of the data type can be found in the XML-based TwinCAT project file following the conversion, and in this way the data type is globally available to the entire TwinCAT project.

A data type occurs as a local and global variant

Following the conversion of a data type into a global data type, the latter appears twice in the list of data types: as a local data type and also as a global data type. The local data type is only removed from the list if it is no longer referenced. It is usually necessary to compile the PLC project again after the conversion. As a result, the reference from the PLC program to the local data types is deleted and only the global type is referenced. Accordingly, the data type should only appear once in the list as in the following illustration.

Use of user-defined data types 4:

Once the user-defined data type has been converted to a global data type, it can be selected from the list of available data types during the creation of a Publisher or Subscriber Variable in the EAP device (see following illustration).

Use of user-defined data types 5:

Changing a global data type

Once a data type has been converted to a global data type, its definition is no longer under the control of the PLC project. The definition of the data type is located in the XML-based TwinCAT project file. This data type must now be changed in the TwinCAT project via the Data Types tab of the System node (see following illustration).

Use of user-defined data types 6:
1. Select the data type that you wish to change from the list.
2. Right-click on it and select the command [Edit] in the context menu.
  • The TMC Editor opens (TMC = TwinCAT Module Configuration).
Use of user-defined data types 7:
1. With the help of the TMC Editors you can change the data type as desired and subsequently save it.
  • The change is accepted in the TwinCAT project by creating a new version of the data type following the saving procedure and marking the original version in the TwinCAT project as Hidden.

A PLC program that uses the data types concerned automatically uses the latest version of the data types. So that the change of the data type is also accepted in the machine code, the PLC project must be recompiled following the change.

If a PLC variable of this data type exists and it is linked with a corresponding Publisher or Subscriber Variable of an EAP device, the latest version of the data type is also used with the Publisher/Subscriber Variable as soon as the PLC project is recompiled.
If no linking of EAP variables to PLC variables exists, the EAP device continues to use the original old version of the data type for its variables. If the new version is to be used instead, the EAP variable concerned must initially be deleted and a new EAP variable of the desired data type added again. The old version of the data type is retained in the TwinCAT project until no further reference to this old version exists.