IMDHMIControls LibraryShop main store

How-to

Starting an OPC UA client connection from PLC code

SCADA and data logging Published 5 min read

Short answer

As of OPC UA Client app version 1.16.0, a configured connection stays Disconnected until something requests a start. PLC code does that job: run cyclically, read the client state, and issue the start request only when the state is Disconnected and no request is pending, gated so it fires once per attempt. Import the PLCOpenXML example into ctrlX PLC Engineering and give the PLC sole ownership of automatic starts.

On this page
  1. Why the connection waits for a command
  2. The pattern the PLC runs every scan
  3. What the gate buys, in numbers
  4. Import the PLCOpenXML example
  5. Where the start request stops
  6. Decisions
  7. Questions asked

As of version 1.16.0, the ctrlX OPC UA Client app no longer starts a configured connection on its own: the connection sits in Disconnected until something requests a start. That something can be an operator, a Node-RED flow, or the PLC, and for a machine that must recover unattended it should be the PLC. Run the supervision cyclically, read the client state, and issue the start only when the state is Disconnected, no attempt is open, and an inhibit is not set. Gate the request so a condition that stays true does not re-fire it every scan. A ready example exists as a PLCOpenXML file for import into ctrlX PLC Engineering.

Why the connection waits for a command #

From version 1.16.0, the ctrlX OPC UA Client app loads its endpoint configuration and then waits: the connection remains in Disconnected until a start is requested. Downloading the app configuration, loading the PLC application, or power-cycling the device does not issue that request, so the client looks dead while its configuration is fine. The start is therefore an owned action, and three candidates exist: an operator working the app, a Node-RED flow that checks the state, or the PLC program. Give it exactly one owner. When the machine has to recover without a person, the PLC is that owner; two supervisors issuing starts against the same connection interleave requests, and you can no longer tell which one caused a state transition. Use a manual start during commissioning, prove one clean session, then hand the start to the PLC for good.

The pattern the PLC runs every scan #

Four rules make the pattern:

  • Read the client state each cycle and act only on Disconnected; a state that is moving or reporting an error should be allowed to finish or report first.
  • Issue the start as an edge, not a level: a request line held true re-submits on every scan.
  • Keep one attempt open at a time, closed by a state change or by a backoff timer.
  • Honor an inhibit so maintenance and operator-requested shutdowns are not instantly reversed.

The names below are illustrative; they stand for the state and command the installed app exposes, and the imported example carries the working bindings:

VAR
    reportedState : STRING := '';   // illustrative: state read from the client app
    disconnected  : BOOL  := FALSE; // illustrative: TRUE when the state is Disconnected
    startCmd      : BOOL  := FALSE; // illustrative: start request written to the app
    busy          : BOOL  := FALSE; // illustrative: TRUE while an attempt is unresolved
    inhibit       : BOOL  := FALSE; // illustrative: maintenance inhibit
    fire          : BOOL  := FALSE; // illustrative: edge memory
    fireWas       : BOOL  := FALSE; // illustrative: edge memory, previous scan
    backoff       : TON;            // illustrative: spacing between attempts
    BACKOFF_TIME  : TIME  := T#5S;  // illustrative example value
END_VAR

disconnected := (reportedState = 'Disconnected');

fire := disconnected AND NOT inhibit AND NOT busy;
IF fire AND NOT fireWas THEN
    startCmd := TRUE;      // one request per rising edge
    busy     := TRUE;
END_IF;
fireWas := fire;

backoff(IN := busy, PT := BACKOFF_TIME);
IF backoff.Q OR NOT disconnected THEN
    startCmd := FALSE;     // attempt closed: state moved or spacing elapsed
    busy     := FALSE;
END_IF;

Keep this supervision out of safety functions; it restores a session, not a safe state. A live session does not even guarantee that every write lands, as fixing robot Profinet output writes over OPC UA shows in another stack.

What the gate buys, in numbers #

Take two example inputs that are yours to set, not documented limits: a cyclic task running every 10 ms and a 5 s backoff. Ungated code of the form IF disconnected THEN start executes 1000 ms / 10 ms = 100 times per second, which is 100 x 60 = 6,000 start requests per minute against a server that is down. The gated pattern issues 60 s / 5 s = 12 requests per minute, a reduction of 6,000 - 12 = 5,988 requests, a factor of 6,000 / 12 = 500. The test that proves it: wire startCmd to a counter, stop the server, and read the counter after one minute: 12, one every 5 s. Restore the server and the counter stops advancing while the state stays out of Disconnected. Twelve attempts per minute recovers a restored server within seconds; six thousand attempts a minute only bury the diagnostic that says why it is down.

