CSoft.TopPortLib 9.12.2

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

概述

Communication c# 通讯库

专为.NET环境设计的高性能、灵活且高度可扩展的通讯库。支持多种通讯口协议、分包方式和自动重连机制,能有效降低通讯代码开发成本,帮助开发者将更多精力投入业务逻辑实现。


🚀 为什么选择 Communication 通讯库

  • 多通讯协议集成:支持串口 (SerialPort)、Tcp Client/Server、UDP、蓝牙、命名管道等多种通讯方式。
  • 分包算法灵活可定制:内置多种主流分包方式,支持头尾、头长、定时分包等,并可通过实现接口自定义协议分包。
  • 同步/异步全支持:异步API设计,不卡UI,适用于复杂人机交互与后台服务场景。
  • 自动重连与通讯队列:强健的网络自动重连机制,内置通讯队列管理,显著提升稳定性。
  • 跨平台广泛兼容:支持 .NET Framework 4.8, .NET Core, .NET 8, .NET 9,易于在各类项目中集成。
  • 低代码、易集成:简明配置,极低上手门槛,开箱即用,即插即扩展。
  • 扩展友好:遵循接口设计,易于扩展通讯协议与处理流程。

⚡️ 30秒快速体验

以TCP服务器接入为例,轻松几步即可启动一个异步通讯服务器(具体API见后文详解):

using Communication.Bus;
using Communication.Interfaces;

// 1. 创建TcpServer,配置端口
IBusPort tcpServer = new TcpServer("127.0.0.1", 9000);

// 2. 注册事件与回调
tcpServer.OnReceived += (sender, args) => {
    // 处理收到的数据包
};

// 3. 启动服务
tcpServer.StartAsync();

如需接入自定义协议,直接实现 IParser 即可无缝接入分包处理。


📦 安装方式

1. 本地源码集成

提供Nuget包管理发布下载,也可直接下载 GitHub项目 源码或将其作为子模块导入。

NuGet\Install-Package CSoft.TopPortLib -Version 9.12.0

/Communication/TopPortLib/Crow/Parser 等核心目录作为项目引用即可。

2. .NET平台兼容矩阵

  • .NET Framework 4.8
  • .NET Core
  • .NET 8, 9

🛠️ 基础用法

多种通讯接口

1. 串口通讯
using Communication.Bus.PhysicalPort;

var serialPort = new SerialPort("COM1", 9600);
// 配置与启动
serialPort.OpenAsync();
2. TcpClient 通讯
using Communication.Bus.PhysicalPort;

var tcpClient = new TcpClient("127.0.0.1", 9000);
tcpClient.OpenAsync();
3. 命名管道通讯
using Communication.Bus.PhysicalPort;

var pipeClient = new NamedPipeClient("PipeName");
pipeClient.OpenAsync();
4. 蓝牙通讯
using Communication.Bluetooth;

var bluetooth = new BluetoothClassic("设备MAC地址");
bluetooth.ConnectAsync();

分包方式定制

实现 IParser,支持任意自定义协议:

public class MyParser : IParser
{
    public IEnumerable<byte[]> Parse(byte[] buffer)
    {
        // 自定义分包算法...
    }
}

📚 API 参考

主要接口与类

物理通讯口
  • IPhysicalPort:物理口基接口(串口/TCP/蓝牙/命名管道等)
  • SerialPort, TcpClient, NamedPipeClient, BluetoothClassic:各类物理口实现类
  • OpenAsync()/CloseAsync():开启/关闭通讯
  • SendAsync(byte[] data):发送数据
逻辑通讯总线
  • IBusPort:总线抽象层(数据包收发)
  • TcpServer, Udp, NamedPipeServer:各类服务端实现
  • StartAsync()/StopAsync():启动/停止服务
  • OnReceived:数据包接收事件
分包处理
  • IParser:数据包分割接口
  • BaseParser, HeadFootParser, HeadLengthParser, TimeParser:内建协议分割实现
  • 可自定义实现Protocol Parser,提升适用性
异常处理
  • ConnectFailedException, NotConnectedException, SendException(Communication/Exceptions)
  • RequestParameterToBytesFailedException, ResponseCreateFailedException(TopPortLib/Exceptions)
高阶抽象
  • TopPort, CondorPort, CrowPort, PigeonPort(TopPortLib)
    • 针对典型工业设备/协议接入的高阶抽象
    • 提供更丰富的命令控制与响应处理接口

🎯 进阶用法

