OPC UA Server

The standard installation of CODESYS includes an OPC UA server. You can use it to access the variable interface of the controller via a client. The OPC UA server communicates with connected OPC UA clients over a separate TCP connection. Therefore, these connections have to be examined again separately with regard to security.

The OPC UA server can now be safeguarded by using encrypted communication to the client and OPC UA user management. See the following sections for these settings.

The CODESYS OPC UA server supports the following features:

Creating a project for OPC UA access

  1. Create a new project with a CODESYS Control Win V3 controller.

  2. Declare some variables of different types in the PLC_PRG program.

  3. Add a Symbol Configuration object below the application.

  4. In the Add Symbol Configuration dialog, select the Support OPC UA Features option.

  5. Open the symbol configuration in the editor.

  6. Click Build.

    ⇒ The variables are shown in a tree structure.

  7. Select the variables that you want to change with an OPC UA client. Specify the access rights.

  8. Download the project to the controller.

Creating a certificate for the CODESYS OPC UA server

In order to encrypt data and exchange it with the client safely, the server needs a certificate that the client must classify as trusted when a connection is established for the first time.

Requirement: The active path to the controller is set.

  1. Install the CODESYS Security Agent add-on.

  2. Click View ‣ Security Screen .

  3. Select the Devices tab.

  4. Select the controller in the left view.

    ⇒ All services of the controller that require a certificate are displayed in the right view.

  5. Select the service CmpOPCUAServer.

  6. Create a new certificate for the device. Click the icon .

    ⇒ The Certificate Settings dialog opens.

  7. Define the certificate parameters and click OK to close the dialog.

    ⇒ The certificate is created on the controller.

  8. Restart the runtime system.

Setting up an encrypted connection with the “UaExpert” client

The OPC UA client “UaExpert” is freely accessible software that you can download from the Internet. Using this client, you can connect to the CODESYS OPC UA server. The following description refers to this program. Other OPC UA clients work in a similar way.

  1. Start the “UaExpert” program.

  2. Click Server ‣ Add .

    ⇒ The Add Server dialog opens.

  3. Expand Local ‣ OPCUAServer@... in the tree view.

  4. Select the connection type Basic256Sha256 - Sign & Encrypt (uatcp-uasc-uabinary) and click OK to close the dialog.

  5. Click Server ‣ Connect .

    ⇒ The Certificate Validation dialog opens with an error message.

  6. Activate the option Accept the server certificate temporarily for this session and click Continue.

  7. In CODESYS Development System, click the symbol.

    ⇒ The view is refreshed.

  8. Select the certificate folder Quarantined Certificates.

    ⇒ The client certificate UaExpert@... is displayed in the right view.

  9. Drag the certificate to the certificate folder Trusted Certificates.

    ⇒ Now the client certificate is classified by the server as trusted.

  10. Click Server ‣ Connect in the UaExpert client.

    ⇒ The Certificate Validation dialog opens with an error message.

  11. Activate the option Accept the server certificate temporarily for this session and click Continue.

    ⇒ The connection is established and objects are displayed in the Address Space view.

User management in OPC UA

The CODESYS OPC UA server supports the CODESYS user management. You set the access rights on the server from the Access Rights tab on the controller. To do this, select the object RuntimeSystemObjects ‣ RemoteConnections ‣ OPCUAServer .

Access rights can be checked at both the service and objects levels. This means that a variable cannot be written by a user, although this user is generally allowed to write to the OPC UA server.

OPC UA service Access Rights
AttributeRead View
AttributeRead Change
CreateMonitoredItem View
ModifyMonitoredItem View
SetMonitoringMode View
DeleteMonitoredItem View
CloseSession View
CreateSubscription View
ModifySubscription View
SetPublishingMode View
DeleteSubscriptions View
Publish View
Republish View
Browse View
BrowseNext View
TranslateBrowsePathsToNodeIds View
RegisterNodes View
UnregisterNodes View

See also

Changing a variable via the OPC UA client

  1. Expand the object Objects ‣ DeviceSet ‣ CODESYS OPC UA ‣ Application ‣ Global Vars ‣ GVL in the “UaExpert” client of the view Address Space.

    ⇒ The variables of the global variable list are visible.

  2. Select the variables and drag them to the Data Access View.

    ⇒ The variables and their current values are shown.

  3. Change the variable values by double-clicking the Value field.

Creating events in the CODESYS project

The CODESYS OPC UA server provides the capability of sending standard OPC UA events.

  1. Create a new project with a CODESYS Control Win V3 controller.

  2. Add an Alarm configuration object below the application.

  3. Add an Alarm class object below the Alarm Configuration. Specify a name, for example Event.

    ⇒ The new alarm group opens in the editor.

  4. Select the acknowledgement method REP.

  5. Add an Alarm group object below the Alarm Configuration. Specify a name, for example ApplicationEvent.

    ⇒ The new alarm group opens in the editor.

  6. Change the following parameters:

    • Observation type: Event
    • Class: Event
    • Message: “Message 1”
  7. Add an Visualization object below the Application.

  8. Add a Symbol configuration object below the application.

  9. In the Program (for example, POU PLC_PRG), add a program call for triggering the event alarm.

    AlarmManager.AlarmGlobals.g_AlarmHandler.RaiseEvent(Alm_AlarmConfiguration_Alarmgroup_IDs.ID_ApplicationEvent, Alm_ApplicationEvent_Alarm_IDs.ID_0);
    
  10. Add the library CmpOPCUAProviderAlarmConfiguration to the Library Manager.

    When the library is added, it connects automatically as a client to the alarm configuration and sends the events to the OPC UA server.

  11. Send the project to the controller and start it.

See also

Monitoring an event via the OPC UA client “UaExpert”

  1. Start the “UaExpert” program.

  2. Click Server ‣ Add .

    ⇒ The Add Server dialog opens.

  3. Expand Local ‣ OPCUAServer@... in the tree view.

  4. Select the connection type None and click OK to close the dialog.

  5. Click Server ‣ Connect .

    ⇒ An object tree is shown in the Address Space view.

  6. Click Documents ‣ Add .

    ⇒ The Add Document dialog opens.

  7. Select the “Document Type” Event View.

    ⇒ The Event View tab opens.

  8. Expand the object Objects ‣ DeviceSet ‣ CODESYS Control Win V3 in the Address Space view.

  9. Select the object CODESYS Control Win V3 in Address Space and drag it to the Event View.

    ⇒ The events are displayed.