Skip to main content

Example: Using the OPC UA PubSub SL Library

Product:CODESYS OPC UA PubSub SL

The OPC UA PubSub SL Example.project example shows how to use the OPC UA PubSub SL library to exchange messages via the Pub/Sub protocol as defined by OPC UA Foundation.

The package also contains a second example: PubSubDataSet.project. It shows how to use the OPC UA PubSub SL library in order to provide different data sets and connect them to GVL instances.

Description

In addition to Client/Server communication, communication via the OPC UA Pub/Sub protocol also provides an additional capability to exchange data between the subscribers of a network in compliance with the rules of the OPC UA Foundation.

The structure of the data (DataSet) can be freely defined and is agreed in advance between the sender and the receiver. This eliminates the need to transport additional (meta) data. Data is transferred with the help of the OPC UA PubSub SL library via UDP/IP according to the rules as defined for UADP.

A Publisher publishes its data to an unknown number of Subscribers. As a result, the sender and receiver do not know each other. That is why the number of receivers also does not have any repercussions for the sender. A reply to the sender as to whether or not its messages have reached the receivers cannot be sent via the protocol due to the nature of the protocol. If necessary, such a reply has to be managed in an application-specific way.

The data is transferred in a binary format according to the rules of the OPC UA Foundation. The OPC UA PubSub SL library handles the conversion of IEC data types into the corresponding OPC UA data types and back.

The implementation follows the following profiles:

  • Publisher: PubSub Publisher UADP Periodic Fixed Settings

  • Subscriber: PubSub Subscriber UADP Periodic Fixed Settings

The message length is limited to 1,500 bytes (MTU) (Chunked NetworkMessages are not supported). As long as the rules for a Time Sensitive Network is still not available, hard real-time conditions cannot be complied with. However, the implementation of the OPC UA PubSub SL library attempts to keep the jitter as low as possible.

The library includes the following function blocks:

  • DataSet:

    Defines a DataSet message

  • Configuration:

    Manages shared resources, such as Connection or Group

  • RootDiagnostics:

    Notifies with superordinate diagnostic data

  • Connection:

    Manages the connection to Publisher and Subscriber

  • ConnectionDiagnostics:

    Notifies with diagnostic data about the connection (Connection)

  • ReaderGroup:

    Manages Reader function blocks (creation of a NetworkMessage from DataSet messages)

  • ReaderGroupDiagnostics:

    Notifies with diagnostic data about the ReaderGroup

  • Reader:

    Manages the DataSet function block (Subscriber)

  • ReaderDiagnostics:

    Notifies with diagnostic data about a Reader function block

  • WriterGroup:

    Manages Writer function blocks (creation of a NetworkMessage from DataSet messages)

  • WriterGroupDiagnostics:

    Notifies with diagnostic data about the WriterGroup

  • Writer:

    Manages a DataSet function block (Publisher)

  • WriterDiagnostics:

    Notifies with diagnostic data about a Writer function block

_example_img_opc_ua_blocks.png

Supported functionality

  • Publish/Subscribe of messages according to OPC 10000-14: OPC Unified Architecture Part 14: PubSub Release 1.04

  • Maximum size of a NetworkMessage: 1,500 bytes

  • The current packet size and payload can be configured by means of the configuration of the respective ReaderGroup/WriterGroup and DataSet function blocks.

  • Support with a background task for the respective Connection function block

  • The following profiles are supported:

    • Publisher: PubSub Publisher UADP Periodic Fixed Settings

    • Subscriber: PubSub Subscriber UADP Periodic Fixed Settings

Additional information

The Device_1 application shows how to read a NetworkMessage.

The Device_2 application shows how to send messages by means of the contained function blocks.

  1. Hardware

    1. You need two CODESYS PLCs which are connected over a network which supports UDP Multicast.

    2. In the project, adapt the device configuration to the devices by updating Device_1 and Device_2 to the hardware used.

  2. Customizations in the project

    1. Set the IP addresses in the GlobalIP GVL to the hardware which you have configured. You will find this GVL in the POUs area.

    2. Set the Multicast address to a free address in your network.

      Note: If you are not in a private network, request that your network administrator assign a free address for you.

    3. Set the port. The default port 4840 is the recommended port for OPC UA PubSub.

  3. Log in to both controllers and start the applications.

  4. Start both the sender and the receiver:

    Device_2: PLC_PRG.xEnable := TRUE

    Device_1: Communication_PRG.xEnable := TRUE

    On the receiver side, you should now see how the values of the sine change. You can manually change the other values in the sender and the see the changes in the receiver.

Procedure. Suggestion for extending the example

Add a variable to the DataSet which has already been sent.

  1. Extend SensorDataSet._aIndex by one entry. Select any data type.

  2. In SensorDataSet.Init, adapt the version of DataSet by updating the date entry.

  3. In the PLC_PRG program of the sender, create a variable of the selected data type. Assign the value txSensorDataSet.PrepareValues to the variable.

  4. In rxSensorDataSet.PrepareValues, repeat this step on the receiver side. Create a new variable of the same type beforehand here as well.

  5. Perform a new download.

    The new variable should be transmitted as well.

Example 1. Example of a typical configuration
_example_img_opc_ua_pubsub_config.png


System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.17.0 or higher)

Runtime system

CODESYS Control Win (version 3.5.14.0)

Note

Depending on the capabilities of the respective runtime system, the messages can be sent via Unicast, Multicast, or Broadcast.

Supported platforms/devices

Tip

Use the Device Reader project to find out the supported features of your device. Device Reader is available free of charge in the CODESYS Store International.

Restrictions

  • The maximum length of a network message is 1,500 bytes.

    (Chunked NetworkMessages not supported)

  • The transmission time point is determined via the task configuration.

    The udiPublishingInterval parameter does not have any effect.

Add-on components

CODESYS OPC UA PubSub SL

Note

_example_icon.png DOWNLOAD Project