Skip to main content

Session — DarraOpcUa

DarraOpcUa This is the main Client class; one instance corresponds to one OPC UA Session. All access operations (Read / Write / Browse / Subscribe / Call / History) originate from this object.

Subpage Redirect
  • For structural and connection specifications, please refer to Constructor.
  • For connecting/disconnecting, please refer to Connection Management.
  • For single-item and batch read/write operations, please refer to Read / Write.
  • For the Unified Incident Reporting Channel, please refer to Events.
  • For namespace lookup, please refer to Namespaces.
  • For information on heartbeat and session keep-alive, please refer to KeepAlive.

Public Attributes​

CategoryPropertyTypeAccessDescription
ConnectionsEndpointUrlstringRThe endpoint URL specified at construction
SecurityModeMessageSecurityModeRSecurity Mode (None / Sign / SignAndEncrypt)
SecurityPolicyUristringRSecurityPolicy URI (e.g., #None / #Basic256Sha256)
ClientCertificatePfxPathstringRClient certificate PFX path
StatusStateSessionStateRCurrent session status (Disconnected / Connecting / Connected / Reconnecting / Closing / Failed)
IsConnectedboolRWhether the connection is active (= State == Connected)
Child ObjectsNodesNodeCollectionRNode accessor (retrieves nodes by string NodeId index)
NamespacesNamespaceCollectionRNamespace URI ↔ Index Conversion
EventsEventsOpcUaEventsRUnified channel for session-level events (StateChanged / Connected / Disconnected / Reconnecting / Reconnected / KeepAlive / CommunicationError / SubscriptionLost / Any / NodeRemoved / ...)
ConfigurationKeepAliveIntervalMsuintRWKeepAlive heartbeat interval (default 10000 ms, 0 = disabled)
AutoPublishboolRWEnable or disable the background Publish thread (automatically enabled after a successful Connect)

Public Methods​

Connection Management​

  • Connect() — Establish a connection (Hello → SecureChannel → Session → Activate)
  • Disconnect() — Connection terminated voluntarily; the instance can reconnect
  • Dispose() — Disconnect and release the session handle (idempotent, can be called multiple times)

Heartbeat and Release​

  • Publish(timeoutMs = 2000) — Manually trigger a Publish once (usually not necessary), returns StatusCode

Read / Write​

Browse​

Subscribe​

Method Call​

History​

The history entry is directly attached to DarraOpcUa; it is not a separate History property:

Control​

  • Cancel(requestHandle) — Cancel pending requests and return uint

Complete Example​

using System;
using System.Threading;
using DarraOpcUa_Client;

using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Events.Connected += (s, e) => Console.WriteLine($"Connected to {e.EndpointUrl}");
ua.Events.Disconnected += (s, e) => Console.WriteLine($"Disconnected: {e.StatusCode} {e.Message}");
ua.Connect();

// Read
using var dv = ua.Read("ns=2;s=Temperature");
Console.WriteLine($"T = {dv.Value.AsDouble} °C");

// Write
using var sp = new Variant();
sp.Double = 42.0;

var st = ua.Write("ns=2;s=Setpoint", sp);
Console.WriteLine($"Write status = {st}");

// Subscribe
using var sub = ua.CreateSubscription(500);
sub.DataChanged += (s, e) =>
Console.WriteLine($"{e.NodeId} = {e.ValueString} ({e.Status})");
sub.Add("ns=2;s=Counter");

// Methods
using var a = new Variant(); a.Int32 = 3;
using var b = new Variant(); b.Int32 = 4;

var outputs = ua.Call("ns=2;s=Calc", "ns=2;s=Calc.Add", a, b);
foreach (var v in outputs) using (v)
Console.WriteLine($"sum = {v.AsInt32}");

Thread.Sleep(TimeSpan.FromMinutes(1));

Next Step​