CSoft.TopPortLib 11.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSoft.TopPortLib --version 11.0.0
                    
NuGet\Install-Package CSoft.TopPortLib -Version 11.0.0
                    
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="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.TopPortLib" Version="11.0.0" />
                    
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 11.0.0
                    
#r "nuget: CSoft.TopPortLib, 11.0.0"
                    
#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 CSoft.TopPortLib@11.0.0
                    
#: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=CSoft.TopPortLib&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CSoft.TopPortLib&version=11.0.0
                    
Install as a Cake Tool

CSoft.TopPortLib

把物理通信口与分帧器组装成应用可直接使用的端口。端口提供收发事件和连接生命周期,并可按场景选用 Crow、Pigeon 或 Sparrow 请求队列。

安装

dotnet add package CSoft.TopPortLib --version 11.0.0

提供 .NET 8、9、10、11 专用目标,另通过 .NET Standard 2.0 兼容 .NET Framework 4.8。

选择端口

端口 适用场景
TopPort 点对点分帧收发,例如串口、TCP 客户端和命名管道客户端。
TopPort_Server、TopPort_M2M 直接与多个对端收发,例如 TCP 服务端和 UDP 多对多。
CrowPort、CrowPort_Server 串行请求响应。服务端版本绑定一个客户端。
PigeonPort、PigeonPort_Server 双工请求响应和设备主动推送。
SparrowPort 按客户端标识发起 UDP 多对多请求,接收响应或主动推送。

TCP 分帧收发

在 .NET 8 至 11 的控制台应用中运行以下示例。启动一个监听 127.0.0.1:2756 的 TCP 服务,收到 PING\r 后返回以 \r 结尾的应答。FootParser 会在收到终止字节后交付完整帧。

using System;
using System.Text;
using System.Threading.Tasks;
using Communication.Bus.PhysicalPort;
using Parser.Parsers;
using TopPortLib;

await using var port = new TopPort(
    new TcpClient("127.0.0.1", 2756),
    new FootParser(new byte[] { 0x0D }));

var response = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
port.OnReceiveParsedData += frame =>
{
    response.TrySetResult(frame);
    return Task.CompletedTask;
};

await port.OpenAsync();
await port.SendAsync(Encoding.ASCII.GetBytes("PING\r"));
var received = await response.Task.WaitAsync(TimeSpan.FromSeconds(2));
Console.WriteLine(Encoding.ASCII.GetString(received).TrimEnd('\r'));

自动生成协议接口

源码生成器随 CSoft.TopPortLib 自动加载,需要 Roslyn 4.8 或更高版本。使用生成的协议 Builder 时,同时引用 CSoft.Protocol 11.0.0。

  1. 在 partial 协议类上标记 [AutoCrowPortBuilder]、[AutoPigeonPortBuilder] 或 [AutoSparrowPortBuilder],提供 public static IParser CreateParser()。
  2. 为业务命令定义同一前缀的 XxxReq 和 XxxRsp。Crow 请求实现 IByteStream,响应提供 Result 属性。Pigeon 和 Sparrow 的请求实现 IAsyncRequest,其响应实现 IAsyncResponse<T>。
  3. 在应用中调用生成的 Builder 和业务方法。带 [ActivelyPushResponse] 的 Pigeon 或 Sparrow 响应可生成主动推送事件。

Crow 协议示例 · Pigeon 协议示例 · Sparrow 协议示例

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 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.  net11.0 is compatible. 
.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 (4)

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

Package Downloads
CSoft.Communication.Bluetooth

Package Description

CSoft.Communication.Builder

通信库 Fluent Builder API - 简化通信口创建

CSoft.Communication.BLE

Package Description

CSoft.MAUI.FT231X

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.3 570 11/13/2026
11.0.2 242 11/13/2026
11.0.1 299 11/12/2026
11.0.0 222 11/12/2026
10.6.2 2,018 5/28/2026
10.6.1 324 5/28/2026
10.6.0 468 5/27/2026
10.5.1 391 5/25/2026
10.5.0 418 5/25/2026
10.4.10 526 5/19/2026
10.4.9 412 5/19/2026
10.4.8 277 5/18/2026
10.4.7 286 5/18/2026
10.4.6 327 5/15/2026
10.4.5 331 5/14/2026
10.4.3 286 5/14/2026
10.4.1 369 5/11/2026
10.4.0 296 5/11/2026 10.4.0 is deprecated because it has critical bugs.
10.3.1 280 5/7/2026
10.3.0 322 5/7/2026
Loading failed

升级至 11.0.0,新增 .NET 8、9 和 11 目标,继续提供 .NET Standard 2.0 和 .NET 10。
同步 Communication、Parser 和 CommTask 的传输、分帧及 Crow 队列改进。