QLProtocolLibrary 0.5.0
dotnet add package QLProtocolLibrary --version 0.5.0
NuGet\Install-Package QLProtocolLibrary -Version 0.5.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.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QLProtocolLibrary" Version="0.5.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.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QLProtocolLibrary, 0.5.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.5.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.5.0
#tool nuget:?package=QLProtocolLibrary&version=0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
QLProtocolLibrary
中文 | English
QLProtocolLibrary 是一个面向 QL 设备主应用层协议报文的 C# NuGet 包。
默认处理的主报文格式为:
设备地址(4) + 功能码(1) + 功能数据(N) + CRC16(2)
同时支持文档中的可选包络:
C6 F4 C2 CC + 长度(2) + 裸报文 + 0D 0A
安装
dotnet add package QLProtocolLibrary
最短示例
using QLProtocolLibrary;
uint deviceAddress = 0x10000001;
byte[] requestBytes = QlProtocolCommandBuilder.BuildRead(deviceAddress, 0x0000, 0x0001);
Console.WriteLine(QlHexConverter.ToHexString(requestBytes));
// 10 00 00 01 03 00 00 00 01 43 21
0x32 指令转发
从 0.5.0 开始,库提供了专用的 0x32 构包与解析辅助方法。
报文结构:
设备地址(4) + 0x32(1) + 数据长度(2) + 端口ID(1) + 转发内容(N) + CRC16(2)
示例:
using QLProtocolLibrary;
byte[] forwardedCommand = QlHexConverter.FromHexString(
"10 00 00 01 06 00 16 00 01 04 01 00 00 00 2E F9");
byte[] forwardFrame = QlProtocolCommandBuilder.BuildForward(
0x1000000F,
0x01,
forwardedCommand);
QlProtocolFrame frame = QlProtocolParser.Parse(forwardFrame);
Console.WriteLine(frame.ReadForwardPortId()); // 1
Console.WriteLine(QlHexConverter.ToHexString(frame.ReadForwardContent()));
常用 API
构包
QlProtocolCommandBuilder.BuildRead(...)QlProtocolCommandBuilder.BuildWrite(...)QlProtocolCommandBuilder.BuildWriteRegisters(...)QlProtocolCommandBuilder.BuildWriteFloat(...)QlProtocolCommandBuilder.BuildForward(...)QlProtocolCommandBuilder.BuildPacket(...)
解包
QlProtocolParser.Parse(...)QlProtocolParser.ParseHex(...)QlProtocolParser.TryParse(...)
payload 读取
frame.ReadUInt16()frame.ReadUInt32()frame.ReadSingle()frame.ReadUtf8()frame.ReadBcdDateTime()frame.ReadForwardPortId()frame.ReadForwardContent()
使用注意事项
- 设备地址固定 4 字节
- CRC16 按低字节在前发送
- 1 个寄存器按文档为 4 字节
- 协议控制字段与 payload 数据值字段的字节序不能混为一谈
0x32的数据长度 =端口ID + 转发内容的总字节数
相关文档
- 仓库首页 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.5.0 adds dedicated 0x32 command-forwarding helpers including BuildForward(...), BuildForwardHex(...), ReadForwardPortId(), and ReadForwardContent(), and refreshes the public docs for the release.