packServer/desktop/Services/Scan/ScannerCommands.cs

52 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
namespace YuncangTrace.LocalService.Services.Scan;
/// <summary>
/// 扫码枪的设置指令(照搬 AndroidScanCenter 的 <c>ScannerCommands</c>,来源:设备商
/// 《网口配置-文档介绍-V4.0》第 14 页「串口指令表」)。
///
/// ⚠️ 这些指令发给的是**扫码枪**,不是网口设备:我们通过已有的 TCP 连接写进去,
/// 设备按 `Rout=uart` 透传到串口。
///
/// ⚠️ 静音那两条是 **10 字节**(其余 9 字节),**不要**按 9 字节去"凑"长度,
/// 校验位也照抄,改错了设备会静默丢弃(现象是"发了没反应")。
/// </summary>
public static class ScannerCommands
{
/// <summary>触发模式 → 连续扫描:扫码枪自己一直扫,不用主机触发</summary>
public static readonly byte[] TriggerContinuous =
{ 0x07, 0xC6, 0x04, 0x08, 0x00, 0x8A, 0x04, 0xFE, 0x99 };
/// <summary>识读间隔 → 0s:连扫时两条之间不等待</summary>
public static readonly byte[] IntervalZero =
{ 0x07, 0xC6, 0x04, 0x08, 0x00, 0x89, 0x00, 0xFE, 0x9E };
/// <summary>
/// 静音 → 使能:扫到码不蜂鸣。
/// 参数是「静音」,0x01 = 使能(安静)、0x00 = 禁止(照旧响)—— 是**反的**。
/// </summary>
public static readonly byte[] MuteOn =
{ 0x08, 0xC6, 0x04, 0x08, 0x00, 0xF2, 0x0C, 0x01, 0xFE, 0x27 };
/// <summary>静音 → 禁止:恢复蜂鸣</summary>
public static readonly byte[] MuteOff =
{ 0x08, 0xC6, 0x04, 0x08, 0x00, 0xF2, 0x0C, 0x00, 0xFE, 0x28 };
/// <summary>
/// 连上之后按顺序下发的设置(9 + 9 + 10 = 28 字节,一次写完)。
///
/// 为什么放在"连上时"而不是做成一个按钮:这些是**扫码枪**的状态,
/// 枪自己断电重启就丢了;而连接每重建一次都会走这里,等于自动兜住。
/// 静音取**通道记住的值**(不是固定值),否则每次重连都会把人的设置覆盖掉
/// —— 现场看到的现象就是"设了过一会儿自己又响了"。
/// </summary>
public static IReadOnlyList<byte[]> StartupSequence(bool muted) => new[]
{
TriggerContinuous,
IntervalZero,
muted ? MuteOn : MuteOff,
};
}