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.
- 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
- NuGet (Recommended)
- Package Manager
- csproj
dotnet add package Darra.OpcUa
Install-Package Darra.OpcUa
<PackageReference Include="Darra.OpcUa" Version="*" />
System Requirements
| Item | Requirements |
|---|---|
| Framework | .NET 8 |
| OS | Windows 10/11 |
| Platform | x64 |
| Agreement | OPC UA TCP (opc.tcp://) |
Namespace
using DarraOpcUa_Client;
Main Types:
| Type | Uses |
|---|---|
| DarraOpcUa | Client Superclass (Session) |
| OpcUaSubscription | Data Subscription Container |
| OpcUaEventSubscription | Event Subscriptions (Alarms & Conditions) |
| NodeCollection / OpcUaNode | Lazy Load Node Access |
| Variant / DataValue | Data Container |
| OpcUaDiscovery (Static) | GetEndpoints / FindServers |
| WellKnownNodes (Static) | OPC UA Standard Node Constants |
| CertificateManager (static) | Client Certificate: Self-Signed / Cached / Diagnostic |
| OpcUaException | Exceptions 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
| Feature | Entry API | Description |
|---|---|---|
| Connection / Encryption | new DarraOpcUa(...) + Connect() | MessageSecurityMode.None / Sign / SignAndEncrypt; Identity token: currently supports two types—anonymous and username |
| Single-Point Read/Write | ua.Read / Write | Single Node, Single Attribute |
| Batch Read | ua.ReadMany(nodes[, attr]) | Once RPC, N nodes |
| Browse Tree | ua.Browse / BrowseMany / BrowseWithPaging / BrowseNext | Full pagination support |
| Path Resolution | ua.Resolve / TranslateBrowsePaths | Browse Path → NodeId |
| Registration Node | ua.RegisterNodes / UnregisterNodes | Reduces server-side parsing overhead during frequent, repeated requests to the same node (benefits based on actual server-side testing) |
| Data Subscriptions | ua.CreateSubscription + sub.Add / AddMany | publishing / sampling, two-layer |
| Event Subscription | ua.SubscribeEvents | Alarms & Conditions |
| Adjustment Methods | ua.Call(objId, mtdId, ...) | OPC UA Method Node |
| History Reading | ua.ReadHistory / ReadHistoryModified / ReadHistoryAtTime / ReadHistoryProcessed / ReadHistoryEvents | Raw / Modified / AtTime / Processed / Events |
| Writing History | ua.UpdateHistory / DeleteHistoryRange | Insert / Replace / Update / Remove |
| Heartbeat | ua.KeepAliveIntervalMs | Background Periodic Monitoring |
| Automatic Reconnection | (Built-in) | Check for Disconnections → Republish Subscribe |
| Unified Event | ua.Events.* | Session / Subscription / Data / Communication Errors |
| Service Discovery | OpcUaDiscovery.GetEndpoints / FindServers | No session required |
| Certificate Tools | CertificateManager.EnsureClientCertificate / ForceRegenerate / DescribeCachedCertificate | Client PFX Automatic Generation and Diagnostics |
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.Signor.SignAndEncrypt. IfsecurityPolicyUriis not passed,Noneis usedSecurityPolicy#None, and the rest automatically fall back toSecurityPolicy#Basic256Sha256. Sign/ A client certificate (SignAndEncrypt)clientCertPathmust be provided; otherwise, the connection will fail. You can useCertificateManager.EnsureClientCertificate()auto-generation PFX.- Usernames, passwords, and encryption modes are three separate matters.: As long as the constructor receives
usernameit will use those credentials, I won't refuse just because ofsecurityMode = None.... In other words, isnew DarraOpcUa(url, username: "op", password: "...")Sending passwords in plain text over the network. In a production environment, you must first configure [the system] before enteringSignAndEncryptyour credentials. - If the server certificate is not transmitted, the server's identity is not verified.: Do not transmit; use an unencrypted channel for "None"
serverCertPathin real timeGetEndpoints; 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
usernameAnonymous; if arguments are passed, it isUsername.UserTokenTypeThe enumeration also includesCertificate/Issued, but there is currently no corresponding entry for the constructor.clientCertPathis 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.