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
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Connections | EndpointUrl | string | R | The endpoint URL specified at construction |
SecurityMode | MessageSecurityMode | R | Security Mode (None / Sign / SignAndEncrypt) | |
SecurityPolicyUri | string | R | SecurityPolicy URI (e.g., #None / #Basic256Sha256) | |
ClientCertificatePfxPath | string | R | Client certificate PFX path | |
| Status | State | SessionState | R | Current session status (Disconnected / Connecting / Connected / Reconnecting / Closing / Failed) |
IsConnected | bool | R | Whether the connection is active (= State == Connected) | |
| Child Objects | Nodes | NodeCollection | R | Node accessor (retrieves nodes by string NodeId index) |
Namespaces | NamespaceCollection | R | Namespace URI ↔ Index Conversion | |
| Events | Events | OpcUaEvents | R | Unified channel for session-level events (StateChanged / Connected / Disconnected / Reconnecting / Reconnected / KeepAlive / CommunicationError / SubscriptionLost / Any / NodeRemoved / ...) |
| Configuration | KeepAliveIntervalMs | uint | RW | KeepAlive heartbeat interval (default 10000 ms, 0 = disabled) |
AutoPublish | bool | RW | Enable 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 reconnectDispose()— 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), returnsStatusCode
Read / Write
Read(nodeId, attribute = Value)— Read a Single Node's Specified AttributeReadMany(nodeIds, attribute)— Batch Read (Single Attribute)ReadMany(items)— Batch Read (Any NodeId + AttributeId Combination)Write(nodeId, value, attribute = Value)— Order Entry Node
Browse
Browse(nodeId, filter = Unspecified)— Single-page viewBrowseMany(nodeIds, filter)— Batch ViewBrowseWithPaging(nodeId, filter)— Includes ContinuationPoint page-turning supportBrowseNext(continuationPoint, release = false)— Continue to the next pageTranslateBrowsePaths(paths)— Batch parse the paths to NodeIdResolve(path)— Parsing a Single Absolute PathResolve(startNodeId, path)— Parsing a Single Relative PathRegisterNodes(nodeIds)— Register for a Temporary High-Efficiency Plan NodeIdUnregisterNodes(registeredNodeIds)— Cancel Temporary NodeId
Subscribe
CreateSubscription(publishingIntervalMs = 500.0)— Create a data subscriptionSubscribeEvents(nodeId = null, existingSubscription = null)— Subscribe to Events (Alarms / Conditions)TransferSubscriptions(subscriptionIds, sendInitialValues = true)— Migrating Subscriptions Across Sessions
Method Call
Call(objectId, methodId, ...inputs)— Call the node OPC UA Method
History
The history entry is directly attached to DarraOpcUa; it is not a separate History property:
ReadHistory(nodeId, startTime, endTime, maxValues = 0)— Read raw history (simplified entry point)ReadHistoryModified(...)— Reading a history that includes revision recordsReadHistoryAtTime(...)— Read the interpolated value at a specified time pointReadHistoryProcessed(...)— Aggregation (Average / Minimum / Maximum / TimeAverage / ...)ReadHistoryEvents(...)— Reading About Historical EventsUpdateHistory(nodeId, updateType, values)— Insert / Replace / Update / Remove HistoryDeleteHistoryRange(nodeId, start, end, deleteModifiedToo = false)— Delete history by time period
Control
Cancel(requestHandle)— Cancel pending requests and returnuint
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));