zuruck zur Themenseite

Articles and background information on the topic

Kempten University of Applied Sciences

Meinrad Happacher | Meinrad Happacher,

First experiences with OPC UA PubSub

Codesys already offers an object-oriented IEC library for implementing PubSub. Kempten University of Applied Sciences has now equipped an Industry 4.0 demonstrator with the communication system. A first field report.

© Kempten University of Applied Sciences

The demonstrator at Kempten University of Applied Sciences already has a past life: It served as a much-used trade fair exhibit and was made available to Kempten University of Applied Sciences in a non-operational state. It was originally used as part of a research project to illustrate the networking of decentralized control architectures.

The system was recommissioned as part of a final thesis. A new control architecture with three decentralized small controllers based on Raspberry Pi and a higher-level soft PLC (industrial PC) for system control including visualization was used for this purpose. In a first step, communication between the controllers took place via TCP/IP. The next step was to implement OPC UA PubSub.

Why PubSub?

In networked systems with a distributed control architecture whose communication does not have to be completely real-time capable, there is always the requirement to be able to exchange data between the participants simply and efficiently. Previously common transmission methods such as TCP/IP require all participants in the network that are to communicate with each other to be individually networked and implemented in a self-defined (proprietary) transmission protocol. This is where OPC UA PubSub comes in: In a standardized protocol that is subdivided into senders (publishers) and receivers (subscribers), the data can be transferred across platforms without having to know the details of the communication or implement it yourself.

Advertisement

The basic principle of data transmission with OPC UA

© Kempten University of Applied Sciences

The basic structure of PubSub is similar to that of the well-known Internet protocol MQTT: A publisher offers data under a specific topic, for which it is generally irrelevant whether it is actually used or received. If a controller is interested in a publisher's topic, it can subscribe to the corresponding topic as a subscriber - from any number of possible subscribers. As a result, all data sent in the network under the 'subscription' is automatically received and can be used.

The User Data Protocol (UDP) is used for the lower network layers (OSI model) of transmission with PubSub. This means that the data transport takes place without a connection and therefore, for example, without feedback from the recipient. This means that PubSub can transmit its transmissions faster than confirmed, connected protocols - such as TCP-IP. At the same time, no acknowledgements of receipt are provided, so that a sender cannot be aware that its messages have been received. Of course, it would also be conceivable to implement an acknowledgement system via PubSub if required.
To better secure data transport, the implementation of PubSub in Codesys uses additional security functions of the message mapping protocol (UADP, for example encryption or data signing).

How to use PubSub in Codesys?

Structure of a publisher's data transmission

© Kempten University of Applied Sciences

Codesys offers an object-oriented IEC library for implementing PubSub, which can be integrated as standard IEC code in any IEC programs on almost any Codesys-based controllers. To do this, the PubSub library must first be downloaded from the Codesys store and then integrated 'as normal' within the library manager. For test purposes, the library can be used in demo mode for 30 minutes - without any content restrictions - before the associated program has to be restarted. For permanent use of PubSub, a license is required, which must be purchased for each controller that is to use PubSub and installed on the respective device via the license manager.

The cost of a license is 50 euros (as of 02.12.2020). The PubSub library from Codesys contains all the necessary components to create publishers or subscribers. The structure for both variants is very similar: The code for data transmission consists of five function blocks that are to be interconnected.
The UADP.Connection block establishes the connection and therefore requires the most complex parameterization. In the UADP.WriterGroup block, several DataSet messages are combined into one network message. This is provided with additional parameters, such as a time stamp, in the UADP.Writer.

The project tree for publisher and subscriber communication

© Kempten University of Applied Sciences

For the subscriber, only the Writer Group and the Writer module are replaced by a Reader Group and a Reader module and the parameterization of the Connection module is adapted.
The assignment of data to a topic is carried out using freely selectable IDs in unsigned integer format instead of clear topic names. To transfer the data to the desired controllers, the IP addresses and ports of all participating devices are entered. A multicast IP can be selected for data transfer to several controllers.

