2

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?

  • Could you try using sendFeatureReport() instead of sendReport()? Often devices are configured via feature reports. – aja Apr 07 '21 at 06:05
  • Looking at the figure I posted again, you are absolutely right – it says Example Scale Control Feature Report. I just tried sending the same command using `sendFeatureReport` in place of `sendReport` but I still didn't get the result I expected. This is a new area for me to look into, though! – Robert Peacock Apr 07 '21 at 13:59

1 Answers1

1

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.

kelvynf
  • 26
  • 2
  • If I'm reading your post correctly, you are suggesting the following: `device[0].sendFeatureReport(0x02, new Uint8Array([0x01]))` This didn't work for me, so I tried using a program called USB Scale Wedge to see if my scale can be tared via HID at all. It doesn't seem like it can. I'm marking your answer as accepted in the hopes that it helps someone using a different scale than mine. – Robert Peacock Aug 27 '21 at 19:57
  • 1
    My comment was specifically that I found sending EZR, not ZS, to work for my scale (and unfortunately I'm sure not all scales will necessarily responding in the same way). I was using a different mechanism to send the report to the scale. Rather than "sendFeatureReport", I was writing a byte array directly to the USB device file handle. I also was padding the array with zeros up to the size of the FeatureReport as obtained from a GetCapabilities call. – kelvynf Aug 28 '21 at 19:54