Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


TwinCAT OPC UA Server PC/CE : Overview

TS6100-0030 | TwinCAT OPC-UA Server CE

Product description

OPC Unified Architecture (UA) is the next generation of the classic OPC-standard and describes a worldwide standardized communication protocol, which enables a vendor- and platform-independent transfer of process data. OPC-UA integrates well established security mechanisms directly into the protocol. Another advantage, compared to classic OPC, is the independence of the old COM/DCOM standard. For detailed information about OPC-UA, please consider visiting the websites of the OPC Foundation.

Components

Since version 1.6.80, the product "TwinCAT OPC-UA" consists of the following components (Windows XP- and Windows CE-based systems):

  • UA-Server: provides UA-Server interface to enable other UA-clients to access TwinCAT symbols (1)
  • UA-Client: provides a UA-client to initiate a UA connection and communication out of TwinCAT-PLC with functionsblocks to other UA-Servers (2)

On Windows XP-based systems, two additional UA-tools are installed:

  • UA-Configurator: a graphical interface to configure the UA-Server
  • UA-SampleClient: a graphical UA-Client which enables to browse the UA-Namespace and test UA-Server installations


TwinCAT OPC UA Server PC/CE : Overview

System requirements

Windows XP-platform

Currently all Beckhoff hardware device running one of the following operating systems are supported: Windows XP, Windows XP Embedded, Windows Embedded Standard 2009, Windows Vista, Windows 7. You can use TwinCAT OPC-UA either on a 32-bit or 64-bit Operating System. Any difference between these two systems will be described in the corresponding installation manual. Additionally, at least TwinCAT2 CP needs to be installed on the OPC-UA Server and needs to be either in Config- or Run-Mode during operation.

Windows CE-platform

All Beckhoff hardware devices with large memory are supported (for example CX1010, CX1020, CX9001, CX9010, CP62xx, C69xx, ...). Devices with only a small memory, like the CX1000 or CX9000, are not supported. For the Operating System, at least Windows CE6 is needed.


TwinCAT OPC UA Server CE : Installation

Installation CE

This part of the documentation describes, how you can install the supplement TwinCAT OPC-UA on a Beckhoff Embedded PC Controller based on Windows CE, for example CX1000, CX1020, CX9000, CX9001, CX9010, CX8090, CP62xx, C69xx, ...

The setup process consists of four steps:

  • Downloading the setup file
  • Installation on a host computer
  • Transfering the setup file to the Windows CE device
  • Executing the setup on the Windows CE device

Downloading the setup file

Like many other TwinCAT Supplement products, OPC-UA for CE is available for download via the Beckhoff FTP-Server. The download represents the most current version. To download the setup file, please perform the following steps:

  • Start a FTP-Client software of your choice, for example FileZilla or Total Commander
  • Open a connection to download.beckhoff.com, without using user credentials (Anonymous)
  • Navigate to the path "Software/TwinCAT/TwinCAT2/Supplement/TwinCAT_OPC_UA_Server_CE/Install" and download the file "TcOpcUaSvrCE.exe"

Installation on a host computer

To get the installation files for Windows CE, you first need to install the downloaded setup file on a host computer, which can be any Windows CE based system. Please perform the following steps:

  • Double-click the downloaded file "TcOpcUaSvrCE.exe"
  • Select an installation language
  • Click on "Next" and accept the license agreement

  • Enter your user information. All fields are mandatory. Please note that OPC-UA for CE is currently not available as a demo version. Therefore you need a valid license key to continue installation.

  • Select "Complete" as the setup type and click on "Next"

  • Click on "Install" to start installation

After installation, the setup files for Windows CE can be found in the directory ".\TwinCAT\CE". This directory contains setup files for the following CE platforms:

  • TwinCAT OPC UA Client CE\I586: OPC-UA Client (PLC library) for x86 based CPUs (like CX10xx, CP62xx, C69xx, ...)
  • TwinCAT OPC UA Client CE\ARMV4I: OPC-UA Client (PLC library) for ARM based CPUs (like CX9001, CX9010, CP6608, ...)
  • TwinCAT OPC UA Server CE\I586: OPC-UA Server for x86 based CPUs (like CX10xx, CP62xx, C69xx, ...)
  • TwinCAT OPC UA Server CE\ARMV4I: OPC-UA Server for ARM based CPUs (like CX9001, CX9010, CP6608, ...)

Transfering the setup file to the Windows CE device

Transfer the corresponding setup file to you CE device. This can be done in the following ways:

  • via a Shared Folder
  • via the integrated FTP-Server
  • via ActiveSync
  • via a CF card

For more information, please consult the "Windows CE" section in our Infosys documentation system.

Executing the setup on the Windows CE device

Now the transfered setup file "TcOpcUaSvrCe.xxxx.CAB" needs to be executed on the CE device. Please perform the following steps:

  • Navigate to the directory where you transfered the setup file to

  • Double-click the CAB file. Should you get a message box stating that this program is not compatible with the current operating system, please re-check if you used the correct CAB-file (ARM, I586) for your IPC/Embedded-PC.
  • If you are sure that the CAB-file corresponds to the Embedded-PC/IPC, please acknowledge this message box with "Yes".

  • Select "\Hard Disk\System" as the destination directory

  • To start installation, click on "Ok"

