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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="h-opc-net" Version="1.0.0.105" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="h-opc-net" Version="1.0.0.105" />
                    
Directory.Packages.props
<PackageReference Include="h-opc-net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add h-opc-net --version 1.0.0.105
                    
#r "nuget: h-opc-net, 1.0.0.105"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package h-opc-net@1.0.0.105
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=h-opc-net&version=1.0.0.105
                    
Install as a Cake Addin
#tool nuget:?package=h-opc-net&version=1.0.0.105
                    
Install as a Cake Tool

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:

  • readEvent contains all the information relevant to the event such as timestamps, quality and the value
  • unsubscribe is 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/DaClient is 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/WriteAsync now use the native task-based calls instead of hand-rolled TaskCompletionSource + Begin/End plumbing.
  • ReConnect/RecreateSession now go through the session factory's RecreateAsync, the supported replacement for the removed Session.Reconnect/Session.Recreate methods.
  • Bug fixes carried from 1.0.0.104.x maintenance: Monitor overload infinite recursion (StackOverflow), clear OpcException instead of NullReferenceException when reading unreadable/bad-quality tags into value types, correct GetDataType mapping for Float/String and other built-in types, thread-safe DA node cache, DA monitor subscriptions cleaned up on Dispose (no more server-side leaks), configurable DA MonitorInterval, per-entry folder cache expiry, hardened Dispose for 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.