Import the PLCOpenXML example #

  1. Record the installed OPC UA Client app version and the configured connection, and read that version's documentation for the start command and its state values.
  2. Import the PLCOpenXML startup-and-recovery example into a working copy of the project in ctrlX PLC Engineering.
  3. Inspect the imported objects, the referenced libraries, and the connection selection; resolve missing dependencies against the installed software before touching the running project.
  4. Identify how the example reads the state, requests the start, and receives the result, and bind those operations to your configured connection.
  5. Add the inhibit input and map state, last result, and a retry counter to diagnostics so the underlying network fault stays visible while recovery runs.
  6. Compile, download, and run the counter test above before machine logic is allowed to consume communication readiness.

Where the start request stops #

Before blaming the client, trace the request from the controller's network interface to the server endpoint: link state on both ends, the address and routing the endpoint resolves to, and whether the server is listening on that port through every firewall on the path. A recovery loop cannot repair a pulled cable, a wrong host, or a closed port; it will just retry. Transport is only the first gate: after it, the client must build its secure channel and session, where the security policy, message security mode, certificates, and user authentication can each stop the request. A reachable host is not an accepting endpoint. From the PLC's chair a rejected certificate looks identical to a start that never happened, so read the diagnostic result instead of starting again; trusting the OPC UA client certificate on the server PLC covers that failure at the trust end.

Decisions #

  • Commissioning: start the connection by hand once, confirm endpoint, security, and data flow, then retire the manual habit.
  • Unattended machine: the PLC owns every automatic start, using the pattern above, with any Node-RED alternative for that connection disabled.
  • Edge-supervised installation: if a Node-RED flow already supervises this connection, keep it and leave the PLC out of starting; if machine sequencing consumes connection state, the PLC owns it instead. One owner either way.
  • Maintenance: the inhibit holds Disconnected deliberately, and the retry counter tells the next technician how long the path has been down.

Questions asked

Which OPC UA Client versions need an explicit start?

Version 1.16.0 is where the change lands: from that version on, a configured connection stays in Disconnected until a start is requested. If you upgrade from an earlier release, a client that used to come up by itself will sit idle afterwards, so add the supervision logic before or together with the upgrade and confirm the behavior on the installed version.

How should I size the retry spacing?

Set the spacing longer than the time one start attempt needs to complete or fail in the installed app, which you read from its documentation and one measured failure. With the 5 s example value, the client sees 12 attempts per minute, which recovers a restored server within seconds without flooding diagnostics. Faster spacing never fixes a rejected certificate or a wrong endpoint; it only multiplies failures.

Does a Connected state mean the process values are usable?

No. Connected proves the session exists, not that subscriptions are active or that the values are fresh. Machine logic should qualify each value with its own quality or staleness check before acting on it, and communication readiness must never stand in for a safety function. Treat a reconnect the same way: revalidate before you resume control.

Can Node-RED run the start instead of the PLC?

Yes, a Node-RED flow that checks the state and starts a Disconnected client handles both startup and runtime recovery, and it is the right owner when no PLC logic depends on connection timing. Where machine sequencing consumes connection state, keep the start in the PLC. The one hard rule is single ownership: never let both run against the same connection.

Keep reading

  • Troubleshooting

    Getting Citect SCADA talking to a Mitsubishi iQ-R PLC

    Fix the transport before anything else: the Citect MELSECQ port on TCP_BOARD must match the iQ-R's SLMP connection module exactly — protocol, port number and IP address. If tags above device 65,535 fail, that is the MELSEC Q protocol's 16-bit address ceiling, and no setting fixes it; move to Mitsubishi's OPC MX UA server with a Citect OPC client driver.

    SCADA and data logging

  • How-to

    Trusting the Citect OPC UA client certificate on a B&R PLC

    OPC UA checks certificates in both directions, so a working UAExpert connection only proves the server side. On the B&R CPU Configuration page, open the OPC UA configuration, create the server certificate if there is none, and add the Citect client's public certificate to the trusted clients; then select the same security policy in Citect and the controller.

    SCADA and data logging

  • How-to

    Connect an S7-1500 to SCADA over OPC UA from TIA Portal

    The S7-1500 has a built-in OPC UA server from firmware V2.0, deactivated by default. Enable it in the CPU device properties in TIA Portal, select the installed server license, copy the endpoint URL, and download. Paste the opc.tcp address into any OPC UA SCADA client, trust the certificates on both sides, then browse the PLC variables and map them to SCADA tags.

    SCADA and data logging