Skip to Content
On this page

OPC UA client

The OPC UA client connects to an OPC UA server, browses nodes, reads values, and optionally creates subscriptions for data changes.

Compatible devices and models

Device series / model examplesConnection requirements
PLCs, devices, SCADA systems or gateways exposing OPC UAConfigure endpoint, security policy, certificates or user authentication. Use the server namespace and NodeId and enable the required read/write or subscription permissions.

Publish and identify the OPC UA node

First make the UA server read its underlying device. In KEPServerEX, configure the PLC Channel, Device and Tag, then check connectivity, type and quality in OPC Quick Client. This example uses the published simulator Ramp1: DA Item 模拟器示例.函数.Ramp1, UA NodeId ns=2;s=模拟器示例.函数.Ramp1. A PLC register such as D100 or DB1.DBW0 is not a replacement for that server NodeId.

  1. In KEPServerEX project properties, check OPC UA → Server Interface → Enable and choose the project’s anonymous-access policy. The following KEPServerEX6.6 vendor-help window shows the interface. Max connections limits client sessions; Allow anonymous login controls anonymous identity, not variable write permissions.

KEPServerEX vendor-help window showing the UA interface and session settings

  1. In OPC UA Configuration Manager, enable a Server Endpoint on the intended interface. Record its complete URL, security policy and message-security mode; 49320 is a common port. For remote clients, use a reachable interface address instead of 127.0.0.1. A PLC’s built-in UA service requires its own engineering settings and published variables.
  2. Configure users and certificate trust for that endpoint. For a secure connection, trust the gateway application certificate at the server and the server certificate at the gateway. Application trust and user node permissions are separate.

Read the same node in UaExpert

  1. Add a server in UaExpert. Under Custom Discovery, double-click Add Server and enter the actual endpoint. The local example uses opc.tcp://127.0.0.1:49320.

Entering the complete discovery URL in UaExpert

  1. Expand the discovery result and select the matching endpoint and identity. This example uses the existing None - None endpoint and Anonymous, then connects. A server requiring signing, encryption or credentials needs the corresponding endpoint and authorized identity.

Selecting the discovered KEPServerEX endpoint and Anonymous identity

  1. Browse Objects → 模拟器示例 → 函数 → Ramp1 in Address Space. In Attributes, copy the complete NodeId and check DataType, ValueRank, AccessLevel and UserAccessLevel. The example has namespace 2, String identifier kind and identifier 模拟器示例.函数.Ramp1.

Complete UaExpert NodeId, namespace and String identifier

  1. Right-click the Data Access View and select Add custom node…. Choose the server, namespace 2, String and the identifier. The resulting monitored row shows Ramp1, Int32, value 99, Good and source/server timestamps.

Adding a monitored node by namespace and String identifier

UaExpert monitored Ramp1 showing Int32, value99 and Good

Add the corresponding gateway variable

  1. Under Development Configuration → Collection Configuration → No channel, add an OPC UA client device. This example uses Collect_OPC_UA, interval 1000, enabled. Reading ordinary variables does not require device method calls.

Selecting and enabling the OPC UA client device

  1. Under Plugin properties, enter the same Endpoint. For this None/None anonymous endpoint, leave credentials empty and keep Secure connection and Accept untrusted certificates off; enable data subscriptions. Match other endpoints to their actual security, certificates and users, then save.

UA endpoint, identity, security and data-subscription settings

  1. Under Protocol Debug → Node browser, find Ramp1 and refresh/read it. Check the complete NodeId, value, Good status and timestamp. This node declares Int32, ValueRank -1 (scalar), and AccessLevel/UserAccessLevel 1 (readable).

Reading the complete UA NodeId with value95 and Good status

  1. Add an enabled Ramp1 variable with address ns=2;s=模拟器示例.函数.Ramp1, Int32, Read Only and array length 1.

UA variable device, complete NodeId, Int32 and scalar length

In the address field editor, enter namespace 2, String and identifier 模拟器示例.函数.Ramp1, then confirm and fill back. Check the resulting ns=2;s= prefix; entering the complete NodeId again as the identifier would duplicate it.