After installation, the setup file will be automatically deleted. Please note that, if you installed the OPC-UA Server, this component will be available after a restart of your CE device.


TwinCAT OPC UA Server (PC/CE) : Configuration

OPC-UA Server

This part of the documentation describes the basic configuration of the TwinCAT OPC-UA Server. This configuration is independent of the operating system (XP and CE). Additional information about all supported features of the OPC-UA Server can be found here.

Since UA-Server version 1.232.9.28 (and above) the basic setup is performed by the Setup and the first PLC runtime is detected automatically. Please also read our Quick Start article, which gives an introduction for a fast connection setup to the OPC-UA Server.

Here, you can find more information about the following topics:

  • OPC-UA Configurator: A graphical user interface to configure the TwinCAT OPC-UA Server
  • OPC-DA (Data Access): Access to TwinCAT environment via OPC-UA, for example PLC or IO-Tasks
  • OPC-HA (Historical Access): Storing historical data
  • OPC-AC (Alarm & Conditioning): Condition Monitoring of PLC variables
  • OPC-UA Security: Integrated Security features of OPC-UA

Advanced configuration

Depending on your environment, you may want to set additional parameters:

  • Configuration file: Explains the configuration file "ServerConfig.xml" of the TwinCAT OPC-UA Server
  • Configuration of PLC variables: Gives an overview about all configurable options for a PLC variable
  • Additional ADS devices: You may want to connect additional ADS devices to your UA-Server
  • Multiple UA-Servers: You may want to configure multiple UA-Servers on one system
  • UA via NAT: Configuring a UA-Communication via a NAT-device
  • Change array appearance in UA namespace: Describes two different views on arrays in UA namespace


TwinCAT OPC UA Server PC/CE : Overview

Quick Start

After installation, TwinCAT OPC-UA Server is using the default UA discovery port 4840 (TCP). To connect from an OPC-UA-Client, just use the UA Endpoint URL with port 4840:

opc.xxx://<ip or name>:port

opc = Pre-defined

xxx = Transport to OPC-UA Server, for example "tcp"

port = Port number of OPC-UA Server, for example 4840 (default)

Examples:

opc.tcp://CX_0215AF:4840

opc.tcp://172.16.2.80:4840

Since Version 1.6.80, TwinCAT OPC-UA Server is being delivered with a Sample UA-Client which enables you to test your UA-Server installation by simply connecting to it and browsing its namespace. For more information about the "UA Sample Client" please check this documentation.


TwinCAT OPC UA Server PC/CE : Features

Features

Following features are supported and tested against OPC-UA clients on OPC Interoperability workshops:

  • Discovery
  • Session: Support security: No / Basic128Rsa15 / Username password
  • View Services: Support browsing, TranslateBrowsePathToNodeId
  • Attribute Services: Support read attributes for various UA nodes, vendor, specific nodes, support MaxAge
  • Method Service: Support calling ADS methods
  • Information Model: Standard types are exposed
  • Subscription Services: Support of Create / Delete / Publish
  • Data Change: Support Add monitored Items, Enable/Disable sampling/publishing


TwinCAT OPC UA Server (PC/CE) : Configuration

General: Configuration file

Under WinXP-based Operating Systems, all settings regarding the TwinCAT OPC-UA Server can be configured with a special Configurator, which is being automatically deployed since UA-Server version 1.6.80. This graphical tool makes the configuration of the "ServerConfig.xml" easy and comfortable and should always be preferred instead of manually editing this file. This configuration file contains a hierarchical XML-based structure of all necessary parameters of the UA-Server. The following picture shows a sample of this file.

The configuration file can be found under the following path, depending on the operating system:

  • Windows XP / 7: %TwinCATDIR%\OPC\UA
  • Windows CE: HardDisk\System


TwinCAT OPC UA Server (PC/CE) : Configuration

General: PLC Tags

The configuration of PLC variables for an OPC-UA feature takes place directly within a PLC program. This has the advantage that a PLC programmer can perform these configuration tasks directly in his own known program code. This configuration is simple and straight-forward - just by adding a PLC comment behind the corresponding variable, e.g.:

bVariable : BOOL; (*~ (OPC:1:available vor OPC-UA Clients)
                     (OPC_UA_PROP[0005]:1:ReadOnly) *)

The following table gives an overview about all OPC-UA tags and their meaning. For a detailed description of its functionalities, a link to the corresponding feature page is provided.

