Press ESC to close · Ctrl+K to open

CODESYS SoftPLC as an OPC UA Server and Siemens S7-1500 as Client

OPC UA, the advantage of using it for communication between different manufacturers.

Architecture with CODESYS Control Win as OPC UA server and Siemens S7-1500 as client

Goal and environment

The goal of this article is to connect two different manufacturers using one common standard: CODESYS will act as the OPC UA server, and a Siemens S7-1500 PLC will act as the OPC UA client.

The idea is: prepare a Windows SoftPLC, download a basic program with changing variables, publish those variables through OPC UA and read them from the Siemens PLC using OPC UA Client.

Test environment:

  • CODESYS Development System 64 3.5.22.20 as the engineering IDE.
  • CODESYS Control Win V3 / Control Win SL as the Windows SoftPLC runtime.
  • CODESYS server PC: test IP address 192.168.1.133.
  • Siemens client: S7-1500 in TIA Portal, downloaded to PLCSIM Advanced.
  • OPC UA port: 4840, with endpoint opc.tcp://192.168.1.133:4840.
  • UA Expert: OPC UA client used to verify that the CODESYS server is publishing correctly.
OPC UA communication architecture between CODESYS SoftPLC and Siemens S7-1500

The official CODESYS Development System page states that the setup includes the development environment and a demo version of CODESYS Control Win SL. CODESYS also documents that, when the communication add-on is installed, the runtime can expose an OPC UA server so that a client can read the controller variable interface.

Installing CODESYS and Control Win

The first step is to install the IDE from the official CODESYS Development System V3 page.

Inside the installer or package manager, look for CODESYS Control Win. This component is the Windows SoftPLC runtime, which means it is the controller where the test application will be downloaded.

CODESYS installer showing CODESYS Control Win 64

After installation, start the runtime. CODESYS Control Win stays running on Windows and is ready to receive the project download from the IDE.

CODESYS Control Win running as a Windows SoftPLC

One important detail: the SoftPLC uses the network interface of the PC where it is running. In this test the PC IP is 192.168.1.133, so this is the endpoint that UA Expert and the Siemens client will use later.

Basic CODESYS program

We create global variables and change them cyclically.

CODESYS global variables to be published through OPC UA
Structured Text
VAR_GLOBAL
    Bool_Test : BOOL := FALSE;
    Int_Test  : DINT := 0;
    Real_Test : REAL := 0.0;
END_VAR

In the main program, a one-second timer and an edge detector can be used to update the values in a controlled way:

Structured Text
VAR
    T_Pulse : TON;
    R_Pulse : R_TRIG;
END_VAR

T_Pulse(IN := NOT T_Pulse.Q, PT := T#1s);
R_Pulse(CLK := T_Pulse.Q);

IF R_Pulse.Q THEN
    GVL_Test.Bool_Test := NOT GVL_Test.Bool_Test;
    GVL_Test.Int_Test  := GVL_Test.Int_Test + 1;
    GVL_Test.Real_Test := GVL_Test.Real_Test + 0.5;

    IF GVL_Test.Int_Test >= 100 THEN
        GVL_Test.Int_Test  := 0;
        GVL_Test.Real_Test := 0.0;
    END_IF;
END_IF;

Publishing variables through OPC UA

For the OPC UA client to see the variables, having them in the program is not enough. They must be exposed through the symbol configuration. In CODESYS, open the configuration, select the variables to publish and generate the configuration.

In this test, Bool_Test, Int_Test and Real_Test are published. This selection must be downloaded to the runtime together with the application, because the OPC UA server uses that published interface.

CODESYS symbol configuration for exposing variables through OPC UA

If your version uses an explicit OPC UA configuration object in the project tree, also review the OPC UA Server or Communication Manager object. In this test, OPC UA is used without security to simplify the lab and check communication between manufacturers directly.

If we want to work without username and password for testing, we access the runtime security policies.

CODESYS Control Win runtime security policies

We enable anonymous access so UA Expert and the Siemens client can connect in test mode.

Allowing anonymous access to the CODESYS runtime for OPC UA testing

Downloading to the SoftPLC

With the runtime started and the configuration ready, download the application to the SoftPLC. If communication between the IDE and the runtime is correct, CODESYS will detect the local device or the runtime at the configured IP address.

Downloading the CODESYS project to the Control Win SoftPLC

After the download, the program must be running. From that moment on, the OPC UA server can expose the selected variables.

Validation with UA Expert

Before moving to Siemens, validate the server with UA Expert. This avoids mixing two different problems: a CODESYS server problem and a Siemens client problem.

The endpoint used in the test is:

opc.tcp://192.168.1.133:4840

If UA Expert can browse the variables and show live values, the server is ready.

UA Expert reading variables from the CODESYS OPC UA server

Siemens PLC as OPC UA client

The Siemens side follows the same approach explained in Siemens S7-1500 OPC UA Client: read and write in TIA Portal, but with a different server: here the server is not another Siemens PLC, it is the CODESYS SoftPLC.

Siemens documents this functionality in the STEP 7 help for using an S7-1500 CPU as an OPC UA client, and on its general Siemens OPC UA page.

Summary of the steps in TIA Portal:

  1. Enable OPC UA Client functionality in the compatible CPU.
  2. Select the OPC UA license that matches the CPU.
  3. Create a Client interface.
  4. Configure endpoint opc.tcp://192.168.1.133:4840.
  5. Connect online to the CODESYS server and create a Read list.
  6. Compile with Rebuild all so TIA Portal generates the interface DB.
  7. Run the read operation from the user program with compact blocks, for example OPC_UA_ReadList_C.
OPC UA read list in TIA Portal with variables from the CODESYS server

If Siemens also needs to write values back to CODESYS, the concept is the same: create a Write list, allow write permissions on the published variables and call the matching write block. This article focuses on reading because it is the minimum path to validate interoperability.

Final online test

With the client downloaded to the Siemens PLC, go online and inspect the DB generated by the client interface. The values coming from the CODESYS SoftPLC are now available inside the Siemens project.

CODESYS values recovered online in the Siemens OPC UA client DB

The screenshot shows the read result:

  • Bool_Test: received as Boolean and changing between TRUE and FALSE.
  • Int_Test: received as DINT and updated with the CODESYS counter.
  • Real_Test: received as REAL and keeping the decimal value.

This validates the complete path: CODESYS runs the program, CODESYS publishes through OPC UA, Siemens connects as a client and TIA Portal displays the recovered data.

The conclusion is straightforward: OPC UA allows a CODESYS SoftPLC and a Siemens PLC to exchange data without a proprietary driver between them. For a lab we can leave the path open and quick; for a real plant, the same flow must be closed with authentication, certificates and encryption.



Was this article useful?

Share on LinkedIn