A significant difference to known transmission protocols such as TCP/IP lies in the preparation of the data: All variables must be referenced and assigned in a data set function block. The latter is derived from a DataSet function block offered in the library according to the concepts of object-oriented programming and thus 'inherits' a certain, necessary basic structure. This provides for the references to the variables to be transferred to be stored in an array of the block. The PrepareValues method is available for the corresponding registration of the variables.

To ensure that publishers and subscribers belonging together use the same DataSet module, a version code is generated in the Init method, which must be identical for all devices involved in the communication. It should be updated or regenerated if the DataSet module content changes. If the version codes of a publisher and a subscriber differ, no data transfer can take place between them.

The PubSub implementation

Prof. Dr. rer. nat. Josef Griesbauer is Professor of Automation and Measurement Technology at Kempten University of Applied Sciences.

© Kempten University of Applied Sciences

With OPC UA PubSub, Codesys offers an entry-level system for data transmission systems that is also suitable for beginners with a little training. However, prior knowledge of object-oriented programming is required. If this is not available, this is reflected in the project planning time for the initial project. For advanced programmers with experience in object-oriented programming, it is quite possible to understand the requirements and implement them in a basic project within a few hours. For beginners, on the other hand, this can take several days. The example project provided in the library, which contains a basic structure for publishers and subscribers, is always helpful. The professional, thoroughly object-oriented implementation of this sample project can be challenging and sometimes time-consuming for newcomers in this field.

Florian Kast is a non-scientific assistant (former Master's student) at Kempten University of Applied Sciences.

© Kempten University of Applied Sciences

The naming of the internal variables of the library's function blocks takes some getting used to. In the Connection module, for example, it is not always clear at first glance which IP address must be assigned to which variable. In this case, the assigned comments are helpful.
It is advisable to create and test the communication separately, as the library uses the NBS namespace, which is also used for data transmission via TCP/IP in Codesys. This can lead to overlapping and therefore errors if PubSub and TCP/IP are used at the same time.

If the communication structure is faulty during the actual test of a PubSub project, this can be easily recognized by the PubSub modules used. These have three output variables that indicate the status, the activity and an error status. It should be noted here that an error status in the subscriber does not necessarily have to originate in the subscriber program. For example, another incorrectly parameterized publisher, which itself reports correct activity, can lead to connection problems in a subscriber. However, testing each transmission separately can prevent misinterpretation of a communication problem.

A summary

The ability to easily and quickly transfer data between a publisher and any number of subscribers makes OPC UA PubSub a powerful tool. Especially when it comes to realizing projects that aim to implement the Internet of Things in industry.

The first-time use of object orientation certainly entails difficulties when implementing a Codesys PubSub project. The slightly higher and object-oriented programming effort in the first project can be compensated for in subsequent projects thanks to the good reusability of the code. In conclusion, it should be noted: At the moment, there is no alternative to implementing PubSub in Codesys and: it works!

  • Xing Icon
  • LinkedIn Icon
Advertisement
Back to topic page
Advertisement

You might also be interested in

Advertisement
Advertisement
Advertisement

Codesys

News from the profiler

Whether performed regularly, prophylactically or sporadically as required: If you examine the runtime of your IEC 61131-3 project with a profiler as an additional tool, the effort involved is minimal, but the benefits are considerable. A plea for...

read more...
Advertisement

Codesys

From data analysis to OPC UA PubSub

With the Codesys Automation Server, Codesys added an Industry 4.0 platform to its IEC 61131-3 automation software last year. The latest innovations for this platform and a library for OPC UA-PubSub communication will now be presented at SPS Connect.

read more...
Advertisement
Advertisement
Advertisement

Best of 2022

The top articles of the year

What do marketplaces, PLC solutions in the cloud, new reading worlds, the abandonment of hardware exclusivity and TSN networks have in common? Quite simply, these topics are among the most-read articles of 2022. We take a look back at them...

read more...
Subscribe to our newsletter
Advertisement
Back to home