问题描述
我在 Chrome 中使用 WebHID 与支持 USB 的数字秤进行通信。我可以连接到体重秤并订阅重量数据流,如下所示:
// Get a reference to the scale.
// 0x0922 is the vendor of my particular scale (Dymo).
let device = await navigator.hid.requestDevice({filters:[{vendorId: 0x0922}]});
// Open a connection to the scale.
await device[0].open();
// Subscribe to scale data inputs at a regular interval.
device[0].addEventListener("inputreport",event => {
const { data,device,reportId } = event;
let buffArray = new Uint8Array(data.buffer);
console.log(buffArray);
});
我现在接收格式为 Uint8Array(5) [2,12,255,0]
的常规输入,其中第四个位置是重量数据。如果我在秤上放一些东西,它会变成 Uint8Array(5) [2,48,0]
,也就是 4.8 磅。
我想将秤归零(去皮),使其当前的负担状态成为新的零点。成功归零后,我希望秤再次开始返回 Uint8Array(5) [2,0]
。我目前对此的最佳猜测是:
device[0]
.sendReport(0x02,new Uint8Array([0x02]))
.then(response => { console.log("Sent output report " + response) });
这是基于 HID Point of Sale Usage Tables 中的下表:
第一个字节是报告 ID,根据表格为 2。对于第二个字节,我希望 ZS 操作设置为 1,因此是 00000010,因此也是 2。sendReport
将报告 ID 作为第一个参数,并将所有后续数据的数组作为第二个参数。当我将其发送到设备时,它不会被拒绝,但不会将比例归零,并且 response
未定义。
如何使用 WebHID 将此比例归零?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)