IMDHMIControls LibraryShop main store

How-to

CODESYS as an OPC UA client to an S7-1200 server

Industrial networks Published 6 min read By IMDHMI controls team

Short answer

Yes: a CODESYS runtime can act as an OPC UA client to an S7-1200 acting as the server, but only with the separately licensed OPC UA Client SL on the CODESYS device, an S7-1200 CPU and firmware that support its OPC UA server with published variables, and a matching endpoint, exchanged application certificates, an authorized user identity and the variable's NodeId. Configuring the S7-1200 server alone provides none of that.

On this page
  1. What the CODESYS side needs before anything connects
  2. What the S7-1200 side must provide
  3. Match the endpoint, the security policy and the certificates
  4. Commissioning sequence
  5. Worked example: the network path from a CODESYS device at 192.168.1.20 to an S7-1200 at 192.168.1.10
  6. When the read or the write is refused
  7. Questions asked

A CODESYS device can read and write an S7-1200 over OPC UA, but the two roles are licensed and configured on opposite sides: the CODESYS runtime needs the separately licensed OPC UA Client SL package acting as the client, and the S7-1200 needs a CPU and firmware that run its OPC UA server, with the variables you want published and their access rights set. The OPC UA server function that CODESYS ships with its runtime licenses is a different role — it exposes the CODESYS PLC's own data, which is why the help file leads you to the server. Work the commissioning sequence below in order; every step has an acceptance result, and the sequence ends with a read and a write of a test variable that cannot disturb the machine.

What the CODESYS side needs before anything connects #

The client role is an add-on, not a default. CODESYS provides it through the OPC UA Client SL package, which installs on the engineering side via the CODESYS Installer and is licensed per device as a software-based license activated on the target the runtime runs on; the single-device license is purchased in the Application-Based Licenses category. The OPC UA server included in a restricted form with application-based runtime licenses covers only the server side and does not give you a client.

A library or an example project visible on the engineering computer proves nothing until the target runtime shows the licensed component as present. Deploy the smallest documented client example to the target and treat it as the acceptance test: it must connect and the runtime must report no missing-component or licensing condition. If that example fails on the target, no amount of server-side configuration on the S7-1200 will fix it.

What the S7-1200 side must provide #

Check the exact CPU, its firmware version, the engineering-software compatibility and any server license in Siemens documentation before you configure anything. The family name is not enough: OPC UA server support is not uniform across S7-1200 CPUs and firmware versions, and the configuration procedure differs accordingly.

Then enable the server, publish the variables the client will use, and set their access rights. Publishing and write permission are separate decisions — a published value the server marks read-only refuses every write, no matter what the client does. Keep one test variable that the logic ignores for the first exchange, with the same access rights you plan to run in production.

Acceptance: server diagnostics show the service available with no configuration or license fault, and a known-good OPC UA client browses and reads the test variable. If your layout is one S7-1200 serving data out of another controller, the article on S7-1200 as an OPC UA gateway for S7-300 data covers the server side of that arrangement.

Match the endpoint, the security policy and the certificates #

The endpoint URL — address, port and security policy the server advertises — comes from the S7-1200's server configuration or diagnostics, not from an assumed port. Standard OPC UA over TCP defaults to port 4840 and many servers keep it, but a server configured elsewhere rejects a client pointed at the default. Choose a security policy both sides support; the client and server must agree on the message security mode as well.

Application certificates establish trust between the two programs, and the user identity you supply decides which operations the session may perform, so a connected session can still fail a certificate check or a write. Exchange both application certificates into each side's trust list through the documented trust management, and check validity dates and device clocks on both devices while you are there. If the failure sits in certificate trust rather than the network, the page on troubleshooting OPC UA certificates with Security None walks through those trust-list checks step by step.

Keep the production security settings during commissioning. Dropping security to force a connection hides the trust or identity fault instead of fixing it.

Commissioning sequence #

  1. Confirm the client package and license on the CODESYS target: install the client package, activate its license on the runtime device, and run the smallest documented client example until the runtime reports no missing component or license fault.
  2. Confirm the S7-1200 CPU, firmware and any server license in Siemens documentation, then enable the server; its diagnostics must show the service available.
  3. Publish one test variable the logic ignores, with the read and, where intended, the write access you plan to use in production.
  4. Verify the network path between the two devices — the worked example below shows the check and the arithmetic.
  5. Read the endpoint URL out of the S7-1200's server configuration or diagnostics; do not construct it from the default port.
  6. Select a security policy both sides support, exchange the application certificates into each trust list, and confirm validity dates and clocks.
  7. Configure a user identity the server authorizes; application trust and user permission are separate checks.
  8. Browse from the CODESYS client to the test variable and record its namespace URI, identifier, data type and access rights.
  9. Read the test variable: expect a good operation status, good value quality, and the same value the PLC's online view shows.
  10. Write a compatible test value and read it back; expect the readback to match unless the logic deliberately changes that variable.

