Quick start

The following chapter provides a quick start to the TwinCAT OPC UA Server. In these instructions, you initialize the TwinCAT OPC UA Server in the delivery state, then create a TwinCAT PLC project and finally enable a PLC variable by setting a pragma via OPC UA. The variable is then available in the address space of the server.
The action steps are described in more detail below in the order in which they are performed:

Initialization of the server

After installation, the server needs to be initialized once according to the so-called TOFU principle (Trust-On-First-Use). Here you configure a user account, which is then required to establish a connection with the server.

As this is a central and security-relevant topic, initialization is explained in detail in a separate documentation chapter. The further steps in this section assume that this process has been carried out once and that you have initialized the server with a user account.

Quick start 1:

Tools for initializing the server

You can use the TwinCAT OPC UA Configurator to initialize the server. This may require the installation of an additional software package.

Creating a TwinCAT PLC project (download of symbol files)

1. Open the TwinCAT XAE Shell (or Visual Studio).
2. In the File menu, select the command New > Project.
3. Add an empty PLC project to the project.
4. Activate the automatic download of the TMC file in the properties of the PLC project, as shown in the following screenshot.
A new TwinCAT project has been created.

Quick start 2:

Adding a product license

Check whether a TF6100 license is available in the TwinCAT XAE license dialog.
1. If not, you can use a 7-day trial license as part of this Quick Start Tutorial.
Quick start 3:

Enabling a variable

2. Add a new variable of data type INT to the MAIN program.
3. Set the pragma on this variable to enable the variables via OPC UA.
{attribute 'OPC.UA.DA' := '1'}
nMyCounter : INT;
4. In the implementation part of the MAIN program, increment this variable by 1 each cycle.
nMyCounter := nMyCounter + 1;
5. Activate the TwinCAT project on your system.

Connecting an OPC UA client

An OPC UA client uses the so-called ServerURL to connect to a server. The ServerURL contains the IP address or the host name of the device on which the server was installed. In this tutorial, we assume that the client and server are running on the same system. The client thus connects to the following ServerURL:

opc.tcp://localhost:4840

As a client, we use the TwinCAT OPC UA Sample Client, which is part of the TF6100 product package.

Quick start 4:

TwinCAT OPC UA Sample Client

It may be necessary to install an additional setup or package to install the TwinCAT OPC UA Sample Client on your system.

After installation, it can be called up via the Windows start menu.

Quick start 5:

The ServerURL to the local host is already entered by default in the TwinCAT OPC UA Sample Client.

6. Click on the Get Endpoints button.
If you are using the Sample Client for the first time, a dialog box appears to accept settings for generating application certificates.
Quick start 6:
7. Confirm the dialog box with the Create button.
All connection endpoints are now read from the server and displayed.
8. Select the endpoint "SignAndEncrypt:Basic256Sha256:Binary" and click on the Connect button.
Quick start 7:
9. Enter the data for the user account that you configured in the first step of this documentation article for initializing the server.
Quick start 8:
10. Click OK.
You are now connected to the server.
The address space of the server is displayed in a tree structure on the left-hand side of the application and you can navigate through the symbolism of the PLC program. In this example, we have enabled a PLC variable for OPC UA. These can be found at the following path:
Root \ Objects \ PLC1 \ MAIN \ nMyCounter

You can add the variable to the "Watchlist" by double-clicking on it. This means that a subscription is created for the variable and the variable value is transferred from the server to the client in the event of a value change.

Quick start 9: