IMDHMIControls LibraryShop main store

Explainer

Why an OPC UA bridge uses notifications, not monitored-item scans

SCADA and data logging Published 5 min read By IMDHMI controls team

Short answer

Register the stack's data-change notification handler on each monitored item and feed one write worker per destination session. The server already samples each item at its revised sampling interval and the subscription publishes at its revised publishing interval, so a local scan adds latency and cannot distinguish a new value from a stale one.

On this page
  1. What the server already does for you
  2. Why the scanning threads fail
  3. The handler and the write worker
  4. Resolve node IDs per server
  5. Sizing the latency of a bridged analog value
  6. Direction, ownership and commands
  7. Questions asked

An OPC UA bridge between two servers should not scan monitored items in two threads. A monitored item already samples its value inside the server at its revised sampling interval, the subscription publishes on its revised publishing interval, and the client stack hands you each published value through a notification handler. A local scan of "is there a value attached yet" adds latency and cannot tell a new value from one you already forwarded. The correct shape is: register the data-change notification handler on each monitored item, keep the handler short, and push each eligible update into a queue drained by one write worker per destination session. For a SCADA client reading one PLC, why OPC UA subscription updates beat polling PLC input changes covers the single-server case; this article is about the two-server bridge that maps node IDs across different namespace tables.

What the server already does for you #

When you create a monitored item, the server begins evaluating the node at the sampling interval you requested, or the revised sampling interval it accepted if it could not honor yours. Every change that passes the item's filter (deadband or status-based trigger) becomes a notification, queued per item at the queue size set at creation. Part 4 of the OPC UA specification, section 5.13.1.5, defines the queue parameters: when the queue is full and a new notification arrives, the server either discards the oldest entry or the new one, per the item's discard policy. The subscription then publishes queued notifications at its revised publishing interval, and sends a keep-alive when nothing changed for longer than the smallest revised sampling interval of its items.

Read back the revised sampling interval, revised publishing interval and actual queue size after creation, because the server may not grant what you asked for. A typical arrangement: sampling interval 1 s, publishing interval 10 s, queue size 10, so up to 10 different sampled values can arrive in one publish and every intermediate transition survives.

Why the scanning threads fail #

Two threads reading each subscription one by one have three faults:

  • They add their own polling period on top of the revised publishing interval, so end-to-end latency is publish interval plus scan period, and the scan period is pure loss.
  • They cannot distinguish "value present, already forwarded" from "value present, new", because they read the item's current value, not the notification stream. Forwarding the same command twice is the classic symptom.
  • They lose the notification's status code and source timestamp, which are what tell you whether the value is good and when it happened.

The notification handler gives you the value, status and timestamps together, in publish order, once per change. API names differ by C# stack, so use your stack's documented monitored-item notification callback; the OPC Foundation's own client examples show the registration and handler pattern.

The handler and the write worker #

Keep the handler short: identify the mapping, check the value's status, and enqueue the update. Never issue a synchronous network write inside the callback; a slow handler delays every other notification on that subscription. One worker per destination session drains the queue and issues the writes, so two handlers never compete on one session. Inspect every per-node result code in the write response: a completed call can contain individual failures.

Resolve node IDs per server #

A mapping line pairs a source and destination node ID, for example a DA-side item such as ns=3;s=UMUARAMA->OA.OpcOAenterprise.1->Test.Equipment.Motor.CV_E101.EquipmentControlCommand with a PLC-side ns=3;s="MotorControl_CV_E101"."EquipmentCommand". Two rules:

  • The same index on two servers is not the same namespace. Part 6 of the specification reserves index 0 for OPC UA defined nodes; everything above is server-assigned. Resolve each server's namespace table independently and store namespace URIs in the mapping file when your stack resolves them to current indexes.
  • Quotation marks inside a string identifier are part of the identifier, not formatting; do not strip them.

Reject malformed, missing or duplicate mappings before forwarding starts, and read the data type, value rank and write access of each destination with the bridge's authenticated identity before declaring the mapping valid.

Sizing the latency of a bridged analog value #

Inputs, all example values a server might accept:

  • Revised sampling interval: server-side, read back after creation (the value used in the calculation below)
  • Revised publishing interval: read back after creation
  • Queue size: 10 (requested at creation; verify the actual value)
  • Local scan period of the old design: 0.5 s

The rule: worst-case latency to the destination equals the sampling interval (time until the server notices the change) plus the publishing interval (time until the next publish) plus any client-side scan period.

Old design: 1 s + 10 s + 0.5 s = 11.5 s worst case.

Notification design: 1 s + 10 s + about 0 s of handler and queue time = 11 s worst case, and only the changed values travel, in order, with status and timestamps.

Decision: keep the target sampling and publishing intervals for slow process values; the scan removal alone saves 0.5 s per hop and eliminates duplicate forwards. If the mapped signal is a command that must arrive within 2 s, drop the publishing interval to 1 s and the sampling interval to 100 ms, giving 100 ms + 1 s = 1.1 s worst case with margin. Above that point, tune the two intervals; never add a client-side scan.

Direction, ownership and commands #

Do not turn a motor command mapping into unrestricted bidirectional synchronization, or the two servers will echo values forever. Assign one direction per mapping: commands flow from the owner, feedback flows back on a separate mapping with its own nodes. Use latest-value replacement in the queue for continuously varying state; keep ordered, no-loss handling for command transitions, which is where a queue size above 1 matters. Test by changing one controlled source value and confirming the handler fires once, the worker writes once, and the destination reads back the new value with a good status.

Questions asked

What queue size should a bridged item use?

A queue of 1 with discard-old behavior keeps only the latest value and suits continuously varying state. For a command that must not be skipped, set a larger queue, for example 10, so intermediate transitions survive a burst between publishing intervals; verify the server's actual queue size, which may differ from what you requested.

Does the same namespace index mean the same node on both servers?

No. An index of 0 is reserved for OPC UA defined nodes, but index 3 on one server is unrelated to index 3 on the other. Look up each server's own namespace array over its session, and never reuse an index you resolved on the other server; resolve indexes at startup, not from a saved file alone.

Why keep the notification handler short?

The client stack dispatches notifications to handlers in order; a slow handler delays every other notification on that subscription. A synchronous write inside a callback can hold the queue long enough for a keep-alive or overflow condition. Identify the mapping, check status, enqueue, and return; the write worker does the network call.

Can one write service call partially fail?

Yes. A write request carries several nodes and each node gets its own result code. Inspect every result in the response, not just the call's completion, or a failed destination write goes unnoticed until the machine disagrees with the source.

Keep reading

  • 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

  • Explainer

    Reading PLC values from a TwinCAT OPC UA server: read vs subscribe

    The TwinCAT OPC UA server sends nothing to a client that has not asked: your C++ client must send a read for a one-time value, or create a subscription with monitored items for change notifications. A write is a separate request that succeeds only on a node the server exposes as writable, and only with a value of the node's own type.

    SCADA and data logging

  • Explainer

    Reading ctrlX CORE variables without an OPC UA server

    A SCADA server app running on ctrlX OS, SpiderControl is the documented case, reads the variables of its own ctrlX CORE directly through the ctrlX Data Layer, so the local path carries no OPC UA server app. Variables on any other controller still arrive through the server's drivers, one session per source: OPC UA, Modbus or ISO-on-TCP. The server license includes unlimited local access and unlimited HTML5 browser clients, and a 10-day trial is issued automatically.

    SCADA and data logging