Snet.Core 25.271.1

dotnet add package Snet.Core --version 25.271.1
                    
NuGet\Install-Package Snet.Core -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.Core" Version="25.271.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Snet.Core" Version="25.271.1" />
                    
Directory.Packages.props
<PackageReference Include="Snet.Core" />
                    
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 Snet.Core --version 25.271.1
                    
#r "nuget: Snet.Core, 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.Core@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.Core&version=25.271.1
                    
Install as a Cake Addin
#tool nuget:?package=Snet.Core&version=25.271.1
                    
Install as a Cake Tool

<img src="https://api.shunnet.top/pic/nuget.png" height="32"> Snet - 工业协议与数据采集框架

🚀 统一 · 高效 · 灵活 · 可扩展
面向工业数据采集、传输、转发、消息中间件的全栈式解决方案

✨ 框架特色

  1. ✅ 所有协议公共函数 支持同步 / 异步
  2. ✅ 协议 读写参数统一,入参出参统一
  3. 支持多点转发 / 多点解析
  4. 快速对接与配置,可即插即用
  5. 支持虚拟点位(模拟测试更便捷)
  6. ✅ 采集协议全面支持 订阅模式
  7. 采集与转发协议接口统一
  8. ✅ 事件结果统一,并支持 异步事件
  9. ✅ 所有采集协议均支持 WebAPI 控制与数据获取
  10. 快捷二次开发,仅需继承接口与抽象类即可
  11. ✅ 拥有详细的日志记录高度自定义日志输出路径与记录到数据库
  12. ✅ 全局支持中英文实时切换
  13. ✅ 支持反射脚本解析进程缓存共享缓存抽象扩展
  14. ✅ 支持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   // 反射操作

📦 快速开始

  1. 打开 NuGet 搜索并安装对应协议包
  2. 引入命名空间 using Snet.XXX
  3. 按照上方示例编写采集/转发代码

🏗️ 架构总结

Snet 框架通过 统一接口设计模块化协议支持,实现了:

  • 数据采集
  • 协议转发
  • 消息中间件交互
  • 模拟服务端测试
  • 高效日志与缓存

设备 → 协议 → 中间件 → 应用层 全链路打通,支持快速构建工业物联网系统。

📜 许可证

License: MIT

本项目基于 MIT 开源。
请阅读 LICENSE 获取完整条款。
⚠️ 软件按 “原样” 提供,作者不对使用后果承担责任。

🌍 查阅

👉 点击跳转

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 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.

NuGet packages (37)

Showing the top 5 NuGet packages that depend on Snet.Core:

Package Downloads
Snet.MegMeet

采集协议:MegMeet(麦格米特 PLC 通信库,支持多型号、多类型读取写入,并支持数据订阅模式)

Snet.Omron

采集协议:Omron(欧姆龙 PLC 通信库,支持多型号、多类型读取写入,并支持数据订阅模式)

Snet.Yokogawa

采集协议:Yokogawa(横河 PLC 通信库,支持多型号、多类型读取写入,并支持数据订阅模式)

Snet.Toyota

采集协议:Toyota(丰田 PLC 通信库,支持多型号、多类型读取写入,并支持数据订阅模式)

Snet.WeCon

采集协议:WeCon(维控 PLC 通信库,支持多型号、多类型读取写入,并支持数据订阅模式)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
25.271.1 1,664 9/27/2025
25.267.1 2,018 9/24/2025
25.253.1 3,731 9/10/2025
25.252.1 1,299 9/9/2025
25.247.1 1,321 9/4/2025
25.246.1 1,300 9/3/2025
25.245.1 1,271 9/2/2025
25.244.1 1,263 9/1/2025
25.240.1 1,296 8/28/2025
25.239.1 1,299 8/27/2025
25.238.1 1,384 8/26/2025
25.234.1 1,261 8/22/2025
25.224.2 1,307 8/12/2025
25.224.1 269 8/12/2025
25.219.2 1,305 8/7/2025
25.219.1 347 8/7/2025
25.213.1 1,253 8/1/2025
25.211.1 1,584 7/30/2025
25.204.4 1,655 7/23/2025
25.204.3 1,663 7/23/2025
25.204.2 1,697 7/23/2025
25.204.1 1,747 7/23/2025
25.190.2 1,937 7/9/2025
25.190.1 338 7/9/2025
25.187.1 1,750 7/5/2025
25.177.1 1,874 6/26/2025
25.176.1 1,762 6/25/2025
25.175.1 1,779 6/24/2025
25.168.1 1,846 6/17/2025
25.162.1 1,954 6/11/2025
25.161.1 1,923 6/10/2025
25.157.2 1,766 6/6/2025
25.157.1 1,764 6/6/2025
25.156.1 1,784 6/5/2025
25.155.1 1,831 6/4/2025
25.136.1 1,966 5/16/2025
25.132.1 1,816 5/12/2025
25.129.1 1,804 5/9/2025
25.128.1 1,853 5/8/2025
25.127.1 1,799 5/7/2025
25.118.1 1,862 4/28/2025
25.112.2 1,823 4/22/2025
25.112.1 369 4/22/2025
25.107.2 1,946 4/17/2025
25.107.1 377 4/17/2025
25.106.1 1,906 4/16/2025
25.105.1 1,886 4/15/2025
25.104.1 1,881 4/14/2025
25.100.1 1,834 4/10/2025
25.99.1 1,819 4/9/2025
25.88.4 1,765 3/29/2025
25.88.3 1,773 3/29/2025
25.88.2 297 3/29/2025
25.88.1 315 3/29/2025
25.87.1 1,716 3/28/2025
25.86.4 1,788 3/27/2025
25.86.3 1,826 3/27/2025
25.86.2 353 3/27/2025
25.86.1 1,836 3/27/2025
25.77.1 2,882 3/18/2025
25.76.2 1,828 3/17/2025
25.76.1 359 3/17/2025
25.71.1 1,819 3/12/2025
25.69.4 1,848 3/10/2025
25.69.3 377 3/10/2025
25.69.2 385 3/10/2025
25.69.1 1,827 3/10/2025
25.68.1 1,803 3/9/2025
25.65.3 648 3/6/2025
25.65.2 254 3/6/2025
25.65.1 266 3/6/2025
25.63.3 669 3/4/2025
25.63.2 645 3/4/2025
25.63.1 661 3/4/2025
25.62.1 554 3/3/2025
25.44.1 1,037 2/13/2025
25.43.1 557 2/12/2025
25.35.1 510 2/4/2025
25.2.3 937 1/1/2025
25.2.2 854 1/1/2025
25.2.1 881 1/1/2025
24.365.5941 866 12/29/2024
24.365.3233 859 12/29/2024
24.362.61548 867 12/27/2024
24.362.55360 147 12/27/2024