How do I zero a USB scale using WebHID?

772 Views Asked by At

I am using WebHID in Chrome to communicate with a USB-enabled digital scale. I'm able to connect to the scale and subscribe to a stream of weight data as follows:

// 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);
});

I now receive regular input in the format Uint8Array(5) [2, 12, 255, 0, 0], where the fourth position is the weight data. If I put something on the scale, it changes to Uint8Array(5) [2, 12, 255, 48, 0] which is 4.8 pounds.

I would like to zero (tare) the scale so that its current, encumbered state becomes the new zero point. After a successful zeroing, I would expect the scale to start returning Uint8Array(5) [2, 12, 255, 0, 0] again. My current best guess at this is:

device[0]
  .sendReport(0x02, new Uint8Array([0x02]))
  .then(response => { console.log("Sent output report " + response) });

This is based on the following table from the HID Point of Sale Usage Tables: Text

The first byte is the Report ID, which is 2 as per the table. For the second byte, I want the ZS operation set to 1, thus 00000010, thus also 2. sendReport takes the Report Id as the first parameter, and an array of all following data as the second parameter. When I send this to the device, it isn't rejected, but it doesn't zero the scale, and response is undefined.

How can I zero this scale using WebHID?

1

There are 1 best solutions below

2
On BEST ANSWER

So I ended up at a very similar place - trying to programmatically zero a USB scale. Setting the ZS did not seem to do anything. Used Wireshark + Stamps.com app to see how they were doing it and noticed that what was sent was actually the Enforced Zero Return, i.e, 0x02 0x01 (Report Id = 2, EZR). Now have this working.