UA namespace, identifier kind and identifier in the address editor

  1. Save and inspect the live value, advancing collection time and empty error field. The row shows 91, Int32. Ramp1 changes automatically; compare matching times or the trend in UaExpert and the gateway.

UA live variable showing device, value91 and Int32

Address fieldRule
Namespace indexDecimal ns= index from this server’s current NamespaceArray. Recheck after rebuilding its configuration.
Identifier kindNumeric is i=, String s=, Guid g=, Opaque b=. They identify different nodes.
IdentifierPreserve String case and punctuation, including semicolons; use Base64 for Opaque. Verify the complete NodeId after applying the editor.
Arrays/objectsCheck ValueRank and the returned value first. A variable array length does not create server element nodes or PLC offsets.

For an ordinary numeric point, start with subscriptions enabled, 1000 ms sampling and zero deadband. A nonzero deadband is absolute. Direct debugging reads the current source value. Disabling automatic subscriptions switches production collection to polling.

Open the plugin

Open Development Configuration → Collection Configuration, create a device, and select OPC UA client.

This plugin manages its connection in the device properties and does not use an ordinary TCP, UDP, or serial channel. Configure common variables through Collection Configuration.

Plugin properties

Connection and authentication

SettingDescription
Endpoint URLDefault opc.tcp://127.0.0.1:49320. Enter the OPC UA server endpoint.
UsernameUsername required by the OPC UA server. Leave empty when the endpoint allows anonymous access.
PasswordPassword for the OPC UA user. Do not expose it in screenshots or logs.
Use Secure EndpointEnables a secure OPC UA endpoint according to the server policy.
Accept Untrusted CertificatesTemporary commissioning option. In production, configure the trust chain instead.
Client Certificate NameClient certificate selected from Certificate Management. Required by the endpoint’s security policy.

Subscription

SettingDescription
Data Change TriggerDefault Status or Value Changes. Select which data changes trigger a notification.
Enable Data SubscriptionsEnables subscription updates. Disable only when the project uses polling.

Protocol and data format

SettingDescription
Application NameDefault TGateway_OPC_UA_Master. The OPC UA application identity shown to the server.
Load Server Data TypesLoads the server’s node data types so variables can use the correct runtime type.
Use Source TimestampUses the source timestamp supplied by the OPC UA server when enabled.

Application name and source timestamp

Loading server data types

Alarms and conditions

SettingDescription
Subscribe alarm eventsDisabled by default. Receives device alarm, recovery, and acknowledgment states through device event forwarding.
Event nodeDefault i=2253. Use the NodeId of the object providing event notifications.
Condition capacityDefault 4096. Bounds retained conditions and branches; exceeding it reports a gap and suspends control.
Allow alarm acknowledgmentDisabled by default. Device method calls and current caller permissions must also allow control.

Conditions refresh after connection or reconnection. Old events cannot control alarms before refresh completes. Invoke Acknowledge Device Alarm under special methods using the latest event’s Generation, ConditionId, BranchId, and EventId. Confirm=false performs Acknowledge; Confirm=true performs Confirm when the device condition supports it. Stale generations, incorrect branches, and obsolete EventIds are rejected. Verify the device’s new condition state after a successful call.

Runtime and grouping

SettingDescription
Sampling / Polling Interval (ms)Default 1000 ms. Requests monitored-item sampling in subscription mode; the server may revise it. With subscriptions disabled, it schedules polling groups. It does not set the subscription publishing period.
Session Keep-alive Interval (ms)Default 3000 ms. Session KeepAlive interval; 0 selects 5000 ms rather than disabling KeepAlive.
DeadbandDefault 0. A nonzero value requests an absolute numeric deadband, not a percentage. At zero, the client sends no custom data-change filter.
Max Group SizeDefault 500. Maximum nodes grouped in one read or subscription operation.

Sampling or polling interval in milliseconds

Session keep-alive interval in milliseconds

Absolute deadband and maximum group size

Data Change Trigger options are Status Changes, Status or Value Changes, and Status, Value or Timestamp Changes. Choose the last option when a timestamp-only change must be reported.

Address rule

Regular variables

Use the OPC UA NodeId as the address of a regular collection variable, for example ns=2;s=Channel1.Temperature. Browse and read the node in device debug first, then copy the complete namespace and identifier.

