Mapping
The TwinCAT Target Browser is available for linking OPC UA nodes to PLC symbols, which will add the address information of a PLC symbol to an OPC UA node. The nodeset can then deployed to the TwinCAT OPC UA Server.
Objects
Objects cannot be linked to PLC symbols, since they do not have a "value" that could be linked.
Variables and properties
The mapping of variables and properties of a simple data type (Int32, Double, Boolean, ...) can be done by using the TwinCAT Target Browser. Please note that the data type of the PLC variable must "match" the data type of the OPC UA node.

The following table gives an overview of common, simple data types as defined in the OPC UA Base namespace http://opcfoundation.org/UA/. It also shows the corresponding IEC61131 data type.
OPC UA data type |
PLC data type |
---|---|
Boolean |
BOOL |
Sbyte |
SINT |
Byte |
INT |
Int16 |
INT |
UInt16 |
UINT |
Int32 |
DINT |
UInt32 |
UDINT |
Int64 |
LINT |
UInt64 |
ULINT |
Float |
REAL |
Double |
LREAL |
DateTime |
DT |
String |
STRING |
Structures
Structured types can also be linked to a PLC structure via the TwinCAT Target Browser. However, there are a few special features to be considered here. On the one hand, the data structure in the PLC must "fit" the OPC UA data structure and, on the other hand, the data structure in the PLC still requires the OPC UA type information as a PLC attribute.
The following OPC UA structure is given as an example.
<UADataType NodeId="ns=1;i=3015" BrowseName="1:ModelDataType">
<DisplayName>ModelDataType</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5048</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5050</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5049</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:ModelDataType">
<Field DataType="Byte" Name="SwitchingObjectIdentification"/>
<Field DataType="Byte" Name="SwitchingObjectNumber"/>
<Field DataType="Date" Name="CurrentDate"/>
<Field DataType="Int32" ValueRank="1" ArrayDimensions="1" Name="SwitchingTimes"/>
</Definition>
</UADataType>
The structure in the PLC must then have the following structure:
PROGRAM MAIN
VAR
MyModel : ST_ModelDataType;
END_VAR
{attribute 'OPC.UA.DA' := '1'}
{attribute 'OPC.UA.DA.StructuredType' := '1'}
{attribute 'pack_mode' := '1'}
{attribute 'OPC.UA.AdditionalStructuredType.NamespaceName' := 'nameSpaceNameNodeset'}
{attribute 'OPC.UA.AdditionalStructuredType.Id' := 'i=3015'}
TYPE ST_ModelDataType :
STRUCT
SwitchingObjectIdentification : BYTE;
SwitchingObjectNumber : BYTE;
CurrentDate : DT;
SwitchingTimes : ARRAY[0..2] OF DINT;
END_STRUCT
END_TYPE
The additional attributes OPC.UA.AdditionalStructuredType.NamespaceName and OPC.UA.AdditionalStructuredType.id are necessary so that the TwinCAT OPC UA Server can assign the type information. They represent the namespace and the NodeID of the data type of the StructuredType.
The link in the TwinCAT Target Browser can then be made to the structure instance MyTimeModel. Please make sure afterwards that the AdsType "BIGINT" is entered in the TcAdsExtension at the OPC UA Node.