OPC-UA Feature | PLC tag | Meaning
Data Access (DA) | (OPC : 0 : description) | Explicitely deactivates a variable for OPC-UA. The variable is then not shown in UA namespace.
Data Access (DA) | (OPC : 1 : description) | Activates a variable for OPC-UA. The variable is then shown in UA namespace. This tag always needs to be specified when using other tags
Data Access (DA) | (OPC_PROP[0005] : x : description) | Sets Read/Write access for a variable, depending on the parameter "x"(1=ReadOnly, 2=WriteOnly, 3=ReadWrite (default, if tag is not used))
Historical Access (HA) | (OPC_UA_PROP[5000] : x : description) | Activates a variable for "Historical Access" and defines the type of data storage to be used, depending on the parameter "x" (1=Memory, 2=File, 3=Database)
Historical Access (HA) | (OPC_UA_PROP[5000][1] : x : description) | Defines the sampling rate to be used for data storage, depending on the parameter "x" in [ms]
Historical Access (HA) | (OPC_UA_PROP[5000][2] : x : description) | Defines the maximum amount of values to be stored, depending on the parameter "x"
Alarm & Conditions (AC) | (OPC_UA_PROP[6000] : x : description) | Activates a variable for "Alarm & Conditions" and defines the AlarmID as parameter "x"
Alarm & Conditions (AC) | (OPC_UA_PROP[6000][1] : x : description) | Defines the sampling rate to be used for value monitoring, depending on the parameter "x" in [ms]


TwinCAT OPC UA Server PC/CE : Adding additional ADS devices to UA namespace

Adding additional ADS devices to UA namespace

This article describes how to configure the OPC-namespace of TwinCAT-OPC-UA-Server PC/CE.

By configuring the namespace the OPC-UA server knows which TwinCAT-ADS-devices (like PLC, IO-Task, NC..) should be made available via UA-server.

These configuration have to be done just once.

By default the OPC-UA-Server is configured to connect to one TwinCAT-PLC-runtime.

Add / remove ADS-devices

  • Edit the configuraton file ".\TwinCAT\OPC\UA\ServerConfig.xml" with notepad.
    Each ADS-device (PLC.rune-time, IO-Task...) is configured by it's own section "UaNodeManager"
  • To add an additional ADS-device just copy a new section "<UaNodeManager>" ... "</UaNodeManager>" and change the parameters in between
<UaNodeManager>
    <Name>            Unique name of device. Visible in