Point the first write only at the test variable; never let a commissioning write land on a value that drives an output.

Worked example: the network path from a CODESYS device at 192.168.1.20 to an S7-1200 at 192.168.1.10 #

Inputs, taken as example values from a typical single-subnet cabinet build — substitute your project's real addresses: the CODESYS device at 192.168.1.20, the S7-1200 at 192.168.1.10, and a subnet mask of 255.255.255.0 on both.

Rule: two hosts on Ethernet reach each other directly when their addresses masked with the subnet mask give the same network address; when the masked addresses differ, the client needs a default gateway or a static route to reach the server's network.

Arithmetic:

  • 192.168.1.20 AND 255.255.255.0 = 192.168.1.0
  • 192.168.1.10 AND 255.255.255.0 = 192.168.1.0
  • 192.168.1.0 equals 192.168.1.0, so the masked addresses match.

Result and decision: the two devices share a subnet, so no gateway entry is needed and you can point the client straight at the endpoint the server reports — opc.tcp://192.168.1.10 with the port the server's configuration names, port 4840 when it keeps the standard default. If your masked addresses differ — for example a CODESYS device at 192.168.2.20 against the S7-1200 at 192.168.1.10, which mask to 192.168.2.0 and 192.168.1.0 — set the CODESYS device's default gateway to the router that sits on both networks before any OPC UA step can pass.

When the read or the write is refused #

  • Session opens but the browse shows no variable: the server has not published it, or the user identity lacks browse permission. Fix it on the server.
  • The variable appears but the read fails: resolve the NodeId by browsing instead of typing a remembered identifier, and recheck the namespace index against its URI after any server configuration change — a stored numeric index is not permanent across server edits.
  • The read works and the write fails: check the server's write permission for that identity, the data type of the submitted value, and whether PLC logic overwrites the variable every scan; agree ownership of the variable with whoever owns the logic.
  • Every operation returns a certificate or session fault: go back to the trust lists, validity dates, device clocks and the security policy agreement before touching anything else.

Run the sequence in order and the failure list stays short: a licensed client on the target, an enabled and licensed server on a CPU and firmware that support it, a matching endpoint with exchanged certificates and an authorized user, and a browsed NodeId — that combination reads and writes the S7-1200 from CODESYS.

Questions asked

Does the OPC UA server that ships with CODESYS also give me a client?

No. The OPC UA server function is included in a restricted form with the application-based CODESYS runtime licenses and only exposes that PLC's own data. Acting as a client needs the separately licensed OPC UA Client SL package, activated as a software-based license on the target device the runtime runs on. Check the target's license management before you plan the exchange.

Which network port does the client open on the S7-1200?

OPC UA over TCP uses port 4840 as the standard default and many servers keep it. An S7-1200 can be configured on a different port, so read the full endpoint address out of the server's own configuration or diagnostics instead of assuming the default. A client pointed at the wrong port gets no session.

Why can I read a variable but not write it?

Publishing a variable in the server's address space and granting write access are separate steps. A successful read proves only exposure and read permission. A rejected write points at the server's write permission for your user identity, the data type of the submitted value, or PLC logic that overwrites the variable every scan. Set write access on the server and agree ownership with the logic owner.

Keep reading

  • Explainer

    S7-1500 OPC UA server over a CP 1543-1: when it works

    The S7-1500 OPC UA server is reachable only through the CPU's integrated PROFINET interfaces. One documented exception exists: a CP 1543-1 at firmware V2.2 or later, a CPU at firmware V2.8 or later (V3.1 for R/H CPUs), projected in TIA Portal V16 or later, carries the server over IPv4 forwarding and the CPU's virtual communication interface. Older combinations, including any CP1542SP-1, leave only the CPU's own address in the server list.

    Industrial networks

  • How-to

    How to build a virtual PLC test bench for protocol practice

    One laptop runs the whole bench: a Modbus TCP server simulator, a master test client, a Node-RED OPC UA server and a SCADA trial connect over loopback, so you can practice addressing, sessions, scaling, alarms and fault diagnosis without a PLC. Work through three bounded projects and finish with seven pass criteria you can defend.

    Industrial networks

  • Explainer

    Why OPC UA subscription updates beat polling PLC input changes

    An OPC UA subscription replaces repeated reads with server-side monitoring: the PLC's OPC UA server samples the exported variable at the sampling interval and delivers queued data-change notifications at the publishing interval. Set the sampling interval below the shortest input change you must catch, keep the queue deep enough for one publishing cycle, and confirm the change reaches the exported variable — no subscription can report a transition the PLC never saw.

    Industrial networks