CSoft.Communication.Builder
11.0.3
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package CSoft.Communication.Builder --version 11.0.3
NuGet\Install-Package CSoft.Communication.Builder -Version 11.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="CSoft.Communication.Builder" Version="11.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.Communication.Builder" Version="11.0.3" />
<PackageReference Include="CSoft.Communication.Builder" />
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.Communication.Builder --version 11.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CSoft.Communication.Builder, 11.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.
#:package CSoft.Communication.Builder@11.0.3
#: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.Communication.Builder&version=11.0.3
#tool nuget:?package=CSoft.Communication.Builder&version=11.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CSoft.Communication.Builder
使用链式 API 组合物理口、分包器、回调和请求队列。CommBuilder.Comm 根据通讯模式返回不同的构建步骤,Build() 返回相应的 TopPortLib 接口。应用负责打开和关闭已构建的通讯口。
安装
dotnet add package CSoft.Communication.Builder --version 11.0.3
包提供 netstandard2.0、net8.0、net9.0、net10.0 和 net11.0 资产。.NET Framework 4.8 可使用 netstandard2.0 资产。
选择入口
| 入口 | 用途 | 构建结果 | 启停 |
|---|---|---|---|
Comm.Top() |
串口、TCP 客户端或命名管道直接收发 | ITopPort |
OpenAsync / CloseAsync |
Comm.TopServer() |
TCP 服务端直接收发,按客户端 ID 回复 | ITopPort_Server |
OpenAsync / CloseAsync |
Comm.TopM2M() |
UDP 多对多直接收发 | ITopPort_M2M |
OpenAsync / CloseAsync |
Comm.Crow() |
串行请求–响应,适合主从轮询 | ICrowPort |
OpenAsync / CloseAsync |
Comm.Pigeon() |
全双工请求–响应与主动推送,可绑定 TCP 服务端的一个客户端 | IPigeonPort |
StartAsync / StopAsync |
Comm.Sparrow() |
按远端管理请求与推送的 UDP 多对多队列 | ISparrowPort |
StartAsync / StopAsync |
TCP 回环示例
在 .NET 8 或更高版本的控制台项目中运行。示例使用本机端口 27560,如已被占用,请同时修改客户端和服务端的端口。
using System;
using System.Threading.Tasks;
using CommBuilder;
const int portNumber = 27560;
byte[] head = [0xAA];
byte[] foot = [0x55];
using var server = Comm.TopServer()
.UseTcpServer("127.0.0.1", portNumber)
.WithHeadFootParser(head, foot)
.Build();
server.OnReceiveParsedData += (clientId, frame) => server.SendAsync(clientId, frame);
var reply = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
using var client = Comm.Top()
.FromConnectionString($"tcp://127.0.0.1:{portNumber}")
.WithHeadFootParser(head, foot)
.OnReceived(frame => { reply.TrySetResult(frame); })
.Build();
await server.OpenAsync();
try
{
await client.OpenAsync();
try
{
await client.SendAsync([0xAA, 0x01, 0x55]);
var frame = await reply.Task.WaitAsync(TimeSpan.FromSeconds(3));
Console.WriteLine(Convert.ToHexString(frame)); // AA0155
}
finally
{
await client.CloseAsync();
}
}
finally
{
await server.CloseAsync();
}
配置要点
FromConnectionString可在Top、Crow和Pigeon上使用。常用格式为serial://COM3:9600、tcp://127.0.0.1:27560、pipe://MyPipe。需要自定义校验位、数据位或停止位时,使用UseSerial的类型化参数。WithHeadFootParser、WithHeadLengthParser、WithFootParser、WithTimeParser和WithNoParser可直接选择分包策略。使用WithHeadLengthParser时,长度回调返回包含帧头的完整帧长,单位为字节。- 在多客户端场景使用自定义有状态解析器时,优先用
WithParserFactory创建独立实例,例如.WithParserFactory(MyProtocol.CreateParser)。WithParser(parser)传入的是现有实例。 Timeout(ms)配置队列请求的默认超时。Crow 与 Pigeon 还可用SendInterval(ms)配置发送间隔。TCP 服务端队列需要选择具体连接时,可用BindClient(Guid)。Pigeon 和 Sparrow 的WithCheck可注册接收数据校验。
项目中的 TestDemo/CommBuilderDemo 展示了各入口的组合方式。设备报文格式、校验规则和业务命令由调用方实现。
| Product | Versions 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.
-
.NETStandard 2.0
- CSoft.TopPortLib (>= 11.0.3)
-
net10.0
- CSoft.TopPortLib (>= 11.0.3)
-
net11.0
- CSoft.TopPortLib (>= 11.0.3)
-
net8.0
- CSoft.TopPortLib (>= 11.0.3)
-
net9.0
- CSoft.TopPortLib (>= 11.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CSoft.Communication.Builder:
| Package | Downloads |
|---|---|
|
CSoft.Protocol.ProtocolInterface
协议接口 |
|
|
CSoft.Protocol
协议接口 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 11.0.3 | 65 | 11/13/2026 | |
| 11.0.2 | 57 | 11/13/2026 | |
| 11.0.1 | 67 | 11/12/2026 | |
| 11.0.0 | 51 | 11/12/2026 | |
| 10.6.2 | 1,872 | 5/28/2026 | |
| 10.6.1 | 169 | 5/28/2026 | |
| 10.6.0 | 333 | 5/27/2026 | |
| 10.5.1 | 284 | 5/25/2026 | |
| 10.5.0 | 258 | 5/25/2026 | |
| 10.4.10 | 271 | 5/19/2026 | |
| 10.4.9 | 258 | 5/19/2026 | |
| 10.4.8 | 172 | 5/18/2026 | |
| 10.4.7 | 169 | 5/18/2026 | |
| 10.4.6 | 215 | 5/15/2026 | |
| 10.4.5 | 211 | 5/14/2026 | |
| 10.4.3 | 168 | 5/14/2026 | |
| 10.4.1 | 271 | 5/11/2026 | |
| 10.4.0 | 181 | 5/11/2026 | |
| 10.3.1 | 170 | 5/7/2026 | |
| 10.3.0 | 210 | 5/7/2026 |
Loading failed
依赖 CSoft.TopPortLib 11.0.3,自动带入新版 Pigeon 和底层通信修复。