Press ESC to close · Ctrl+K to open

Siemens S7-1500 OPC UA Client: Read and Write in TIA Portal

Practical setup of an S7-1500 as an OPC UA client reading and writing variables from another simulated PLC.

Enabling the OPC UA client in a Siemens S7-1500 PLC

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.
Two simulated PLCs in PLCSIM Advanced for OPC UA client and server testing

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.

Simulation DB and FC for the OPC UA server

Then publish the variables in the OPC UA server interface. These are the variables that the client PLC will discover, read and write.

Variables published in the Siemens PLC OPC UA server interface

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.

Assigning the IP address to the OPC UA client PLC in PLCSIM Advanced

Enable the OPC Client from the PLC configuration. This step enables the client functionality inside the CPU.

Enabling OPC Client from the Siemens S7-1500 PLC configuration

As with the server, the matching OPC UA license is required. For a CPU 1515, use the Medium license.

OPC UA Medium license for enabling the OPC UA client in S7-1500

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.

Endpoint configuration in the OPC UA client interface

On the security tab, leave No security for this test. In a real installation, this is where security policies and certificates must be handled.

No security configuration in the OPC UA client

Now connect online to the OPC UA server to select variables. Change the source to Online and click Online Access.

Selecting Online Access to browse OPC UA variables

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.

Searching for the OPC UA server from TIA Portal

If the connection is correct, the address space published by the server PLC appears. Expand the server interface and select the variables to use.

OPC UA address space published by the server PLC

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.

OPC UA read list with server variables

A write list can also be created. In this case we use a test variable named Cmd and check consistency again.

OPC UA write list with Cmd variable

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.

DB generated by TIA Portal for the OPC UA client interface

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.

Compact OPC UA blocks available for Siemens S7-1500 client

Insert OPC_UA_ReadList_C and configure it with the wizard. First select the client interface created earlier.

Configuration wizard for the OPC_UA_ReadList_C block

In Data access, select the read list. TIA Portal then fills the remaining fields needed to access the list.

Selecting the read list in Data access for OPC_UA_ReadList_C

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.

OPC UA write block parameterized with the client interface and Cmd write list

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.

REQ and MaintainSession configuration in the OPC UA client block

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.

OPC UA read test updating values in the client DB

For writing, enter a value in Cmd from the client PLC and check it in the server PLC with another request.

OPC UA write test from client PLC to server PLC

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.



Was this article useful?

Share on LinkedIn