Skip to content

2.0 HID Communication

klabarge edited this page Mar 27, 2018 · 2 revisions

Compatibility

  • ✅ 2.0.1 | ⛔ 2.0 | ⛔ 1.9 | ...

Read Data

⚠️ Note: Syntax below is for 2.0.6 and newer. Old syntax: claimDevice(vendorId, productId)

// Hardware info (modify to match hardware)
var usb = {
   vendor: '0x0EB8',
   product: '0xF000',
   usagePage: '0x008d', //optional
   serial: '0XBE8d' //optional
};

// Generic error handler
var err = function(e) { console.error(e); }

// Generic data handler
var process = function(data) { console.log(data); }

// Handler to release claimed device	
var release = function() {
   qz.hid.releaseDevice({vendorID: hid.vendor, productID: hid.product, usagePage: hid.usagePage, serial: hid.serial}).catch(err);
}

// Connect to QZ Tray, claim, read, release
qz.websocket.connect().then(function() {
   return qz.hid.claimDevice({vendorID: hid.vendor, productID: hid.product, usagePage: hid.usagePage, serial: hid.serial});
}).then(function() {
   return qz.hid.readData({vendorID: hid.vendor, productID: hid.product, usagePage: hid.usagePage, serial: hid.serial}, '8'); // *
}).then(process).then(release).catch(err);

// Note:  Some hardware such as Fairbanks scales use '6' for byte length.  Adjust as needed

Send Data

function sendHIDData() {
   qz.hid.sendData('0x0EB8', '0xF000', '0x008d', data).catch(displayError);
}

qz.print(config, data).catch(function(e) { console.error(e); });
Clone this wiki locally