QLProtocolLibrary 0.4.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package QLProtocolLibrary --version 0.4.0
NuGet\Install-Package QLProtocolLibrary -Version 0.4.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="QLProtocolLibrary" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QLProtocolLibrary" Version="0.4.0" />
<PackageReference Include="QLProtocolLibrary" />
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 QLProtocolLibrary --version 0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QLProtocolLibrary, 0.4.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 QLProtocolLibrary@0.4.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=QLProtocolLibrary&version=0.4.0
#tool nuget:?package=QLProtocolLibrary&version=0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
QLProtocolLibrary
中文 | English
QLProtocolLibrary 是面向主应用层协议报文的 C# 类库。
这个包默认处理的是主协议裸报文:
设备地址(4) + 功能码(1) + 功能数据(N) + CRC16(2)
同时支持文档中的可选包络:
C6 F4 C2 CC + 长度(2) + 裸报文 + 0D 0A
适合什么场景
- 上位机直接发送/接收协议报文
- 设备调试工具
- 协议解析库封装
- 外部项目通过 NuGet 复用协议能力
安装
dotnet add package QLProtocolLibrary
最短示例
using QLProtocolLibrary;
uint deviceAddress = 0x10000001;
byte[] command = QlProtocolCommandBuilder.BuildRead(deviceAddress, 0x0000, 0x0001);
Console.WriteLine(QlHexConverter.ToHexString(command));
// 10 00 00 01 03 00 00 00 01 43 21
解析示例
using QLProtocolLibrary;
byte[] responseBytes =
{
0x10, 0x00, 0x00, 0x01,
0x03,
0x00, 0x00,
0x04,
0x1C, 0x04, 0x1F, 0x41,
0x97, 0xE9
};
QlProtocolFrame frame = QlProtocolParser.Parse(responseBytes);
Console.WriteLine(frame.DeviceAddressHex);
Console.WriteLine(frame.ReadSingle()); // 9.9385
真实串口/485/TCP 接收场景里,建议直接把收到的原始 byte[] 传给 QlProtocolParser.Parse(...)。
ParseHex(...) 更适合调试和测试。
关键 API
组包
QlProtocolCommandBuilder.BuildRead(...)QlProtocolCommandBuilder.BuildWrite(...)QlProtocolCommandBuilder.BuildWriteRegisters(...)QlProtocolCommandBuilder.BuildWriteFloat(...)QlProtocolCommandBuilder.BuildPacket(...)
解包
QlProtocolParser.Parse(...)QlProtocolParser.ParseHex(...)QlProtocolParser.TryParse(...)
类型读取
frame.ReadUInt16()frame.ReadUInt32()frame.ReadSingle()frame.ReadUtf8()frame.ReadBcdDateTime()
高层已知寄存器 API
QlProtocolKnownCommandsQlProtocolKnownParsersQlKnownOperationsQlProtocolKnownRouter
使用时要注意
- 设备地址固定 4 字节
- CRC16 发送顺序为低字节在前
- 1 个寄存器按文档为 4 字节
- 协议字段和数据值的字节序不能混为一谈
- 不同功能码、不同数据类型的数据区定义不同,必须以文档对应章节为准
相关文档
- 仓库首页 README:
README.md - 中文 API:
docs/API.zh-CN.md - English API:
docs/API.en.md - 示例:
examples/QLProtocolLibrary.Demo
| 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 was computed. 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 was computed. 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.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See CHANGELOG.md in the GitHub repository for version details. Version 0.4.0 aligns the core packet model with the main application-layer structure based on device address, function code, payload, and CRC16, and updates the public docs and demos accordingly.