CSoft.CommTask
11.0.1
See the version list below for details.
dotnet add package CSoft.CommTask --version 11.0.1
NuGet\Install-Package CSoft.CommTask -Version 11.0.1
<PackageReference Include="CSoft.CommTask" Version="11.0.1" />
<PackageVersion Include="CSoft.CommTask" Version="11.0.1" />
<PackageReference Include="CSoft.CommTask" />
paket add CSoft.CommTask --version 11.0.1
#r "nuget: CSoft.CommTask, 11.0.1"
#:package CSoft.CommTask@11.0.1
#addin nuget:?package=CSoft.CommTask&version=11.0.1
#tool nuget:?package=CSoft.CommTask&version=11.0.1
CSoft.CommTask
为自定义通信层提供请求队列、发送调度、响应匹配和超时管理。通过传输适配接口接入已有的串口、TCP、UDP 或测试传输。需要把物理口与分帧器组装成通信端口时,可使用 CSoft.TopPortLib。
安装
dotnet add package CSoft.CommTask --version 11.0.1
提供 .NET 8、9、10、11 专用目标,另通过 .NET Standard 2.0 兼容 .NET Framework 4.8。
选择队列
| 队列 | 传输适配接口 | 适用场景 |
|---|---|---|
CrowLayer<TReq, TRsp> |
ITilesLayer<TReq, TRsp> |
串行处理请求,一次等待一个响应。适合设备轮询和主从协议。 |
PigeonLayer |
IPigeonTilesLayer |
双工请求与主动推送。按响应类型和匹配字节关联请求,服务端还按客户端区分。 |
SparrowLayer |
ISparrowTilesLayer |
多对端请求与主动推送,按客户端标识区分请求。适合 UDP 多对多通信。 |
Pigeon 和 Sparrow 的解析委托把传入字节转换为 ParsedResponse。响应类型和匹配字节应与发送请求时提供的匹配规则对应。
Crow 内存回环
下面的控制台示例使用传输适配器即时返回响应,可以直接运行并输出 42。
using System;
using System.Threading.Tasks;
using CommTask;
using CommTask.Interfaces;
await using var queue = new CrowLayer<int, int>(new LoopbackTiles(), timeDelayAfterSending: 0);
await queue.StartAsync();
Console.WriteLine(await queue.RequestAsync(41, timeout: 1000));
sealed class LoopbackTiles : ITilesLayer<int, int>
{
public event Action<int> OnReceiveData = delegate { };
public Task SendAsync(int data, int timeDelayAfterSending)
{
OnReceiveData(data + 1);
return Task.Delay(timeDelayAfterSending);
}
}
RequestAsync 发送请求并等待响应,SendAsync 仅排队发送。Crow 在底层发送和 OnSentData 回调返回后开始计算响应超时。StopAsync 会等待当前底层发送和事件回调结束,已收到的响应可以正常交付,排队和等待入队的请求以 CrowStopWorkingException 结束。关闭完成后可通过 StartAsync 启动新队列。
仓库的 TestDemo/TopPortLib.Tests/CrowLayerShutdownTests.cs 包含关闭与重启测试。
| 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. |
-
.NETStandard 2.0
- CSoft.LogInterface (>= 11.0.0)
- CSoft.Utils (>= 11.0.1)
- System.Threading.Channels (>= 11.0.0)
-
net10.0
- CSoft.LogInterface (>= 11.0.0)
- CSoft.Utils (>= 11.0.1)
-
net11.0
- CSoft.LogInterface (>= 11.0.0)
- CSoft.Utils (>= 11.0.1)
-
net8.0
- CSoft.LogInterface (>= 11.0.0)
- CSoft.Utils (>= 11.0.1)
-
net9.0
- CSoft.LogInterface (>= 11.0.0)
- CSoft.Utils (>= 11.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CSoft.CommTask:
| Package | Downloads |
|---|---|
|
CSoft.TopPortLib
通信口使用类库 |
GitHub repositories
This package is not used by any popular GitHub repositories.
同步至 11.0.1,继续提供 .NET 8、9、10、11 和 .NET Standard 2.0 目标。
Crow 停止时释放待发送请求及等待入队的任务,保留已经收到的响应。