namespace when UA-client browse into device
    <AdsPort>         ADS-Port
    <AdsNetId>        ADS-NetID of device (if remote ADS
device take care to add this NetID into ADS-router as "Remote
Device")
    <AdsTimeout>      ADS-timeout in ms
    <AdsTimeSuspend>  Suspendtime in ms (If ADS not available
-like timeout- the UA-server will suspend this ADS-device for a
while
    <AutoCfg>         Options how to get information of
symbols from ADS device
                        5 Details_IO: Upload of symbol
information from ADS device (like IO-Task)
                        7 Details_PLC: All PLC variables
are available via OPC-UA
                        8 Details_PLC: A subset of PLC
variables are available via OPC-UA (recommended)
    <AutoCfgSymFile>  Link to tpy-file (Only available in
case of "AutoCfg 0 7 or 8)
                      Recommended to use standard URL (note
"x" is a placeholder for number of PLC runtime
system.)
                        XP:
<AutoCfgSymFile>C:\TwinCAT\BOOT\CurrentPlc_x.tpy</AutoCfgSymFile>

                        CE: <AutoCfgSymFile>\hard
disk\TwinCAT\BOOT\CurrentPlc_x.tpy</AutoCfgSymFile>
    <Disabled>        If set to "1" the UA-server
will ignore this ADS-device
                        Default is "0"
</UaNodeManager>

Sample:

This sample shows a configuration of three UaNodeManagerNodes. Two PLC runtime systems and one IO-Task are available for OPC-UA:


TwinCAT OPC UA Server (PC/CE) : Configuration

General: Install multiple UA-Servers on one system

It is possible to run multiple TwinCAT OPC-UA Servers on one system This part of the documentation described the necessary steps of the configuration, which is identical for Windows CE and Windows XP. The configuration consists of the following steps:

  • Installation of the first TwinCAT OPC-UA Server
  • Copying the installed UA-Server files
  • Customizing the configuration file of the second UA-Server

For the different operating system platforms, merely the paths differ, which will be documented in the corresponding steps.

Please note: TwinCAT OPC-UA Server comes with an integrated ADS-Server which makes it possible to use OPC-UA directly from within your PLC program. However, if you would like to run multiple UA-Server installations on one system, you need to consider that only the first UA-Server instance will be available for the PLC to communicate with.

Installation of the first TwinCAT OPC-UA Server

To install TwinCAT OPC-UA Server, you can use the available setup file on the Beckhoff FTP-Server. By default, the UA-Server will be installed in the following directory:

  • Windows XP: %TwinCATDIR%\OPC\UA
  • Windows CE: HDD\System

Copying the installed UA-Server files

In a second step you need to copy the installed UA-Server files to a new directory. Create a new directory "UA2" in a folder of your choice, for example:

  • Windows XP: %TWINCATDIR%\OPC\UA2
  • Windows CE: HDD\System\UA2

Now you need to copy the contents of the original folder to the new directory.

Customizing the configuration file of the second UA-Server

The second UA-Server needs to use another TCP-Port, so that it can be reached from a UA-Client. To change the default TCP port of the UA-Server, you need to edit its configuration file "ServerConfig.xml" with a text editor of your choice, for example Notepad. Additional information about this configuration file can be found here. In this file, search for the entry "<Url>opc.tcp://[NodeName]:4840</Url>" beneath the node "<UaEndpoint>" and change its current port number (4840) to a new TCP port, for example 4849:

Additionally, you need to change the node <ServerInstanceUri>[NodeName]/Beckhoff/TcOpcUaServer/1</ServerInstanceUri> and insert a new number, for example:

By executing the following file with the parameter "-console", you can now start the second UA-Server:

  • Windows XP: %TWINCATDIR%\OPC\UA2\TcOpcUaServer.exe -console
  • Windows CE: HDD\System\UA2\TcOpcUaServer.exe -console


TwinCAT OPC-UA Server Port Forwarding

TS6100-0030 | TwinCAT OPC-UA Server CE

General: Configuring a UA-Communication via NAT

To establish an OPC-UA communication via a NAT device, for example an Internet router, this device must forward the configured UA-port to the TwinCAT OPC-UA Server (a so-called Port Forwarding). By default, TwinCAT OPC-UA Server is configured for UA-port 4840, however this configuration can be easily adapted to the customer's needs by editing either the server's configuration file or editing the UA-Configurator. The following picture illustrates a possible Port Forwarding setup:

In this example, an OPC-UA Client establishes a UA connection via the TCP-Port 4840. The NAT device then forwards this connection to the TwinCAT OPC-UA Server. This can be achieved by configuring a Port Forwarding for the TCP-Port 4840 in the NAT device. If your TwinCAT OPC-UA Server is using another port for UA communication, please view the server's configuration file or UA-Configurator to check which port is being used. For more information about how to configure your NAT device for Port Forwarding, please check it's corresponding manual.


TwinCAT OPC UA Server (PC/CE) : Configuration

General: Change array appearance in UA namespace

By default, Arrays are being presented as a single node in the UA namespace. This means for example, if you define an array dyn_BOOL[10] in the PLC (and make it available for OPC-UA), this array shows up in the UA namespace as follows:

The advantage of this approach is a considerably less complex UA namespace AND memory consumption because not every position of the array needs to be mapped as a single node. Modern UA-Clients can still access each single sub item via the so-called "RangeOffset".

However, to also support older UA-Clients which do not integrate this feature, you can configure the UA-Server to map every array position into a separate UA node, which would then show up as follows:

This setting can be activated by selecting the option "ArraySubItemLegacySupport" in the namespace part of the UA-Configurator (e.g. UaServer\UaServerConfig\Namespaces\PLC1).

Alternatively, you can also configure the configuration file manually by adding the following tag to its namespace configuration:

Please note that by activating this setting and depending on the complexity of the PLC project, the UA namespace can increase significantly, which will also increase memory consumption of the UA-Server.

Changing the above setting requires a restart of the UA-Server.


TwinCAT OPC UA Server (PC/CE) : Configuration

Basic Setup

This article describes how to step through the basic configuration of the TwinCAT-OPC-UA-Server for Data Access. OPC-UA DA enables UA-Clients to access your TwinCAT environment, for example variables in your PLC program or IO-Tasks.

Follow further documentation to:

  • Configure "Access to PLC"
  • Configure "Access to IO-Task"


TwinCAT OPC Server PC/CE : Access to PLC

Access to PLC

This article describes how to optimize the UA-Namespace of TwinCAT-OPC-UA-Server. The UA-Namespace describes the structure in which PLC variables are being mapped. To reach a variable in this namespace, it needs to be enabled for OPC-UA first. The following documentation describes two possibilities to UA-enable variables in your PLC program.

General

To configure the UA-Namespace and get access to PLC variables, two general options are available, which can be comfortably set either via the UA-Configurator, or directly in the corresponding node <AutoCfg> in the ServerConfig.xml file.

  • AutoCfg "7": All PLC variables are available via OPC-UA
    Please note:
    - The namespace of OPC-UA server might become heavy due to high number of PLC variables, structures, arrays etc.
    - For smaller PLC projects this might work, instead as default we recommend to load a smaller list of PLC variables which are required via OPC-UA in the client
  • AutoCfg "8": A subset of PLC variables are available via OPC-UA
    - Default setting. We recommend to keep this setting.
    - Just a subset of PLC variables are available via OPC-UA
    - Selection is made in PLC-Control by marking the required PLC variable (instance), a structure, or member-variables of a structure

When selecting AutoCfg "8", the following additional steps are necessary to make a PLC variable reachable via OPC-UA:

  • Step 1: Enable the PLC variable for OPC-UA
  • Step 2: Download the symbol description to the PLC runtime of the target system

When selecting AutoCfg "7", all PLC variables will be reachable via OPC-UA. When using this option, you may jump directly to Step 2.

ArraySubItemLegacySupport: Sub items of an Array will not be shown by default in the UA namespace. Instead, only the whole Array will be displayed as a single element, which results in a better memory consumption of the UA-Server if PLC programs with big arrays are being used. However, UA-Clients will still be able to access single elements via the so-called "RangeOffset". To also enable older UA-Clients, which do not support this feature, to access sub items of an array, the TwinCAT OPC-UA Server implements the option "ArraySubItemLegacySupport". By activating this option, sub items of an array will also be displayed as a single elements in the UA namespace. Attention: When using PLC programs with big arrays, this could result in a higher memory consumption! More information can be found here.

Step 1: Enable the PLC variable for OPC-UA

The OPC-UA Server will automatically connect to PLC runtime and provide PLC variables which are marked for OPC-UA within the PLC program. Mark the PLC-variables with a special comment to enable them being accessed by OPC-UA Server. Two examples:

Example 1:

In this example, the variables bMemFlag1, bMemFlag2, bMemAlarm2 and iReadOnly should be enabled for OPC-UA whereas the variable bMemAlarm1 should not be reachable via OPC-UA.

bMemFlag1  AT%MX10.0  :  BOOL;  (*~ (OPC:1:available for OPC-UA Clients) *)
bMemFlag2  AT%MX10.1  :  BOOL;  (*~ (OPC:1:available for OPC-UA Clients) *)
bMemAlarm1 AT%MX10.2  :  BOOL;
bMemAlarm2 AT%MX10.3  :  BOOL;  (*~ (OPC:1:available for OPC-UA Clients) *)
iReadOnly             :  INT;   (*~ (OPC:1:available for OPC-UA Clients)
                                    (OPC_PROP[0005]:1:available for OPC-UA Clients but ReadOnly) *)

Example 2:
In this example, two instances fbTest and fbTest2 of function block FB_BLOCK1 should be enabled for OPC-UA. If a whole instance is being enabled for UA, all symbols of this instance will automatically be enabled for UA, too.

PROGRAM MAIN
VAR
  fbTest1  : FB_BLOCK1;  (*~ (OPC:1:available for OPC-UA Clients) *)
  fbTest2  : FB_BLOCK1;
END_VAR

FUNCTION_BLOCK FB_BLOCK1
VAR_INPUT
  ni1  : INT;  (*~ (OPC:1:available for OPC-UA Clients) *)
  ni2  : INT;
END_VAR
VAR_OUTPUT
  no1  : INT;  (*~ (OPC:1:available for OPC-UA Clients) *)
  no2  : INT;
END_VAR
VAR
  nx1  : INT;  (*~ (OPC:1:available for OPC-UA Clients) *)
  nx2  : INT;
END_VAR

Here, the instance "fbTest" has been enabled for UA, therefore all its variables are enabled for UA, too (fbTest.ni1, fbTest.ni2, ...). The instance "fbTest2" was not enabled for OPC-UA but three variables have been marked for UA in the the function block "FB_BLOCK1". Therefore these variables are UA-enabled in ALL instances.

Step 2: TwinCAT PLC Control: Download symbol description to target PLC runtime

Since TwinCAT Version 2.10 Build 1240 (or higher) the PLC Control allows to download the symbol file <plc-project-name>.TYP to the target TwinCAT machine. The TPY file contains information about all available PLC variables in the PLC project. The TwinCAT OPC-UA Server requires this TPY-information for creating its UA-Namespace.

To download the current symbol information in a TPY file, please open your PLC project with the PLC-Control editor and navigate to "Project-->Options-->TwinCAT" and check the option "Download Symbol description". With each download of the PLC-code, the TPY file is also downloaded as "C:\TwinCAT\Boot\CurrentPlc_1.tpy".

Please Note:
The TPY-file has to be downloaded just once to be available for the UA-server. Further changes in only the PLC logic does not require to again check the option "Download Symbol description" and download TPY file. Only in case of changes in the PLC variables, which would also affect the UA-Namespace the new download is required. After the TPY file has been created, the UA-Server needs to load this file into its configuration database. To do this, there are two possibilities:

  • You can "tell" the TwinCAT OPC-UA Server from within your PLC code to reload the symbol file. For this, you can use a special PLC Functionblock.
  • You could also reboot your TwinCAT system. Please make sure that, if you stop TwinCAT, the process TcOpcUaServer.exe is also stopped before starting TwinCAT again


TwinCAT OPC Server PC/CE : Configuring namespace of IO-Task

Configuration namespace of IO-Task

This article describes how to configure the OPC-namespace of TwinCAT-OPC-UA-Server for a TwinCAT I/O Task.

General

To provide the IO-variables in a TwinCAT IO-task via OPC-UA two steps have to be configured once:

  • Step 1: Configure TwinCAT IO-task to enable symbol handling
  • Step 2: Configure OPC-UA server to integrate IO-task into UA-namespace

Step 1: Configure TwinCAT IO-task to enable symbol handling

In the TwinCAT System Manager navigate through "System configuration ->Additional tasks -> Task x". Once there, activate "Create symbols".

Similar to the UA PLC configuration, there are two possibilities to make inputs and outputs accessible via OPC-UA:

  • AutoCfg 107: All inputs and outputs are accessible via OPC-UA
  • AutoCfg 108: Only specified inputs and outputs are accessible via OPC-UA. These must be explicitely configured with a special comment, as the screenshot below shows:

Step 2: Add IO-task into UA-server-namespace

In the next step, a UA namespace needs to be added for the IO-Task. This can be done either via the UA-Configurator, or directly by editing the configuration file ServerConfig.xml. The following parameters need to be specified for the namespace:

  • Name: Unique identifier for the namespace, will be visible for a OPC-Client browsing into the namespace
  • AdsPort: ADS-Port as defined in TwinCAT System Manager, in this case 301 for the IO-Task
  • AdsNetId: NetId of ADS-device (127.0.0.1.1.1 provides access to local system)
  • AutoCfg: Either 107 or 108, see above
  • AutoCfgSymFile: Path to the XML configuration file of TwinCAT System Manager. In case of a boot project, this is C:\TwinCAT\Boot\CurrentConfig.xml

Configuration of IO-Task namespace in UA-Configurator:

Configuration of IO-Task namespace in ServerConfig.xml:


TwinCAT OPC Server PC/CE : Historical Access

Historical Access (OPC UA HA)

This article describes how to configure the OPC-namespace of TwinCAT-OPC-UA-Server for historical access of variables in a TwinCAT PLC Task.

NOTE: In order to support SQL database, SQL Compact runtime is to be installed on the Target Device.

General

To provide the historizing of TwinCAT plc variables in a TwinCAT PLC-task via OPC-UA two steps have to be configured once:

  • Step 1: Activation of Historical Access on UA-Server
  • Step 2: Activation of Historical Access in TwinCAT PLC-Program

These steps will be described in more detail below. At the end of this document you will find an example about how to view HA-information with the software UAExpert.

Please note:

  • To use Historical Access, you need version 1.6.62 of the TwinCAT OPC-UA Server
  • To save history values in a database, SQL Compact Runtime 3.5 SP2 is needed on the UA-Server device

Step 1: Activation of Historical Access on UA-Server

There are three different modes regarding the data storage of HA values. These modes only need to be activated one-time on the OPC-UA Server device. These settings can be either made in the ServerConfig.xml file or the UA-Configurator. After one or more data storages have been activated on the UA-Server, the PLC program then selects for each symbol, which data storage should be used for that symbol (Step 2). At the moment there are three supported data storages:

  • Memory: Values are saved in the RAM of the UA-Server device.
  • File: Values are saved in a file.
  • Database: Values are saved in a database. To use this mode, SQL Compact Runtime 3.5 SP2 needs to be installed on the UA-Server.

The following screenshots show the configuration of these modes in the ServerConfig.xml and the UA-Configurator. In the ServerConfig.xml, the <HaModes> tag needs to be placed inside of <OpcServerConfig><UaServerConfig>...</UaServerConfig></OpcServerConfig>.

<HaModes>
  <HaMode Type="RAM" />
  <HaMode Type="File" DataStore="C:\Temp\"/>
  <HaMode Type="SQLServerCompact" DbName="C:\Temp\TcOpcUaServer.sdf"/>
</HaModes>

The necessary parameters of each mode are:

  • Memory: Memory mode stores the data into RAM and is hence a non persistent mode.
  • File: For File mode type, please mention the path of the file where the data is to be stored. Each historizing variable has a unique file. In addition to this there exists a valid backup file for each variable. A valid file after a given buffer length of data is renamed and saved as backup file.
  • Database: For Database mode type, it is necessary to provide the path name where the data is to be stored. Name of the file is also to be mentioned.

Please note: In order to support SQL database, SQL Compact Runtime 3.5 SP2 is to be installed on the Target Device.

Step 2: Activation of Historical Access in TwinCAT PLC-Program

The OPC-UA Server will automatically connect to PLC runtime and provide PLC variables which are marked for OPC-UA within the PLC Control. The same procedure also needs to be performed to enable variables for Historical Access. The following parameters need to be specified in the PLC comment:

  • Mode: Selects which data storage should be used (Memory, File, Database)
  • Sampling-Rate: Specifies with which rate variable values should be saved
  • Buffer-Länge: Specifies how many values should be hold available in data storage (ring buffer)

The following sample code shows how to configure these parameters for each Historical Access mode (Memory, File, Database) and is also available for download in our Sample section:

_HistoryMem  : UINT;  (*~ (OPC:1:available for OPC-UA Clients)
                          (OPC_UA_PROP[5000]:1:Historizing Mode = Memory)
                          (OPC_UA_PROP[5000][1]:5:Sampling Rate = 5ms (Default: 100ms))
                          (OPC_UA_PROP[5000][2]:200000:Maximum history length) *)

_HistoryFile : UINT;  (*~ (OPC:1:available for OPC-UA Clients)
                          (OPC_UA_PROP[5000]:2:Historizing Mode = File)
                          (OPC_UA_PROP[5000][1]:5000:Sampling Rate = 5sec (Default: 100ms))
                          (OPC_UA_PROP[5000][2]:10000:Maximum history length) *)

_HistoryDB   : UINT;  (*~ (OPC:1:available for OPC-UA Clients)
                          (OPC_UA_PROP[5000]:3:Historizing Mode = Database)
                          (OPC_UA_PROP[5000][1]:200:Sampling Rate = 200ms (Default: 100ms))
                          (OPC_UA_PROP[5000][2]:200000:Maximum history length) *)

Example: How to view the Data using UAExpert

PLC Sample Program can be downloaded here. Be sure to add the HaModes and corresponding file path and file name as mentioned above in the ServerConfig.xml file.

  1. Download the HA_Test.pro file and the symbol configuration onto the target device.
  2. Configure this PLC project as a boot project.
  3. Restart the TwinCAT OPC-UA Server in order to reload the symbol configuration. This restart can be performed with the UA-Configurator.

Data is now being saved according to the mode selected and configuration made in ServerConfig.xml. This data can now be visualised using UAExpert. The tests have been performed with UAExpert Version 1.2.0.132

  1. Start the Software UAExpert and connect to the OPC-UA Server

  1. Add document "History Trend View"

  2. Connect to the OPC UA Server Device
  3. Drag and drop the historical variables _HistoryDB, _HistoryFast, _HistorySlowPersist in the Server variable box.

  4. Following Trend will be shown. Please adjust the Start Time and the End Time.


TwinCAT OPC Server PC/CE : Alarms and Conditions

Alarms and Conditions (OPC UA AC)

This article describes how to configure TwinCAT-OPC-UA-Server for process alarm management and condition monitoring.

General

Event Types supported are as follows:

OffNormalAlarm: When the value exceeds the Low and High range, it is reported as OffNormal.

ExclusiveLimitAlarm: Alarm Conditions with multiple limits (HighHighLimit, HighLimit, LowLimit, LowLowLimit). The alarm limits listed may cause an alarm to generate when a value equals the limit or may generate the alarm when the limit is exceeded.

-StateCondition:The corresponding variable (if possible) is checked for TRUE or FALSE status.

To enable alarms and conditions two steps have to be configured:

  • Configure ServerConfig.xml to specify the path of event config file
  • Configure TwinCAT PLC-task to enable alarms and conditions
  • Write excel file ConditionConfig.csv to configure alarms and conditions

NOTE: Mininum Version requirement 1.6.62 TcOpcUAServer

Configure ServerConfig.xml to specify the path of event config file

The name of event config csv file is to be specified in ServerConfig.xml file in following manner

  • <ConditionConfig CfgFile="\ConditionConfig.csv" /> . This node comes under UaServerConfig. Same as node UaEndPoint.
  • If this node is not configured in ServerConfig.xml file, default path is where the UA server is installed and default file name is ConditionConfig.csv.
  • At the moment only semicolon seperated files are supported.
  • If the configured file is not found, error is logged and the server starts without any other errors.

Configure TwinCAT PLC-task to enable alarms and conditions

The OPC-UA Server will automatically connect to PLC runtime and provide PLC variables which are marked for OPC-UA within the PLC Control.

Mark the PLC-variables with a comment to enable them being accessed by OPC-UA Server. Enable alarming by assigning ID and sampling rate as shown below.

Extra comments in PLC-IEC1131 Editor will modify the configuration of OPC Server:

_limitAlarm      : LREAL;(*~ (OPC:1:available for OPC-UA Clients)
                             (OPC_UA_PROP[6000]:42:Specified AlarmID (42))
                             (OPC_UA_PROP[6000][1]:1000:Alarm sampling Rate = 1000ms (Default: 1000ms)) *)

_offNormalAlarm1 : BOOL; (*~ (OPC:1:available for OPC-UA Clients)
                             (OPC_UA_PROP[6000]:600:Specified AlarmID (600))
                             (OPC_UA_PROP[6000][1]:1000:Alarm sampling Rate = 1000ms (Default: 1000ms)) *)

_OffNormalAlarm2 : INT;  (*~ (OPC:1:available for OPC-UA Clients)
                             (OPC_UA_PROP[6000]:601:Specified AlarmID (601))
                             (OPC_UA_PROP[6000][1]:1000:Alarm sampling Rate = 1000ms (Default: 1000ms)) *)

_stateCondition  : BOOL; (*~ (OPC:1:available for OPC-UA Clients)
                             (OPC_UA_PROP[6000]:500:Specified AlarmID (500))
                             (OPC_UA_PROP[6000][1]:1000:Alarm sampling Rate = 1000ms (Default: 1000ms)) *)

Write excel file ConditionConfig.csv to configure alarms and conditions

Conditions are to be configured in excel file. This excel file is supposed to be saved in semicolon seperated values format under the file name ConditionConfig.csv. Parameters to be configured are ConditionType, Template, Name, Message, Severity and Limits. For example please see the following snapshot.

This excel file gives user the flexibility to configure more than one messages for different limits. The Message for normal status comes in the very first Message column in excel file. The following messages correspond to the order of limits in column 5,6,7 and 8.

How to view the Data using UAExpert?

The conditions can now be visualised using UAExpert. The tests have been performed with UAExpert Version 1.2.0.132

  1. Add document "Event View"

  2. Connect to the OPC UA Server device
  3. Drag and drop the Server into Event View.

  4. Following Events and Alarms will be shown.


TwinCAT OPC UA Server (PC/CE) : Configuration

OPC-UA Security: Configuration

Communication betweek UA-Client and UA-Server may optionally be secured by using certificates.

TwinCAT OPC-UA Server automatically creates a corresponding certificate at startup.

If you would like to use certificates in your environment, you need to perform the following steps:

Client-Certificates

If you would like to use certificates for authenticating UA-Clients, your UA-Server needs to trust those certificates. Depending on the operating system on the UA-Server, you need to copy the public key of the UA-Client to the following folder:

  • Windows XP / 7: %TwinCATDIR%\OPC\UA\PKI\CA\certs
  • Windows CE: HardDisk\System\PKI\CA\certs

This folder contains all trusted certificates which may be used to establish an authenticated session. Certificates should be stored with"<SomeName>.der" in this folder, so that the UA-Server can read them. The following steps describe two possible ways to get the Client certificate.

Option 1: Establishing a connection to the UA-Server

This option is probably the easiest way to get the certificate of the UA-Client. Connect your UA-Client using one of the security endpoints of your UA-Server. This connection will, of course, be rejected by the server because it doesn't trust the client's certificate. After rejecting the session request, the UA-Server stores a copy of the client certificate's public key in the following folder:

  • Windows XP / 7: %TwinCATDIR%\OPC\UA\PKI\CA\crl
  • Windows CE: HardDisk\System\PKI\CA\crl

The name of the file represents the certificate's thumbprint. This file may now be copied to the "Certs" folder so that the UA-Server accepts additional session requests.

Option 2: Exporting the Client-certificate from the Certificate Store

The following manual describes how you can export a certificate from the Certificate Store of the UA-Client, in case this client runs under Windows XP or Windows 7.

  • Open the Microsoft Management Console (MMC) on the UA-Client by executing "Start - Run - mmc"

  • Open the menu, navigate to "File - Add/Remove SnapIn" and add the SnapIn "Certificates". Add the Certificate Store where your UA-Client certificate resided, for example "Computer Account".

  • Right-click the certificate of your UA-Client and select "All Tasks - Export"
  • Select "No, do not export the private key" and click on "Next"

  • Select the format "DER encoded binary X.509 (.CER)" and click on "Next"

  • Choose a temporary storage location and use .DER as the data type

Now the created file needs to be copied to the corresponding "Certs" folder on the UA-Server, as mentioned above. A reboot of the UA-Server is not necessary.

Server-Certificates

Depending on the UA-Client, different steps may be necessary so that the UA-Client trusts the certificate of the UA-Server. The following steps are only valid for the TwinCAT OPC-UA Client.

The certificate of the UA-Server is, depending on the operating system, located in the following directory:

  • Windows XP / 7: %TwinCATDIR%\OPC\UA\PKI\CA\certs
  • Windows CE: HardDisk\System\PKI\CA\certs

The name of the certificate is "Beckhoff_OpcUaServer.der". This file needs to be copied to the following folder on the TwinCAT OPC-UA Client:

  • Windows XP / 7: %TwinCATDIR%\OPC\UA Client\PKI\CA\certs
  • Windows CE: HardDisk\System\PKI\CA\certs

Now the TwinCAT OPC-UA Client trusts the UA-Server and a secure connection may be established.


TwinCAT OPC UA Server PC/CE : Features UA Client

Functionalities

The OPC-UA client enables a UA communication out of TwinCAT-PLC via functionsblocks.

Supported functionalities::

  • Open a UA connection
  • Close a UA connection
  • read UA nodes from UA-Servers and transport into PLC
  • write PLC variables/structures into UA-Servers

Link: Detailed documentation with samplecode


TwinCAT OPC Server PC/CE : Samples

OPC-UA: Samples

Sample | Description | Download
1 | OPC-UA Data Access: PLC Sample-Program | DA_Sample
2 | OPC-UA Historical Access: PLC Sample-Program | HA_Test
3 | OPC-UA Buffered Values: PLC Sample-Program and .NET HMI | BufferedValues_Sample


TcOpcUA_Samples_Inosoft

IPC Diagnostics

Sample of OPC UA from Inosoft

Download Inosoft Sample Boiler

Download PLC Demo "Boiler"

Cookbook:

  • Extract the PLC-Demo "Boiler" and load into TwinCAT PLC
  • Install TwinCAT-OPC-UA Server (XP or CE depending of your target platform)
  • Extract the Third-Party Demo from Inosoft
  • Open the file "INOSOFT_UABoilerDemo_PC_800_600.vwn" with Notepad
  • Search line <Channel Name="Ch1" Type="OPCUA" ProgID="Beckhoff OPCUA" ComputerName="opc.tcp://188.100.13.207:4840">
  • Adjust the IP-adress to your system - enter the IP adress of devices which is hosting the TwinCAT-UA-Server
  • Save the file and start app "INOSOFT_UABoilerDemo_PC_800_600.exe"
  • Klick OK to accept demo mode - the demo will run for 1h with each start of app


ADS Return Codes

OPC UA Error Codes

The table below gives an overview about the global OPC-UA Error Codes and their description.

Hex | Description
0xE4DD0000 | general UA Server error
0xE4DA0000 | general ADS error
0xE4DB0000 | general API error
0xE4DD0100 | Server is already connected
0xE4DD0101 | general error while establishing a connection to the UA server
0xE4DD0100 | Server is already connected
0xE4DD0101 | general error while establishing a connection to the UA server
0xE4DD0102 | failed to setup UA security
0xE4DD0103 | item ID already exists
0xE4DD0104 | item does not exist
0xE4DD0105 | invalid or unsupported item type
0xE4DD0106 | var types cannot be converted
0xE4DD0107 | device is suspended
0xE4DD0108 | vartype conversion is not supported for this type
0xE4DD0109 | a namespace with the requested name cannot be found
0xE4DD0110 | target host not found
0xE4DD0111 | timeout due to missing reply from target host
0xE4DD0112 | UA Client session handle is invalid
0xE4DD0113 | invalid node ID