如何使用 WebHID 将 USB 秤归零?
How do I zero a USB scale using WebHID?
我在 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, 0]
格式的常规输入,其中第四位是体重数据。如果我把东西放在秤上,它会变成 Uint8Array(5) [2, 12, 255, 48, 0]
,即 4.8 磅。
我想将秤归零(去皮),使其当前的受阻状态成为新的零点。成功归零后,我希望秤再次开始返回 Uint8Array(5) [2, 12, 255, 0, 0]
。我目前对此的最佳猜测是:
device[0]
.sendReport(0x02, new Uint8Array([0x02]))
.then(response => { console.log("Sent output report " + response) });
这是基于 HID Point of Sale Usage Tables 中的以下 table:
第一个字节是报告 ID,根据 table 为 2。对于第二个字节,我希望 ZS 操作设置为 1,即 00000010,因此也是 2。sendReport
将 Report Id 作为第一个参数,并将所有后续数据的数组作为第二个参数。当我将它发送到设备时,它没有被拒绝,但它没有将比例归零,并且 response
未定义。
如何使用 WebHID 将此秤归零?
所以我在一个非常相似的地方结束了 - 试图以编程方式将 USB 秤归零。设置ZS好像没什么作用。使用 Wireshark + Stamps.com 应用程序查看他们是如何做到的,并注意到发送的实际上是强制零 Return,即 0x02 0x01(报告 ID = 2,EZR)。现在开始工作了。
我在 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, 0]
格式的常规输入,其中第四位是体重数据。如果我把东西放在秤上,它会变成 Uint8Array(5) [2, 12, 255, 48, 0]
,即 4.8 磅。
我想将秤归零(去皮),使其当前的受阻状态成为新的零点。成功归零后,我希望秤再次开始返回 Uint8Array(5) [2, 12, 255, 0, 0]
。我目前对此的最佳猜测是:
device[0]
.sendReport(0x02, new Uint8Array([0x02]))
.then(response => { console.log("Sent output report " + response) });
这是基于 HID Point of Sale Usage Tables 中的以下 table:
第一个字节是报告 ID,根据 table 为 2。对于第二个字节,我希望 ZS 操作设置为 1,即 00000010,因此也是 2。sendReport
将 Report Id 作为第一个参数,并将所有后续数据的数组作为第二个参数。当我将它发送到设备时,它没有被拒绝,但它没有将比例归零,并且 response
未定义。
如何使用 WebHID 将此秤归零?
所以我在一个非常相似的地方结束了 - 试图以编程方式将 USB 秤归零。设置ZS好像没什么作用。使用 Wireshark + Stamps.com 应用程序查看他们是如何做到的,并注意到发送的实际上是强制零 Return,即 0x02 0x01(报告 ID = 2,EZR)。现在开始工作了。