OPC UA Server

The standard installation of CODESYS includes an OPC UA server. Then you can access the variable interface of the controller via a client. At the same time, communication can be protected by means of encryption.

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. Activate the option Support OPC UA Features in the dialog Add symbol configuration.

  5. Open the symbol configuration in the editor.

  6. Click Build.

    ⇒ The variables are displayed in a tree structure.

  7. Activate 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 the same 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.

Changing variables 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 os 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 acknowledgment 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:

    • Monitoring 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 of events with 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 documents 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.