-
Notifications
You must be signed in to change notification settings - Fork 0
2.0 HID Communication
klabarge edited this page Mar 27, 2018
·
2 revisions
- ✅ 2.0.1 | ⛔ 2.0 | ⛔ 1.9 | ...
claimDevice(vendorId, productId)
- Claims device based on hardware information using
claimDevice({vendorId: vendorId , productId: productId , usagePage: usagePage, serial: serial})
- Reads data from device using
readData({vendorId: vendorId , productId: productId , usagePage: usagePage, serial: serial}, responseSize)
- Releases device using
releaseDevice({vendorId: vendorId , productId: productId , usagePage: usagePage, serial: serial})
// 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 to a claimed HID device using
sendData(vendorId, productId, data)
function sendHIDData() {
qz.hid.sendData('0x0EB8', '0xF000', '0x008d', data).catch(displayError);
}
qz.print(config, data).catch(function(e) { console.error(e); });