OPC UA method variables

To let an external system call a method on the OPC UA server, create a dedicated variable under the OPC UA device and configure it as follows.

SettingRequired value
Variable nameUse a name that identifies the action, such as Start method or Recipe switch method. External RPC requests use this name to locate the method variable.
Other MethodSelect Call an OPC UA method in the plugin method list.
Variable addressEnter a standard JSON array containing the object and method NodeIds, for example ["ns=2;s=Machine1","ns=2;s=Machine1.Start"]. The first element must be the object that provides the method; the second must be the method node.
Read/Write PermissionSelect Write Only. A control method must not enter periodic collection, which could trigger it repeatedly.
RPC Write EnableEnable it. Web API, MQTT, and other external entries reject the call when this permission is disabled.
Write CheckDisable it. A method call is not a readable point; verify it from the RPC result and device state.

After saving the variable, provide the external RPC value in the same order as the OPC UA method’s InputArguments. The outer JSON array is the argument list.

Method inputsRPC variable value
No input arguments[]
One scalar argument[123]
Two arguments[123, "start"]
One array argument[[1, 2, 3]]

The client reads the standard InputArguments metadata from the server and converts each JSON value to the declared OPC UA data type. All output arguments are returned in order as a JSON array; a method without outputs returns an empty array.

Remote-control safety

Bind method variables only to control methods approved for the site. Grant the integration account only the required variable-write permission, and commission the call with an object and parameters that cannot affect production.

External RPC call

Web API

Call /api/gatewaywritevariablecontroller/setvariablevalue. Organize the request as device name → method variable name → input argument array:

{ "OPC device": { "Start method": [123, "start"] } }

The gateway checks that the variable exists, is writable, allows RPC writing, and does not belong to a paused device before calling the OPC UA method. The variable result’s Content contains the server output-argument array. For a failed call, inspect ErrorMessage, the RPC log, and the device log.

MQTT and other entries

MQTT RPC and every other entry connected to the variable RPC service use the same method variable. After the target RPC topic or script resolves the device name, variable name, and JSON argument array, it invokes the same OPC UA method. See Reverse RPC for topic, authentication, and response rules.

Device debug

Open Development Configuration → Collection Configuration, select the OPC UA device, open Protocol Debug at the top of the workspace.

Node browser

Follow the Ramp1 example above to select and read a variable node. Its complete NodeId, declared type and access rights determine the variable settings.

Browse the server namespace, select a node, and read it before importing variables. Use write operations only for approved writable nodes.

Debug checklist

  1. Confirm the endpoint URL and security mode.
  2. Browse the namespace and copy the exact NodeId.
  3. Read one node and compare its value and data type with the server tool.
  4. Create a subscription only after single-node reading works.

Functions

FunctionPurpose
Browse nodesBrowse the OPC UA namespace and inspect NodeId, data type, value, status, and timestamp.
Read and write nodesRead one selected node; write only to a server-approved test node.
Export and importExport selected nodes to a variable file or import them into the current device.
Subscription managementCreate, inspect, or cancel subscriptions for selected NodeIds.

Subscription and trust checks

Sampling / Polling Interval (ms) requests a monitored-item sampling interval; the server can revise it. It is not the subscription publishing period. Session Keep-alive Interval (ms) set to 0 uses 5000 ms rather than disabling KeepAlive. Nonzero deadband requests an absolute numeric deadband, not a percentage.

Status Changes, Status or Value Changes, and Status, Value or Timestamp Changes select the changes to observe. The current client submits this custom filter only with a nonzero deadband. With zero deadband, no custom filter is sent. Compare direct reads against subscriptions: with deadband 10, 1234 → 1239 can appear in a direct read without a notification, while 1250 crosses the threshold. Status-only filtering does not notify ordinary value-only changes.

The maximum group size chunks reads and automatic subscription organization; repeated NodeIds in a group can be deduplicated. More groups increase session work. Use Source Timestamp must be checked against correct server and gateway clocks. After writes, read the source node again; shared duty-cycle/write-priority fields do not establish an automatic read after every OPC UA write.

