hongmao.HmExtension.Opc 1.0.3

dotnet add package hongmao.HmExtension.Opc --version 1.0.3                
NuGet\Install-Package hongmao.HmExtension.Opc -Version 1.0.3                
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="hongmao.HmExtension.Opc" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add hongmao.HmExtension.Opc --version 1.0.3                
#r "nuget: hongmao.HmExtension.Opc, 1.0.3"                
#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.
// Install hongmao.HmExtension.Opc as a Cake Addin
#addin nuget:?package=hongmao.HmExtension.Opc&version=1.0.3

// Install hongmao.HmExtension.Opc as a Cake Tool
#tool nuget:?package=hongmao.HmExtension.Opc&version=1.0.3                

简介

本项目旨在简化OPC的使用,提供了一个简单的API,使得用户可以通过简单的代码实现OPC的读写操作。

使用方法

1. 安装依赖

dotnet add package hongmao.HmExtension.Opc

2. 创建OPC客户端

var client = HmOpcClientFactory.CreateOpcDaClient();

3. 获取OPC服务器列表

var servers = client.GetServers(); // 获取本地OPC服务器列表
// var servers = client.GetServers("127.0.0.1")

4. 连接OPC服务器

client.Host = "127.0.0.1";
client.ServerName = "Kepware.KEPServerEX.V6";
client.Connect();

5. 浏览节点数据

var nodes = client.Browses(); // 浏览节点列表
var treeNodes = client.BrowseTrees(); // 浏览节点树
var node = client.GetOpcNode("Channel1.Device1.Tag1"); // 获取节点信息

6. 读取数据

var node = client.GetOpcNode("Channel1.Device1.Tag1"); // 获取节点信息
var value = client.ReadValue(node); // 读取节点数据

7. 写入数据

var node = client.GetOpcNode("Channel1.Device1.Tag1"); // 获取节点信息
client.WriteValue(100); // 写入节点数据

8. 监听数据变化

var node = client.GetOpcNode("Channel1.Device1.Tag1"); // 获取节点信息
client.OnDataChange += (groupName,oldValue,newValue)=>{
	Console.WriteLine($"数据变化:{groupName} {oldValue} -> {newValue}");
}

9. 断开连接

client.Disconnect();
Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 76 9/4/2024
1.0.2 111 8/21/2024
1.0.1 102 8/21/2024
1.0.0 112 8/20/2024

1. 修复了获取指定名称节点报空指针问题
2. 优化获取节点方法,可以指定是否返回父节点
3. 新增订阅状态变化事件
4. 新增检查节点是否订阅方法
5. 完善OPC测试界面