Snet.GE
25.271.1
dotnet add package Snet.GE --version 25.271.1
NuGet\Install-Package Snet.GE -Version 25.271.1
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="Snet.GE" Version="25.271.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Snet.GE" Version="25.271.1" />
<PackageReference Include="Snet.GE" />
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 Snet.GE --version 25.271.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Snet.GE, 25.271.1"
#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 Snet.GE@25.271.1
#: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=Snet.GE&version=25.271.1
#tool nuget:?package=Snet.GE&version=25.271.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<img src="https://api.shunnet.top/pic/nuget.png" height="32"> Snet - 工业协议与数据采集框架
🚀 统一 · 高效 · 灵活 · 可扩展
面向工业数据采集、传输、转发、消息中间件的全栈式解决方案
✨ 框架特色
- ✅ 所有协议公共函数 支持同步 / 异步
- ✅ 协议 读写参数统一,入参出参统一
- ✅ 支持多点转发 / 多点解析
- ✅ 快速对接与配置,可即插即用
- ✅ 支持虚拟点位(模拟测试更便捷)
- ✅ 采集协议全面支持 订阅模式
- ✅ 采集与转发协议接口统一
- ✅ 事件结果统一,并支持 异步事件
- ✅ 所有采集协议均支持 WebAPI 控制与数据获取
- ✅ 快捷二次开发,仅需继承接口与抽象类即可
- ✅ 拥有详细的日志记录,高度自定义日志输出路径与记录到数据库
- ✅ 全局支持中英文实时切换
- ✅ 支持反射,脚本解析,进程缓存,共享缓存,抽象扩展
- ✅ 支持JSON/XML/Protobuf...,一系列序列化与反序列化
🧩 核心组件
[ Snet.Log ] 日志系统
Verbose
详细信息Debug
调试Info
信息Warning
警告Error
错误Fatal
致命错误
[ Snet.Unility ] 公共方法集合
- 字节、枚举、文件、字符串、验证、比对、转换、反射、Json、Xml、Ftp、System ...
[ Snet.Model ]
- 特性、数据结构、枚举、接口
[ Snet.Core ]
- 抽象、扩展、处理、反射、队列、中间件、脚本、订阅、虚拟地址、TCP、UDP、HTTP、WS、串口、WebApi
[ Snet.Driver ]
- 底层驱动通信库
📡 采集协议
支持 20+ 种工业通信协议,覆盖 PLC / 工控 / 电力 / DB / 标准通信 等:
三菱 / 西门子 / Modbus / 汇川 / 欧姆龙 / LSis / 基恩士 / 松下 / 罗克韦尔 / 倍福
通用电器 / 安川 / 山武 / 永宏 / 丰炜 / 富士 / 信捷 / 麦格米特 / 横河 / 丰田 / 台达 / 维控
电力通讯规约 / OPC (UA、DA、DAHttp) / DB (SqlServer、MySql、Oracle、SQLite)
TEP (Tcp扩展插件) / Sim (模拟库) / 英威腾 / 西蒙
接口定义:
/// <summary>
/// 数采接口
/// </summary>
public interface IDaq : IOn, IOff, IRead, IWrite, ISubscribe, IGetStatus, IEvent, IGetParam, ICreateInstance, ILog, IWA, IGetObject, ILanguage, IDisposable { }
📬 消息中间件协议
支持常见的高性能消息中间件:
- Kafka [AdminClient、Producer、Consumer]
- Mqtt [Client (Publish/Subscribe)、Service、WSService]
- RabbitMQ [Publish、Subscribe]
- Netty [Client (Publish/Subscribe)、Service]
- NetMQ [Publish、Subscribe]
接口定义:
/// <summary>
/// 消息中间件接口
/// </summary>
public interface IMq : IOn, IOff, IProducer, IConsumer, IGetStatus, IEvent, IGetParam, ICreateInstance, ILog, ILanguage, IDisposable { }
🖥️ 协议服务端 (数据模拟)
- Mqtt 服务端
- Mqtt WebSocket 服务端
- OpcUa 服务端
- Socket 服务端
- WebSocket 服务端
⚡ 实例创建方式
支持 无参、有参、单例、接口化实例 等多种方式,快速上手:
//实例创建的几种方式
//以OPCUA 采集协议为例
using Snet.Model.@interface;
using Snet.Opc.ua.client;
OpcUaClientOperate? operate = null;
IDaq? daq = null;
//无参实例
operate = new OpcUaClientOperate();
//无参实例调函数创建实例,与无参实例配合使用
operate = new OpcUaClientOperate().CreateInstance(new OpcUaClientData.Basics()).GetRData<OpcUaClientOperate>();
//有参实例
operate = new OpcUaClientOperate(new OpcUaClientData.Basics());
//有参单例
operate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics());
//接口 - 无参实例
daq = new OpcUaClientOperate();
//接口 - 无参实例调函数创建实例,与无参实例配合使用
daq = new OpcUaClientOperate().CreateInstance(new OpcUaClientData.Basics()).GetRData<OpcUaClientOperate>();
//接口 - 有参实例
daq = new OpcUaClientOperate(new OpcUaClientData.Basics());
//接口 - 有参单例
daq = OpcUaClientOperate.Instance(new OpcUaClientData.Basics());
using (operate)
{
//使用完直接释放
}
using (daq)
{
//使用完直接释放
}
📥 采集应用示例
通过 NuGet 安装协议包,快速实现采集:
//采集协议
//以OPCUA 采集协议为例
using System.Collections.Concurrent;
using Snet.Core.script;
using Snet.Log;
using Snet.Model.data;
using Snet.Model.@enum;
using Snet.Opc.ua.client;
using Snet.Utility;
using (OpcUaClientOperate operate = new OpcUaClientOperate(new OpcUaClientData.Basics
{
ServerUrl = "opc.tcp://127.0.0.1:6688",
UserName = "user",
Password = "password",
}))
{
//点位地址
Address address = new Address();
address.SN = Guid.NewGuid().ToString();
address.CreationTime = DateTime.Now.ToLocalTime();
address.AddressArray = new List<AddressDetails>
{
new AddressDetails() //地址详情参数介绍
{
SN=$"", //可以理解成唯一标识符(可以存机台号、组名、车间、厂)
AddressAnotherName="", //地址别名
AddressDataType=DataType.String, //数据类型
AddressDescribe="", //地址描述
AddressExtendParam=new object(), //扩展数据
AddressName="", //实际地址[ 不能为空 ]
AddressPropertyName="", //属性名称
AddressType=AddressType.Reality, //地址类型
IsEnable=true, //是否启用
AddressMqParam=new AddressMq //消息队列生产
{
ISns = new List<string> { "ISN1", "ISN2" }, //实例SN
Topic = $"topic", //主题
ContentFormat="Value:{0}" //内容格式
},
AddressParseParam=new AddressParse //脚本解析实例
{
ScriptParam=new ScriptData.Basics //脚本解析基础数据
{
ScriptCode = @"function Convert(addressname,value) { return '【这是调用脚本解析】传入的地址是:'+ addressname + '----传入的参数是:' + value; }", //脚本代码
ScriptFunction = "Convert", //脚本入口
ScriptType = ScriptData.ScriptType.JavaScript //脚本类型
}
},
//AddressParseParam = new AddressParse //反射解析
//{
// ReflectionParam = new object[] //反射解析的参数
// {
// new ReflectionData.Basics //反射解析基础数据
// {
// //反射解析的基础数据
// },
// "SN" //反射解析的SN
// }
// },
}
};
#region 打开
OperateResult result = operate.On();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 打开
#region 读取
//读取
result = operate.Read(address);
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 读取
#region 订阅
//事件信息结果
operate.OnInfoEvent += delegate (object? sender, EventInfoResult e)
{
LogHelper.Info(e.ToJson(true)); //转成JSON.JSON格式化
};
//事件数据结果
operate.OnDataEvent += delegate (object? sender, EventDataResult e)
{
LogHelper.Info(e.ToJson(true)); //转成JSON.JSON格式化
//得到精简版数据 速度很快 <=2ms
IEnumerable<AddressValueSimplify>? simplifies = e.GetSource<ConcurrentDictionary<string, AddressValue>>()?.GetSimplifyArray();
};
result = operate.Subscribe(address);
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 订阅
#region 写入
ConcurrentDictionary<string, object> value = new ConcurrentDictionary<string, object>
{
["地址"] = "string 值",
["地址"] = (float)1.1f,
["地址"] = (double)2.2d,
["地址"] = (int)3,
["地址"] = true
};
result = operate.Write(value);
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 写入
#region 关闭
result = operate.Off();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 关闭
#region 获取状态
result = operate.GetStatus();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 获取状态
#region 获取参数
result = operate.GetParam();
LogHelper.Info(result.GetRData<ParamStructure>().ToJson(true)); //转成JSON.JSON格式化
#endregion 获取参数
}
🔄 MQ应用示例
//MQ协议
//以MQTT为例
using Snet.Log;
using Snet.Model.data;
using Snet.Mqtt.client;
using Snet.Utility;
using (MqttClientOperate operate = new MqttClientOperate(new MqttClientData.Basics
{
Ip = "127.0.0.1",
Port = 11819,
UserName = "user",
Password = "password"
}))
{
#region 打开
OperateResult result = operate.On();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 打开
#region 生产
result = operate.Produce("主题", "内容");
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 生产
#region 消费
//事件信息结果
operate.OnInfoEvent += delegate (object? sender, EventInfoResult e)
{
LogHelper.Info(e.ToJson(true)); //转成JSON.JSON格式化
};
//事件数据结果
operate.OnDataEvent += delegate (object? sender, EventDataResult e)
{
LogHelper.Info(e.ToJson(true)); //转成JSON.JSON格式化
//根据传进的RRT 转发响应类型来判断
switch (basics.RT)
{
case ResponseType.Bytes: //字节数据
byte[] bytes = e.GetRData<byte[]>();
break;
case ResponseType.Content: //字符串数据
string str = e.GetRData<string>();
break;
case ResponseType.ContentWithTopic: //带主题与内容的包体数据
ResponseModel rm = e.RData.ToJsonEntity<ResponseModel>();
break;
}
};
result = operate.Consume("主题");
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 消费
#region 关闭
result = operate.Off();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 关闭
#region 获取状态
result = operate.GetStatus();
LogHelper.Info(result.ToJson(true)); //转成JSON.JSON格式化
#endregion 获取状态
#region 获取参数
result = operate.GetParam();
LogHelper.Info(result.GetRData<ParamStructure>().ToJson(true)); //转成JSON.JSON格式化
#endregion 获取参数
}
⚙️ 常用操作类名
SerialOperate // 串口通信
HttpClientOperate // HTTP 客户端
HttpServiceOperate // HTTP 服务端
TcpClientOperate // TCP 客户端
TcpServiceOperate // TCP 服务端
UdpOperate // UDP 通信
WsClientOperate // WebSocket 客户端
WsServiceOperate // WebSocket 服务端
ProcessCacheOperate // 内存缓存
ShareCacheOperate // 共享缓存
MqOperate // 消息队列
ReflectionOperate // 反射操作
📦 快速开始
- 打开 NuGet 搜索并安装对应协议包
- 引入命名空间
using Snet.XXX
- 按照上方示例编写采集/转发代码
🏗️ 架构总结
Snet 框架通过 统一接口设计 与 模块化协议支持,实现了:
- 数据采集
- 协议转发
- 消息中间件交互
- 模拟服务端测试
- 高效日志与缓存
从 设备 → 协议 → 中间件 → 应用层 全链路打通,支持快速构建工业物联网系统。
📜 许可证
本项目基于 MIT 开源。
请阅读 LICENSE 获取完整条款。
⚠️ 软件按 “原样” 提供,作者不对使用后果承担责任。
🌍 查阅
👉 点击跳转
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 was computed. 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.
-
net8.0
- Snet.Core (>= 25.271.1)
- Snet.Driver (>= 25.271.1)
-
net9.0
- Snet.Core (>= 25.271.1)
- Snet.Driver (>= 25.271.1)
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 |
---|---|---|
25.271.1 | 18 | 9/27/2025 |
25.267.1 | 232 | 9/24/2025 |
25.262.1 | 366 | 9/19/2025 |
25.259.1 | 361 | 9/16/2025 |
25.253.2 | 194 | 9/10/2025 |
25.253.1 | 182 | 9/10/2025 |
25.252.1 | 184 | 9/9/2025 |
25.247.1 | 212 | 9/4/2025 |
25.246.1 | 205 | 9/3/2025 |
25.245.1 | 183 | 9/2/2025 |
25.244.1 | 187 | 9/1/2025 |
25.240.1 | 249 | 8/28/2025 |
25.239.1 | 233 | 8/27/2025 |
25.238.1 | 247 | 8/26/2025 |
25.234.1 | 156 | 8/22/2025 |
25.224.1 | 205 | 8/12/2025 |
25.219.1 | 288 | 8/7/2025 |
25.213.1 | 131 | 8/1/2025 |
25.212.1 | 163 | 7/31/2025 |
25.211.1 | 105 | 7/30/2025 |
25.204.4 | 624 | 7/23/2025 |
25.204.3 | 631 | 7/23/2025 |
25.204.2 | 634 | 7/23/2025 |
25.204.1 | 646 | 7/23/2025 |
25.190.1 | 240 | 7/9/2025 |
25.187.1 | 204 | 7/5/2025 |
25.177.2 | 253 | 6/26/2025 |
25.177.1 | 236 | 6/25/2025 |
25.175.1 | 244 | 6/24/2025 |
25.168.1 | 253 | 6/17/2025 |
25.162.1 | 391 | 6/11/2025 |
25.161.1 | 390 | 6/10/2025 |
25.157.2 | 228 | 6/6/2025 |
25.157.1 | 260 | 6/6/2025 |
25.156.1 | 240 | 6/5/2025 |
25.155.1 | 270 | 6/4/2025 |
25.136.1 | 333 | 5/16/2025 |
25.132.1 | 316 | 5/12/2025 |
25.129.1 | 223 | 5/9/2025 |
25.128.1 | 265 | 5/8/2025 |
25.127.1 | 255 | 5/7/2025 |
25.118.1 | 297 | 4/28/2025 |
25.112.1 | 276 | 4/22/2025 |
25.107.1 | 322 | 4/17/2025 |
25.106.1 | 306 | 4/16/2025 |
25.105.1 | 320 | 4/15/2025 |
25.104.1 | 329 | 4/14/2025 |
25.100.1 | 302 | 4/10/2025 |
25.99.1 | 294 | 4/9/2025 |
25.88.2 | 225 | 3/29/2025 |
25.88.1 | 229 | 3/29/2025 |
25.87.1 | 247 | 3/28/2025 |
25.86.3 | 257 | 3/27/2025 |
25.86.2 | 250 | 3/27/2025 |
25.86.1 | 259 | 3/27/2025 |
25.79.1 | 270 | 3/20/2025 |
25.77.1 | 280 | 3/18/2025 |
25.76.1 | 277 | 3/17/2025 |
25.71.1 | 278 | 3/12/2025 |
25.69.2 | 278 | 3/10/2025 |
25.69.1 | 265 | 3/10/2025 |
25.68.1 | 266 | 3/9/2025 |
25.65.1 | 250 | 3/6/2025 |
25.63.3 | 249 | 3/4/2025 |
25.63.2 | 244 | 3/4/2025 |
25.63.1 | 235 | 3/4/2025 |
25.62.1 | 192 | 3/3/2025 |
25.59.1 | 154 | 2/28/2025 |
25.44.1 | 148 | 2/13/2025 |
25.43.1 | 138 | 2/12/2025 |
25.35.1 | 153 | 2/4/2025 |
25.2.3 | 151 | 1/1/2025 |
25.2.2 | 145 | 1/1/2025 |
25.2.1 | 148 | 1/1/2025 |
24.365.6485 | 134 | 12/29/2024 |
24.365.3593 | 131 | 12/29/2024 |
24.363.11982 | 132 | 12/27/2024 |