自定义分包协议接入

只需实现 IParser 接口,即可用自定义协议处理底层字节流。例如:

public class CustomParser : IParser { ... }
ITopPort port = new TopPort(new TcpClient("127.0.0.1", 9000), new CustomParser());

上层协议栈封装

TopPortLib 提供了对工业协议常用模式的抽象,可灵活叠加堆栈组合业务逻辑,如异步M2M、设备逻辑拆分等。

测试示例工程

/TestDemo 下包含众多实际协议、分包和通讯测试用例,例如:

  • TestNamedPipeClient, TcpServer, TestUdp1, CondorPortProtocolDemo 等, 提供从基础通讯到进阶协议解码的全流程样例。

🔧 配置选项

支持自定义通讯参数,如串口波特率、网络端口、协议分包超时时间等,大多通过构造函数或属性设置即可。

var serial = new SerialPort(portName: "COM2", baudRate: 9600, parity: Parity.None);

对于高级需求,参见各类接口提供的扩展属性(详见源码与examples)。


🧩 主要集成与扩展方式

框架支持

  • 原生支持WPF、WinForms、控制台等任何.NET工程类型。
  • 作为通讯层可与业务中间件、工业协议栈、SCADA系统无缝集成。

扩展插件机制

  • 任意新增通讯协议,仅需实现对应接口 (IPhysicalPort, IParser)。
  • 可叠加应用层协议,伴随队列、重连、缓存、事件驱动等机制。

📊 性能与质量

  • 异步架构,高并发友好:所有通讯操作异步实现,不卡UI。
  • 内存优化:分包算法避免无效字节流淤积,内建安全防护。
  • 稳定性保障:自愈通讯机制,断线自动重连,错误有效上报。

🔗 兼容性与升级指南

  • 兼容 .NET Framework 4.8, .NET Core, .NET 8/9,支持绝大多数主流.NET应用环境。
  • 新增协议或通讯方式时,仅需实现标准接口,无需修改核心库。
  • 原有分包/设备逻辑如需迁移,仅需替换配置,无需重构业务代码。

🕹️ 学习与支持

入门建议

  1. 从TestDemo工程实际运行示例开始理解调用方式与数据流转。
  2. 仔细阅读各接口源文件与内建Parser算法实现,理解协议扩展机制。
  3. 如有业务特殊需求,优先选择继承/实现相关接口适配扩展。

社区与维护

  • 源码仓库
  • 欢迎issue/PR,共同维护完善
  • 框架持续维护,适配新协议和.NET新特性

总结

Communication通讯库是.NET下通用高扩展性的通讯中间件,开箱即用,易于扩展,可显著提升上位机通讯开发效率,减少代码出错概率并提升系统健壮性。适合各类工控、物联网、业务信息系统场景。

立即集成,专注业务,高效通讯!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on CSoft.TopPortLib:

Package Downloads
CSoft.Protocol.ProtocolInterface

协议接口

FTIRSpectrometerCore

基于设备私有网络应用层通信协议开发为傅里叶红外光谱产品服务的配套模块库

GalaxySmartDeviceCore

如果银河系有旋律,星星一定是发光的IoT设备。做可信赖的智慧工业物联网的生态型伙伴,听一听宇宙终极乐章。

CSoft.Communication.Bluetooth

Package Description

FTIRSpectrometerBusiness

