From 0fea65018b27c88633ba0b6712815d555e3d4835 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Mon, 21 Sep 2026 17:18:02 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20Pavo=20=E6=9E=9A=E4=B8=BE=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E5=8A=A0=20[pavo-diag]=20=E8=AF=8A=E6=96=AD=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=88Windows=20=E6=9E=9A=E4=B8=BE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户 Windows 实测:驱动装好后(cs2xxhcd.inf 入库、安装器触发过真实打印、 打印机本体正常——同一台机器 mac 全通)枚举反而返回空("打印机未连接"), 且装驱动前能枚举到(status=0x80)——枚举走的设备通道在驱动绑定前后变化。 对枚举内部加 stdout 诊断:两段式返回码、原始缓冲前 96 字节 hex、 解码与拆分结果(flutter run 控制台可见),下次运行即可区分 "DLL 层失败(ret/size)"还是"解码拆分层问题"。 --- lib/print/pavo/pavo_printer.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/print/pavo/pavo_printer.dart b/lib/print/pavo/pavo_printer.dart index cc3e096..a15ea17 100644 --- a/lib/print/pavo/pavo_printer.dart +++ b/lib/print/pavo/pavo_printer.dart @@ -8,6 +8,9 @@ import 'package:ffi/ffi.dart'; import '../../image/card_image.dart'; import 'pavo_ffi.dart'; +// Windows 枚举/直打链路的 [pavo-diag] 诊断日志(stdout,flutter run 控制台可见) +// ignore_for_file: avoid_print + /// 携带 HiTi 状态码的打印异常(错误码进任务 status,文案进 statusText)。 class HitiException implements Exception { HitiException(this.statusCode, this.message); @@ -26,10 +29,14 @@ class HitiException implements Exception { /// 全部为同步 ffi 调用,必须在独立 isolate 中运行(见 PavoPrintBackend)。 class PavoPrinter { /// 枚举 USB 连接的证卡打印机名。SDK 缓冲可能是 UTF-8 或 UTF-16,两种都尝试解析。 + /// + /// 含 [pavo-diag] 诊断日志(stdout):Windows 枚举问题排查用, + /// 输出两段式返回码/原始缓冲 hex/解码与拆分结果,flutter run 控制台可见。 static List enumUsbPrinters(PavoApi api) { final sizePtr = calloc(); try { var ret = api.enumUsbCardPrinters(nullptr, sizePtr); + print('[pavo-diag] enum#1 ret=0x${ret.toRadixString(16)} size=${sizePtr.value}'); if (ret != 0 || sizePtr.value == 0) { return const []; } @@ -38,14 +45,23 @@ class PavoPrinter { final size = sizePtr.value; sizePtr.value = size; ret = api.enumUsbCardPrinters(buf, sizePtr); + final bytes = buf.asTypedList(size); + final hex = bytes + .take(96) + .map((b) => b.toRadixString(16).padLeft(2, '0')) + .join(' '); + print('[pavo-diag] enum#2 ret=0x${ret.toRadixString(16)} size=$size raw[$hex]'); if (ret != 0) { return const []; } - return decodeAuto(buf.asTypedList(size)) + final decoded = decodeAuto(bytes); + final list = decoded .split(RegExp('[\x00\n\r,]')) .map((s) => s.trim()) .where((s) => s.isNotEmpty) .toList(); + print('[pavo-diag] decoded="$decoded" => $list'); + return list; } finally { calloc.free(buf); }