微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 WebHID 将 USB 秤归零?

如何解决如何使用 WebHID 将 USB 秤归零?

我在 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 中的下表:

Text

一个字节是报告 ID,根据表格为 2。对于第二个字节,我希望 ZS 操作设置为 1,因此是 00000010,因此也是 2。sendReport 将报告 ID 作为第一个参数,并将所有后续数据的数组作为第二个参数。当我将其发送到设备时,它不会被拒绝,但不会将比例归零,并且 response 未定义。

如何使用 WebHID 将此比例归零?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。