傅里叶红外光谱商用库是为傅里叶红外光谱产品服务的配套模块,基于设备私有网络应用层通信协议开发。它提供了一组功能强大的接口和工具,方便用户对傅里叶红外光谱产品进行操作和控制,具有高度可定制、高效稳定、易于使用、灵活可扩展等特点。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.12.2 224 6/27/2025
9.12.1 172 6/25/2025
9.12.0 334 6/4/2025
9.11.3 276 5/30/2025 9.11.3 is deprecated because it is no longer maintained.
9.11.2 249 5/27/2025 9.11.2 is deprecated because it is no longer maintained.
9.11.1 327 5/22/2025 9.11.1 is deprecated because it is no longer maintained.
9.11.0 268 5/21/2025 9.11.0 is deprecated because it is no longer maintained.
9.10.2 402 3/20/2025 9.10.2 is deprecated because it is no longer maintained.
9.10.1 307 3/18/2025 9.10.1 is deprecated because it is no longer maintained.
9.10.0 289 3/17/2025 9.10.0 is deprecated because it is no longer maintained.
9.9.2 469 2/19/2025 9.9.2 is deprecated because it is no longer maintained.
9.9.1 221 2/18/2025 9.9.1 is deprecated because it is no longer maintained.
9.9.0 214 2/17/2025 9.9.0 is deprecated because it is no longer maintained.
9.8.1 183 2/14/2025 9.8.1 is deprecated because it is no longer maintained.
9.8.0 185 2/12/2025 9.8.0 is deprecated because it is no longer maintained.
9.7.1 195 2/12/2025 9.7.1 is deprecated because it is no longer maintained.
9.7.0 184 2/12/2025 9.7.0 is deprecated because it is no longer maintained.
9.6.0 178 2/10/2025 9.6.0 is deprecated because it is no longer maintained.
9.5.3 175 2/8/2025 9.5.3 is deprecated because it is no longer maintained.
9.5.2 177 2/8/2025 9.5.2 is deprecated because it is no longer maintained.
9.5.1 271 1/23/2025 9.5.1 is deprecated because it is no longer maintained.
9.5.0 213 1/20/2025 9.5.0 is deprecated because it is no longer maintained.
9.4.1 166 1/20/2025 9.4.1 is deprecated because it is no longer maintained.
9.4.0 240 1/2/2025 9.4.0 is deprecated because it is no longer maintained.
9.3.0 392 12/28/2024 9.3.0 is deprecated because it is no longer maintained.
9.2.0 154 12/28/2024 9.2.0 is deprecated because it is no longer maintained.
9.1.0 509 11/29/2024 9.1.0 is deprecated because it is no longer maintained.
9.0.0 279 11/22/2024 9.0.0 is deprecated because it is no longer maintained.
8.3.1 2,449 9/3/2024
8.3.0 765 6/28/2024
8.2.9 254 6/25/2024 8.2.9 is deprecated because it is no longer maintained.
8.2.8 202 6/21/2024 8.2.8 is deprecated because it is no longer maintained.
8.2.7 417 6/11/2024 8.2.7 is deprecated because it is no longer maintained.
8.2.6 265 6/7/2024 8.2.6 is deprecated because it is no longer maintained.
8.2.5 181 6/6/2024 8.2.5 is deprecated because it is no longer maintained.
8.2.4 172 6/6/2024 8.2.4 is deprecated because it is no longer maintained.
8.2.3 180 6/6/2024 8.2.3 is deprecated because it is no longer maintained.
8.2.2-pre 131 5/31/2024 8.2.2-pre is deprecated because it is no longer maintained.
8.2.1-pre 126 5/30/2024 8.2.1-pre is deprecated because it is no longer maintained.
8.2.0 180 5/30/2024 8.2.0 is deprecated because it is no longer maintained.
8.1.7 226 5/28/2024 8.1.7 is deprecated because it is no longer maintained.
8.1.6 745 4/30/2024 8.1.6 is deprecated because it is no longer maintained.
8.1.5 212 4/29/2024 8.1.5 is deprecated because it is no longer maintained.
8.1.3 356 4/11/2024 8.1.3 is deprecated because it is no longer maintained.
8.1.2 258 4/10/2024 8.1.2 is deprecated because it is no longer maintained.
8.1.1 215 3/22/2024 8.1.1 is deprecated because it is no longer maintained.
8.1.0 272 3/11/2024 8.1.0 is deprecated because it has critical bugs.
8.0.9 251 2/28/2024 8.0.9 is deprecated because it has critical bugs.
8.0.8 223 2/4/2024 8.0.8 is deprecated because it is no longer maintained.
8.0.7 181 2/4/2024 8.0.7 is deprecated because it has critical bugs.
8.0.6 413 12/28/2023 8.0.6 is deprecated because it is no longer maintained.
8.0.5 192 12/28/2023 8.0.5 is deprecated because it is no longer maintained.
8.0.4 253 12/20/2023 8.0.4 is deprecated because it is no longer maintained.
8.0.3 244 12/14/2023 8.0.3 is deprecated because it is no longer maintained.
8.0.2 215 12/12/2023 8.0.2 is deprecated because it has critical bugs.
8.0.1 423 12/4/2023 8.0.1 is deprecated because it is no longer maintained.
8.0.0 473 11/15/2023 8.0.0 is deprecated because it has critical bugs.
7.0.6 360 9/19/2023 7.0.6 is deprecated because it is no longer maintained.
7.0.5 619 8/28/2023 7.0.5 is deprecated because it has critical bugs.
7.0.4 234 8/17/2023 7.0.4 is deprecated because it is no longer maintained.
7.0.3 2,542 2/28/2023 7.0.3 is deprecated because it is no longer maintained.
7.0.2 567 2/27/2023 7.0.2 is deprecated because it is no longer maintained.
7.0.1 2,126 2/13/2023 7.0.1 is deprecated because it is no longer maintained.
7.0.0 2,867 11/9/2022 7.0.0 is deprecated because it is no longer maintained.
6.6.2 538 10/24/2022 6.6.2 is deprecated because it is no longer maintained.
6.6.1 844 10/17/2022 6.6.1 is deprecated because it is no longer maintained.
6.6.0 514 10/17/2022 6.6.0 is deprecated because it is no longer maintained.
6.5.2 545 10/15/2022 6.5.2 is deprecated because it is no longer maintained.
6.5.1 645 10/15/2022 6.5.1 is deprecated because it is no longer maintained.
6.5.0 820 10/14/2022 6.5.0 is deprecated because it is no longer maintained.
6.4.3 529 10/14/2022 6.4.3 is deprecated because it is no longer maintained.
6.4.2 539 10/14/2022 6.4.2 is deprecated because it is no longer maintained.
6.4.1 540 10/13/2022 6.4.1 is deprecated because it has critical bugs.
6.4.0 546 10/13/2022 6.4.0 is deprecated because it is no longer maintained.
6.3.0 552 10/13/2022 6.3.0 is deprecated because it is no longer maintained.
6.2.6 833 9/30/2022 6.2.6 is deprecated because it is no longer maintained.
6.2.5 520 9/30/2022 6.2.5 is deprecated because it is no longer maintained.
6.2.4 707 9/26/2022 6.2.4 is deprecated because it is no longer maintained.
6.2.3 698 9/23/2022 6.2.3 is deprecated because it is no longer maintained.
6.2.2 611 9/23/2022 6.2.2 is deprecated because it has critical bugs.
6.2.1 597 9/22/2022 6.2.1 is deprecated because it is no longer maintained.
6.2.0 1,288 8/19/2022 6.2.0 is deprecated because it is no longer maintained.
6.1.2 594 8/12/2022 6.1.2 is deprecated because it has critical bugs.
6.1.1 589 5/26/2022 6.1.1 is deprecated because it is no longer maintained.
6.0.9 674 5/19/2022 6.0.9 is deprecated because it has critical bugs.
6.0.5 575 5/17/2022 6.0.5 is deprecated because it is no longer maintained.
6.0.4 585 5/13/2022 6.0.4 is deprecated because it is no longer maintained.
6.0.3 618 3/15/2022 6.0.3 is deprecated because it is no longer maintained.
6.0.2 568 3/15/2022 6.0.2 is deprecated because it is no longer maintained.
6.0.1 746 11/9/2021 6.0.1 is deprecated because it is no longer maintained.
5.1.4 606 8/18/2021 5.1.4 is deprecated because it is no longer maintained.
5.1.3 638 7/8/2021 5.1.3 is deprecated because it is no longer maintained.
5.1.2 577 7/8/2021 5.1.2 is deprecated because it has critical bugs.
5.1.1 505 7/8/2021 5.1.1 is deprecated because it has critical bugs.
5.1.0 791 7/7/2021 5.1.0 is deprecated because it has critical bugs.
5.0.9 617 7/7/2021 5.0.9 is deprecated because it has critical bugs.
5.0.8 694 3/11/2021 5.0.8 is deprecated because it is no longer maintained.
5.0.7 689 1/26/2021 5.0.7 is deprecated because it is no longer maintained.
5.0.6 592 1/23/2021 5.0.6 is deprecated because it is no longer maintained.
5.0.5 634 1/22/2021 5.0.5 is deprecated because it is no longer maintained.
5.0.4 631 1/11/2021 5.0.4 is deprecated because it is no longer maintained.
5.0.3 595 1/11/2021 5.0.3 is deprecated because it is no longer maintained.
5.0.2 664 11/18/2020 5.0.2 is deprecated because it is no longer maintained.
5.0.1 775 11/18/2020 5.0.1 is deprecated because it has critical bugs.
1.0.2 666 11/18/2020 1.0.2 is deprecated because it is no longer maintained.
1.0.1 677 10/12/2020 1.0.1 is deprecated because it has critical bugs.
1.0.0 758 6/30/2020 1.0.0 is deprecated because it has critical bugs.

更新依赖