h-opc-net
1.0.0.105
dotnet add package h-opc-net --version 1.0.0.105
NuGet\Install-Package h-opc-net -Version 1.0.0.105
<PackageReference Include="h-opc-net" Version="1.0.0.105" />
<PackageVersion Include="h-opc-net" Version="1.0.0.105" />
<PackageReference Include="h-opc-net" />
paket add h-opc-net --version 1.0.0.105
#r "nuget: h-opc-net, 1.0.0.105"
#:package h-opc-net@1.0.0.105
#addin nuget:?package=h-opc-net&version=1.0.0.105
#tool nuget:?package=h-opc-net&version=1.0.0.105
h-opc-net
An Opc Library and a command line to perform OPC operations with ease and transparency among different protocols. Currently supports synchronous operation over UA and DA protocols. This fork targets modern .NET (net8.0/net9.0/net10.0) and is actively maintained.
Table of Contents
Use
To install h-opc-net, run the following command in the Package Manager Console:
PM> Install-Package h-opc-net
To install the command line interface, head to the nuget gallery.
Documentation
to use the UA Client simply...
using (var client = new UaClient(new Uri("opc.tcp://host-url")))
{
client.Connect();
// Use `client` here
}
or with options...
var options = new UaClientOptions {
UserIdentity = new Opc.Ua.UserIdentity("<your-username>", "<your-password>")
};
using (var client = new UaClient(new Uri("opc.tcp://host-url")), options)
{
client.Connect();
// Use `client` here
}
and to use the DA Client instead:
using (var client = new DaClient(new Uri("opcda://host-url")))
{
client.Connect();
// Use `client` here
}
Exploring the nodes
You can get a reference to a node with...
var node = client.FindNode("path.to.my.node");
This will get you a reference to the node node in the folder path.to.my.
You can use the node reference to explore the hieriarchy of nodes with the properties Parent and SubNodes. For example...
Node parentNode = node.Parent;
IEnumerable<Node> children = client.ExploreFolder(node.Tag);
IENumerable<Node> grandChildren = children.SelectMany(m => client.ExploreFolder(m.Tag));
Read a node
Reading a variable? As simple as...
var myString = client.Read<string>("path.to.string").Value;
var myInt = client.Read<int>("path.to.num").Value;
The example above will read a string from the tags string and num in the folder path.to
Writing to a node
To write a value just...
client.Write("path.to.string", "My new value");
client.Write("path.to.num", 42);
Monitoring a tag
Dead-simple monitoring:
client.Monitor<string>("path.to.string", (readEvent, unsubscribe) =>
{
DoSomethingWithYourValue(readEvent.Value);
if(ThatsEnough == true)
unsubscribe();
});
The second parameter is an Action<T, Action> that has two parameter:
readEventcontains all the information relevant to the event such as timestamps, quality and the valueunsubscribeis a function that unsubscribes the current monitored item. It's very handy when you want to terminate your callback
it's important that you either enclose the client into a using statement or call Dispose() when you are finished, to unsubscribe all the monitored items and terminate the connection!
Go Asynchronous!
Each method as an asynchornous counterpart that can be used with the async/await syntax. The asynchronous syntax is recommended over the synchronous one (maybe the synchronous one will be deprecated one day).
Command line
You can also use the command line interface project to quickly test your an OPC. Build the h-opc-cli project or download it from the release page of this repository, then run:
h-opc-cli.exe [OpcType] [server-url]
Where OpcType is the type of opc to use (e.g: "UA", "DA"). Once the project is running, you can use the internal command to manipulate the variable. To have more information aboute the internal commands, type help or ?
What's new in 1.0.0.105
- Modern async OPC UA stack: all OPC Foundation client APIs have been migrated from the
obsolete synchronous/Begin-End set (
Session.Read/Write/Browse,BeginRead/EndRead,Subscription.Create/Delete,Session.Create/Recreate,DiscoveryClient.Create/GetEndpoints,NodeCache.Find, parameterless telemetry ctors) to the supported Task-based set (ReadAsync/WriteAsync/BrowseAsync/CloseAsync/CreateAsync/RecreateAsync, telemetry-aware constructors). The library now compiles with zero obsolete-API warnings, which keeps it buildable against future OPC Foundation releases that remove the legacy APIs. - The public API surface of
UaClient/DaClientis unchanged: synchronous methods still exist and now wrap the async calls with deadlock-safe bridging (AsyncHelpers.RunSync), so existing code keeps working without changes.ReadAsync/WriteAsyncnow use the native task-based calls instead of hand-rolledTaskCompletionSource+ Begin/End plumbing. ReConnect/RecreateSessionnow go through the session factory'sRecreateAsync, the supported replacement for the removedSession.Reconnect/Session.Recreatemethods.- Bug fixes carried from 1.0.0.104.x maintenance: Monitor overload infinite recursion
(StackOverflow), clear
OpcExceptioninstead ofNullReferenceExceptionwhen reading unreadable/bad-quality tags into value types, correctGetDataTypemapping for Float/String and other built-in types, thread-safe DA node cache, DA monitor subscriptions cleaned up onDispose(no more server-side leaks), configurable DAMonitorInterval, per-entry folder cache expiry, hardenedDisposefor both clients, CLI EOF handling and float/string writes. - Restored and modernized the test suite (NUnit 4): offline unit tests plus UA/DA integration tests with environment-overridable endpoints; 55/55 tests pass, including integration tests against a live OPC UA demo server.
Disclaimer
This fork is maintained by XiaoyuvaX; the original project is hylasoft/h-opc by Hylasoft. OPC UA and DA connectivity is provided by the OPC Foundation .NET Standard stack and Quick.OpcNetApi.
Roadmap
- ...
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.5.378.156)
- Quick.OpcNetApi (>= 2.1.108)
- Quick.OpcNetApi.Com (>= 2.1.108)
-
net8.0
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.5.378.156)
- Quick.OpcNetApi (>= 2.1.108)
- Quick.OpcNetApi.Com (>= 2.1.108)
-
net9.0
- OPCFoundation.NetStandard.Opc.Ua.Client (>= 1.5.378.156)
- Quick.OpcNetApi (>= 2.1.108)
- Quick.OpcNetApi.Com (>= 2.1.108)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on h-opc-net:
| Package | Downloads |
|---|---|
|
Wima.Opc
Wima通用Opc基础库,提供两个底层Opc框架:hOpc和LibUA的支持,和客户端抽象接口。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0.105 | 144 | 9/10/2026 |
| 1.0.0.104 | 489 | 4/18/2025 |
| 1.0.0.100 | 206 | 1/9/2025 |
| 1.0.0 | 271 | 11/11/2024 |
| 1.0.0-alpha | 241 | 11/11/2024 |
Migrate all OPC Foundation client APIs to the modern async set (ReadAsync/WriteAsync/BrowseAsync/CloseAsync/CreateAsync/RecreateAsync); removes all obsolete-API warnings. Monitor recursion fix, clear errors for unreadable tags, correct GetDataType mapping, thread-safe DA cache, DA subscription cleanup, per-entry cache expiry.