Accept Untrusted Certificates only permits the untrusted-certificate validation case. It does not waive expiry, application-URI, or host-name errors. Establish application certificate trust on both sides and select the proper user identity separately. An endpoint URL must include the actual scheme, host, port, and required path.

Method calls

In Method call, enter the object NodeId and method NodeId, which can be copied from Node browse. Add arguments in the order declared by the device. Each row accepts a string, number, Boolean, structure or array JSON, or Null, and can be moved or removed. For a method without input arguments, call it without adding rows.

Numeric input retains its original JSON text without conversion through a browser floating-point value. Enter a structure or array as one JSON argument. The selected format controls editing; the actual OPC UA types and argument count follow the device’s InputArguments declaration. Confirm the device, nodes and complete arguments before calling. Methods may change device state, so special-method execution permission and enabled device method calls are required. Results preserve output argument order; rejections and timeouts are not retried automatically.

You can edit up to 128 input arguments. The complete parameter JSON must fit within 64 KiB (65,536 UTF-8 bytes), including both NodeIds, array punctuation, and string escapes. Some characters use multiple bytes. The page rejects oversized arguments before confirmation; reduce the arguments and try again.

Alarm conditions and acknowledgement

Open Alarms and events in protocol debugging. First enable alarm-event subscription in the device properties and select an event-capable node. The list shows source, message, severity, active/recovered state, acknowledgement, confirmation, and time. Expand a row to inspect its condition, branch, and event identity.

OPC UA Alarms and events tab, source filter and subscription message

Search by source, message, or condition details; sort, paginate, and enable automatic refresh as needed. Refresh reads the current condition snapshot. If subscription is disabled, the device is unavailable, refresh is incomplete, or a gap is reported, check the event node, subscription, and condition capacity.

Control requires Allow alarm acknowledgement, the device’s Allow method calls, and dangerous-debug permission. Select Acknowledge alarm, then Confirm alarm only when the server requires that second step. An optional comment accompanies the operation. Read-only users can inspect conditions without control actions.

The confirmation dialog keeps the selected event identity. After reconnection, a newer event, or a target change invalidates it, refresh and review the condition again. After a successful call, check the server’s subsequent state. Acknowledgement does not clear the physical cause or acknowledge the gateway’s own alarm list.

Verify the configuration

  1. Browse to a known NodeId and read it. Confirm that the status code is good.
  2. Change the approved test node on the server and confirm that the read result or subscription value updates.
  3. Import a small set of test nodes and check NodeId, data type, value, and timestamp.
  4. When subscriptions are enabled, confirm Sampling / Polling Interval, Data Change Trigger, deadband, and Max Group Size.
  5. Write only to a server-approved test node, then read it again.
  6. Call a non-production test method first and verify the object NodeId, method NodeId, and input-argument count.
  7. Invoke the method once from the variable write dialog and once from the intended external RPC entry. Compare the output arguments, RPC log, and server-side result.

Troubleshooting

SymptomCheck
Cannot connectEndpoint URL, server availability, firewall, security policy, certificate trust, and username/password.
Certificate rejectedIdentify the rejecting side. A client rejection requires checking the server certificate and local trust; a server rejection requires checking its trust in the client application certificate. Check validity and application URI on both sides.
Browse returns no nodesSession security, user permissions, namespace selection, and the starting NodeId.
Read returns an errorExact NodeId spelling, namespace index, node access permission, and server data type.
Subscription does not updateEnable Data Subscriptions, Data Change Trigger, deadband, Sampling / Polling Interval, and server subscription limits.
Value type is wrongEnable Load Server Data Types and compare the variable data type with the OPC UA node type.
Call an OPC UA method is missingConfirm that the device uses the current OPC UA client plugin and restart TGateway after updating the application.
Input-argument count is invalidThe outer RPC array is the argument list. For one array argument, use a nested array such as [[1, 2, 3]].
Input type does not matchCompare the payload with the method’s InputArguments data types and value ranks, and confirm that the server publishes the standard metadata.
Method is invalid or not executableCheck that the object owns the method, the OPC UA user can execute it, and the method is executable.
Method runs repeatedlySet the method variable to Write only so periodic collection cannot invoke it.
External RPC is rejectedEnable RPC writing on the method variable, confirm that the device is not paused, and grant the integration account variable-write permission.