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

第一个字节是报告ID,根据表,它是2。对于第二个字节,我希望ZS操作设置为1,因此设置为00000010,因此也设置为2。sendReport将报告Id作为第一个参数,并将后面所有数据的数组作为第二个参数。当我将它发送到设备时,它不会被拒绝,但它不会将刻度置零,并且response是未定义的。
如何使用WebHID将此刻度置零?
发布于 2021-08-26 01:43:01
所以我最终来到了一个非常相似的地方--试图通过编程将USB刻度调零。设置ZS似乎没有任何作用。使用Wireshark + Stamps.com应用程序查看他们是如何做到这一点的,并注意到发送的实际上是强制零返回,即0x02 0x01 (报告Id = 2,EZR)。现在让它工作起来。
https://stackoverflow.com/questions/66972686
复制相似问题