Objective and setup
In this article we configure a Siemens S7-1500 PLC as an OPC UA client. The client reads variables from another S7-1500 acting as an OPC UA server and also writes one test variable.
The test is built with TIA Portal and PLCSIM Advanced. To keep the example direct, the communication is left as No security. If certificates are required, review the article about OPC UA security with Siemens S7-1500 and UA Expert first.
Setup used:
- OPC UA server PLC: 192.168.1.191.
- OPC UA client PLC: 192.168.1.192.
- PLC: CPU 1515-2 PN.
- Simulation: PLCSIM Advanced.
OPC UA server PLC
The OPC UA server must be running before configuring the client. Here we start from the same approach explained in Siemens S7-1500 OPC UA Server: TIA Portal V20 and PLCSIM: a DB with simulated variables, an FC that changes values and an OPC UA interface publishing those variables.
To generate quick test variables, the DB and FC can be prepared from an external source. Siemens documents this workflow in its guide to importing external source files into TIA Portal. This also lets us use AI tools such as Codex to generate test blocks and save time when we only need changing values to validate communication.
Then publish the variables in the OPC UA server interface. These are the variables that the client PLC will discover, read and write.
OPC UA client PLC
Create another CPU 1515-2 PN to use as the client. In PLCSIM Advanced assign the prepared IP address for this client PLC, in this example 192.168.1.192.
Enable the OPC Client from the PLC configuration. This step enables the client functionality inside the CPU.
As with the server, the matching OPC UA license is required. For a CPU 1515, use the Medium license.
Interface and variables
Create an OPC UA client interface. Enter the server PLC IP address, 192.168.1.191. The default OPC UA port is kept.
On the security tab, leave No security for this test. In a real installation, this is where security policies and certificates must be handled.
Now connect online to the OPC UA server to select variables. Change the source to Online and click Online Access.
In the connection window, enter the OPC UA server IP address and search for the server. When it appears, select the unsecured connection for this example.
If the connection is correct, the address space published by the server PLC appears. Expand the server interface and select the variables to use.
To read variables, create a read list. If there is a complete DB, it can be added as a group and then checked for consistency.
A write list can also be created. In this case we use a test variable named Cmd and check consistency again.
After running Rebuild all, TIA Portal generates the interface DB with the variables from the lists. A full compile is important so those DBs are generated correctly.
Compact blocks
With the interface ready, the OPC UA calls must be executed from the program. Siemens provides several blocks. For this example we use the compact blocks, which simplify connection handling and reading.
Insert OPC_UA_ReadList_C and configure it with the wizard. First select the client interface created earlier.
In Data access, select the read list. TIA Portal then fills the remaining fields needed to access the list.
To write the Cmd value, instantiate the write block using the same steps as the read block: select the OPC UA client interface and parameterize Data access with the write list configured earlier.
Two signals remain important:
- REQ: read request. Each positive edge updates the data.
- MaintainSession: OPC UA session maintenance.
For a test, a marker or clock signal is enough. In a real application, the refresh rate must be chosen according to load and process needs.
Final test
Test the read operation online. With a positive edge on REQ_OPC_UA, the server values are updated in the client interface DB.
For writing, enter a value in Cmd from the client PLC and check it in the server PLC with another request.
The key point is consistency between the variables published by the server and the lists configured in the client. If the server DB changes, compile properly, review the lists and regenerate the interface DBs before testing again.