Skip to main content

Darra OPC UA Client — C# SDK

Darra OPC UA Client C# Binding. Advanced cross-language alignment API—the concepts you learn here can be directly applied to Java, Python, C++, Rust, and C.

Chapter Navigation
  • Getting Started → Session (Construct / Connect / Read / Write / KeepAlive)
  • Browse → Nodes (Browse / Path Resolution / RegisterNodes)
  • Real-time → Subscription (CreateSubscription / MonitoredItem / DataChanged)
  • History → History (Raw / Modified / AtTime / Processed / Events / Update / Delete)
  • Call → Method (Call)
  • Discover → Discovery (GetEndpoints / FindServers)
  • Data → Data Types (Variant / DataValue / WellKnownNodes / OpcUaNodeId / NumericRange / Structure Decoding)
  • Security → Security (Certificates / Encryption)

Installation​

dotnet add package Darra.OpcUa

System Requirements​

ItemRequirements
Framework.NET 8
OSWindows 10/11
Platformx64
AgreementOPC UA TCP (opc.tcp://)

Namespace​

using DarraOpcUa_Client;

Main Types:

TypeUses
DarraOpcUaClient Superclass (Session)
OpcUaSubscriptionData Subscription Container
OpcUaEventSubscriptionEvent Subscriptions (Alarms & Conditions)
NodeCollection / OpcUaNodeLazy Load Node Access
Variant / DataValueData Container
OpcUaDiscovery (Static)GetEndpoints / FindServers
WellKnownNodes (Static)OPC UA Standard Node Constants
CertificateManager (static)Client Certificate: Self-Signed / Cached / Diagnostic
OpcUaExceptionExceptions associated StatusCode with "carry"

Quick Start in One Minute​

using System;
using DarraOpcUa_Client;

// Default MessageSecurityMode.None (plaintext); to encrypt, see "Encryption and Credentials" below
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();

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

// Write
using (var v = new Variant())
{
v.Double = 42.0;
ua.Write("ns=2;s=Setpoint", v);
}

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

Advanced API Overview​

FeatureEntry APIDescription
Connection / Encryptionnew DarraOpcUa(...) + Connect()MessageSecurityMode.None / Sign / SignAndEncrypt; Identity token: currently supports two types—anonymous and username
Single-Point Read/Writeua.Read / WriteSingle Node, Single Attribute
Batch Readua.ReadMany(nodes[, attr])Once RPC, N nodes
Browse Treeua.Browse / BrowseMany / BrowseWithPaging / BrowseNextFull pagination support
Path Resolutionua.Resolve / TranslateBrowsePathsBrowse Path → NodeId
Registration Nodeua.RegisterNodes / UnregisterNodesReduces server-side parsing overhead during frequent, repeated requests to the same node (benefits based on actual server-side testing)
Data Subscriptionsua.CreateSubscription + sub.Add / AddManypublishing / sampling, two-layer
Event Subscriptionua.SubscribeEventsAlarms & Conditions
Adjustment Methodsua.Call(objId, mtdId, ...)OPC UA Method Node
History Readingua.ReadHistory / ReadHistoryModified / ReadHistoryAtTime / ReadHistoryProcessed / ReadHistoryEventsRaw / Modified / AtTime / Processed / Events
Writing Historyua.UpdateHistory / DeleteHistoryRangeInsert / Replace / Update / Remove
Heartbeatua.KeepAliveIntervalMsBackground Periodic Monitoring
Automatic Reconnection(Built-in)Check for Disconnections → Republish Subscribe
Unified Eventua.Events.*Session / Subscription / Data / Communication Errors
Service DiscoveryOpcUaDiscovery.GetEndpoints / FindServersNo session required
Certificate ToolsCertificateManager.EnsureClientCertificate / ForceRegenerate / DescribeCachedCertificateClient PFX Automatic Generation and Diagnostics
Encryption and Credentials — Insecure by default; must be explicitly enabled

new DarraOpcUa(endpointUrl) securityMode The default is MessageSecurityMode.None, meaning plaintext is not encrypted.. The "None / Sign / SignAndEncrypt" in the table above isList of Optional Abilities, It is neither the default value nor "Enabled."

  • To enable encryption, you must explicitly pass securityMode: MessageSecurityMode.Sign or .SignAndEncrypt. If securityPolicyUri is not passed, None is used SecurityPolicy#None, and the rest automatically fall back to SecurityPolicy#Basic256Sha256.
  • Sign / A client certificate (SignAndEncrypt) clientCertPath must be provided; otherwise, the connection will fail. You can use CertificateManager.EnsureClientCertificate() auto-generation PFX.
  • Usernames, passwords, and encryption modes are three separate matters.: As long as the constructor receives username it will use those credentials, I won't refuse just because of securityMode = None .... In other words, is new DarraOpcUa(url, username: "op", password: "...")Sending passwords in plain text over the network. In a production environment, you must first configure [the system] before entering SignAndEncrypt your credentials.
  • If the server certificate is not transmitted, the server's identity is not verified.: Do not transmit; use an unencrypted channel for "None" serverCertPath in real time GetEndpoints; use the certificate self-signed by the server to establish an encrypted channel —— None TOFU / Fingerprint storage and comparison, A man-in-the-middle could impersonate the server. To verify that "you're connecting to the correct server," check the server's certificate PFX (PKCS#12, no password) Pass the path explicitly; for details, see Security。
  • The identity token only accepts "anonymous" or a username: If no arguments are passed to the constructor, it is username Anonymous; if arguments are passed, it is Username.UserTokenType The enumeration also includes Certificate / Issued, but there is currently no corresponding entry for the constructor. clientCertPath is the client certificate used for the encrypted channel and is not the same as the identity token.

Cross-Language Alignment​

The API naming and behavior of the C# SDK serve as the reference implementation for the other language bindings. The Java, Python, C++, Rust, and C bindings follow their own language conventions, but the semantics are consistent (e.g. C# ua.Read ↔ Python ua.read ↔ Rust ua.read(...)). Start with C#; switching to another language later only requires renaming — the concepts and semantics stay the same.

Just read through the left sidebar in order to master everything SDK API.