chore: Pavo 枚举链路加 [pavo-diag] 诊断日志(Windows 枚举空问题定位)
用户 Windows 实测:驱动装好后(cs2xxhcd.inf 入库、安装器触发过真实打印、 打印机本体正常——同一台机器 mac 全通)枚举反而返回空("打印机未连接"), 且装驱动前能枚举到(status=0x80)——枚举走的设备通道在驱动绑定前后变化。 对枚举内部加 stdout 诊断:两段式返回码、原始缓冲前 96 字节 hex、 解码与拆分结果(flutter run 控制台可见),下次运行即可区分 "DLL 层失败(ret/size)"还是"解码拆分层问题"。
This commit is contained in:
1 parent
d1c34cb833
commit
0fea65018b
1 file changed
+17
-1
@@ -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<String> enumUsbPrinters(PavoApi api) {
|
||||
final sizePtr = calloc<Uint32>();
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user