OPC UA (Open Platform Communication Unified Architecture) is not just a communication protocol, but an architecture that also includes the concepts of data models and interactions, and is increasingly becoming a new market standard, providing the basis for open and standardized communication. It provides the basis for open and standardized communication. It enables standardized data exchange between different platforms.
And since OPC UA is an integral part of PLCnext Technology, it is supported by OPC UA in connection with third-party systems. It is the OPC UA PubSub functionality that we will introduce here.
OPC UA PubSub Communication
OPC UA PubSub (Publish-Subscribe) is part of the OPC UA Framework and is designed to provide Message with a combination of Publisher and Subscriber to deliver real-time and non-real-time data with high efficiency Communication over a standard IP network. Communication is handled using the UDP (User Datagram Protocol) mechanism over a standard IP network, an approach that is flexible and not tied to a specific system.
In general, PubSub communications are independent of the configuration and operation of the OPC UA server. When delivering data to a network, the Publisher and the recipient of the data may be one or more Subscriber, and yet be OPC UA servers or clients at the same time.
Note that OPC UA PubSub communication requires an IGMP-enabled switch in the controller network. IGMP (Internet Group Management Protocol) is a communication protocol in the TCP/IP protocol family.
OPC UA PubSub communication is independent of OPC UA client-server communication. However, the publishers and subscribers described here may simultaneously be OPC UA servers or clients.
Flow
When initially setting up OPC UA Pub/Sub, set up the procedure as follows.
Note that for PLCNEXT, the Controller can act as both Publisher and Subscriber, but must be defined in a different PLCnext Engineer project.
- Define a Data Set to Publish
- Set up a network connection for Publish/Subscribe of the Data Set
- Configure the Controller as Publisher
- Setup Controller as Subscriber
Data Set
A Data Set is a grouping of ports and variables that can be published to the network; conversely, a Data Set is a collection of ports/variables that can be published.
After a Data Set is defined, it can be selected by a Writer (or Publisher) defined in the project. This makes the DataSet reusable and the items contained in the DataSet can be published to the network.
Which data can be used?
In PLCNEXT Controller, the following Components can be used as a Data set.
- Variables set on the OUT port
- Global IEC variables (Local variables, Program Global variables, and In/Out variables are not included)
- Basic data types and one-dimensional arrays of basic data types
Be carefu-1
The order in which variables are set into the data set is important for any Subscriber reading this data set; the configuration of the Reader requires that the target variables be created in exactly this order and with the correct data type. Otherwise, Mapping of the received value to the target variable will not be correct.
Be carefu-2
Since the Publisher and Subscriber are configured in separate projects, there are no automatic checks; the End-User must receive the necessary information from the Publisher to configure the Subscriber.
Be carefu-3
The OPC attribute of the POU variable table can be added to the Data Set even if the checkbox is not selected in the declaration.
Be carefu-4
Datasets are reusable. Datasets can be selected many times, i.e., published by multiple Writers.
Publisher?
Publisher means that the value of Port/variable is written to the defined network and can be read by the Subscriber configured accordingly.
The network addressed is specified by the network address (Multicast address) defined for the particular connection. So, a Writer is a Connection.
A Writer consists of so-called Writer Groups. Each Connection can have multiple Writer Groups, and a Group can have multiple Writers.
Subscriber?
Subscriber is to read a Published Data Set from a defined Network.
The Network specified by Address is specified by the Network address (Multicast address) defined for the specific connection. So, the Reader is a Connection.
A Reader is composed of so-called Reader Groups. Each Connection can have multiple ReaderGroups, and a Group can have multiple Readers.
The data set to subscribe to a Reader must match the Publish ID, Writer Group ID and Writer ID of the Publish.
Error
The Configuration Compile result will be a binary output file conforming to the OPC UA standard Filename:pcwe.opcua.pubsub.uabinary
Default location:/opt/plcnext/projects/PCWE/Services/OpcUA/PubSubConfig.
Implementation
Firmware
PLCnext Technology controllers with Firmware 22.0 or higher will implement the OPC UA PubSub communication model, which is compliant with Part 14 of the OPC Unified Architecture specification.
Version
This is the PLCNEXT Engineering Version I will be using.It will be 2023.0.
Configuration
This is the current Configuration, and both AXCF3152 and AXCF2152 are also set up as Publisher and Subscriber, and finally verified by Wireshark/UaExpert and PLCNEXT Engineering in three directions.
Enable the Function
Access the AXCF2152 Web server ,Go to System Services and Put Activation Check mark on OPC UA PubSub >Apply and reboot.
AXCF3152 Side
Add Program
Create a project for AXCF3152>open COMPONENTS on the right>Local>Programs.
Since this is for testing purposes, either language is acceptable.
The Code edit screen appears.
Define Publish/Subscribe Variables
Open the Variables Tab.
Publish Variables
Add three Publish variables.
Note that the “OUT Port” should be set in the “Usage” field.
In this way, variable attributes can be set from the Field of Usage to the Drop-List.
Subscribe Variables
Next, let’s also define a set of variables that we want to subscribe to from AXCF2152.
Note that “IN Port” should be set in the Usage field.
Configure the Program Task
Assign the program to the CPU’s Execution Task; click on PLCnext(2).
The Task and Events build screen will appear.
Enter the Task name in Enter task name here in ESM1.
Let’s assume here that it is OB1.
Drop the program created in the previous step into the “Enter program instance name here.
Done!Now pAXCF3152 is running cyclically.
OPC UA PubSubs
Next, configure the PubSub settings for OPC UA: open the OPC UA>OPC UA Pub/Sub tab.
Configuration
Open the Configuration section and the Configuration screen will appear.
Press “Click here to add a new connection”.
Done!A new Connection has been added.
Network Address
The Network Address is the address to which AXCF3152 publishes/subscribes data, and the Format is opc.udp//ipaddress:port. Note that the PLCNEXT project can only have one CPU, so it is necessary to manually adjust the network addess of each project.
Network Interface
The Network interface is the network Port to which the AXCF3152 will Pub/Sub. In this case, X2 is selected.
Publisher ID
Set PublishID to 10.Please set the PublishID so that it does not cover other CPUs.
Published data sets
The next step is to create a Publish data set for the CPU.
Add New Dataset
Press “Click here to add new published data set” to add a new data set.
DataSet1 is added. At the same time, the item “DataSet1: Published data set” is added to the Published data sets.
Data set
Let’s add a variable to Publish in the DataSet of Publish.
Clicking on the Variables field allows you to select variables that are set to be Out Port to the CPU directly from the DropList.
Let’s add three Publish variables.
Done!
Configure Pub/Sub
The next step is to connect the Publish Data Set to the Connections and link those variables to the program variables with Subscribe settings .
Open Connection1:Connections.
The “Connection1” is the one created in the previous “Configuration” Step.
Click here to add a new Writer group” under “Publish” to create a new Writer group.
A Writer Group with Writer group ID=1 has been created. The ID cannot be duplicated.
Publish
Open WriterGroup1.
Edit Group
Add “Writer” here.
Normally, only one Writer would be sufficient, but we will define three Writers and examine them later.Published data set should be the same “DataSet1”.
Subscribe
Next, let’s configure the Scbscribe side: open Scbscribe.
Add Reader Group
Add a new Writer Group at Name field.
OK, that’s it, don’t forget the Checkbox for Enabled.
Add Reader
I’m going to add a Reader to the Reader Grouper just added before.
Click on the Field of Name to define a new Reader.
Done! Note that the “Publish ID” and “Writer Group ID” in the “Subscribe” field must match the Publish side.
Add New Variables
Add variables in the Reader.
Press the ”Click here to add a new variables” to define new variable.
Variables are now added as shown.The name of the Source Variables can be left as it is; instead, what needs to be set is the “Target Variables” next to it.
From the Drop List, you can select variables defined as “In Port” in the project.
Done!Note that the variable data type and number of Publish Groups should be matched in AXCF2152 side.
AXCF2152 Side
Add Program
Create a program in Locals>Programs as in AXCF3152. This time, we will define three separate programs.
Define Publish/Subscribe
Define variables for Publish and Subscribe using the same operation as on the AXCF3152 side. Basically, the three programs (Station1, Station2, and Station3) have the same variables.
Station1
The IN Port variable is one real number, and the Out Port variable is a mixture of Boolean, Int, and Real.
Station2
Same as Station1.
Station3
Same as Station1.
Configure the Program Task
Set the programs for Station1, Station2, and Station3 to Execution Task.
OPC UA PubSubs
The operation is not much different from the previous one.
Configuration
Press ”Click here to add a new connection” to create a new connection.
Network address
Add Connection to Configuration. Note that it must match the Network address of AXCF3152.
Network Interface
Set the Network Port for AXCF2152.
Publish Id
The Publish ID for AXCF2152 should be 1 (Defaut) and should not overlap with other Publisher IDs.
Publish data sets
Create a Publish dataset for AXCF2152.
Add new Data Set
Add a StationSet to the Published data sets section.
Data Set
Next, add data to the published data set “Station1”.
Let’s add the “OUT PORT” variable that we defined earlier in the program. Note that the order in which the variables are added must be the same for the other Subscriber (since the data will be incorrect).
Configure Pub/Sub
The next step is to place Publish/Subscribe data on the Connection.
Publish
Add a new DataWriter Set.
For the Published data set, set the “Station” Set you just added.
Subscribe
The next step is to Subscribe to AXCF3152’s Published data. Add a new Reader Group.
Published Id
You just set the Publish ID of AXCF3152 to “10” in the previous step.So set the Publisher ID of DataSetReader1 to 10.
Reader Data
Add the three real Published variables defined by AXCF3152.
Likewise, you can select a variable that is set to “IN PORT” in the program.
Test with UaExpert
Download the project AXCF3152 and AXCF2152 and first make sure that the connection settings are in place, start UaExpert and connect both the 3152 and 2152 CPUs to the built-in OPC UA server.
Add Documents
Documents>Right click>Add.
Select PubSub Config View for Document Type >Ok.
Now that you are also connected to two OPC UA Servers, and check the Pub/Sub status of both.
Check Config
First, there is opc.udp://239.0.0.01:48451 in the UDP Multicast Folder. This is the “Network address” that you first set in the Connections of PLCNEXT Engineering Software.
Next, when I open DataSetWriter1 of AXCF2152, I can see all the Published data that I set in the PLCNEXT Engineering tool.
DataSetReader1 has also been set.
The Field Name is Station11.r32subData/Station21.r32subData/Station31.r32subData, which is the same as that set with the PLCNEXT Engineering tool.
There is also a DataSetReader on the AXCF3152 side.
Did you remember that we set up only 3 DataWriters on the Published side of AXCF3152? So there are three DataSetWriters.
DataSetWriter1, DataSetWriter2, and DataSetWriter3 contain the same variables.
Test with Wireshark
You can also see the UDP Packets from Wireshark.
Test with PLCENXT
Finally, there was also data on the PLCNEXT Engineering side.
Download
Please download the Sample Project from Github.
https://github.com/soup01Threes/PLCNEXT/blob/main/PLCNEXT%20Controller%20OPCUA%20PubSub%20Example.7z
コメント
Good Morning,
My name is Francesca Cavicchi and I am a student of the University of Bologna in Automation Engineering. I’m currently working on my bachelor degree thesis on data modelling and the available functionality of OPC UA.
I write to you because I was searching information about the pubsub config view of UAExpert and found your blog (it’s really well done by the way and very helpful) I wanted to ask to you if it is possible to use UAExpert as a subscriber and see the value of the variable that are being pubblished (I’m currently struggling to connect the pubsub plug-in to the server of the publisher that I made via Automation Studio).
Hope the rest of the week finds you well.
Sincerely,
Francesca