Wiki - 2.0 HID Communication

Compatibility

Read Data

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

// 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(hid.vendor, hid.product).catch(err);
}

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

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

Send Data

qz.usb.sendData('0x0EB8', '0xF000', data).catch(displayError);

Honeywell Barcode Scanner

var device = {
   vendorId: '0x0c2e',     // Honeywell barcode scanner
   productId: '0x0b87',
   readSize: 8,            // in bytes, adjust as needed
   usagePage: '0x008c',    // optional for HID devices with duplicate endpoints
                           // Note:  usagePage is not yet available for Linux
};

qz.websocket.connect().then(function () {
   qz.hid.claimDevice(device);
}).then(function () {
   qz.hid.openStream(device);
}).catch(function (e) {
   console.error(e);
});

qz.hid.setHidCallbacks(function (streamEvent) {
   streamEvent.type === 'RECEIVE' ? console.log(streamEvent.output) : console.error(streamEvent.exception);
});

Posiflex USB Cash Drawer

// Posiflex Cash Drawer
var usb = {
   vendor: '0x0d3a',
   product: '0x0207'
};

// Drawer number 0-7 (7 is default)
var drawer = String.fromCharCode(7);
//                               ^-- Drawer number

/**
   USB kick code for the posiflex 4000 series:
   - 120 bytes including the report id
   - all 0x00 with byte[1] and byte[2] the drawer number
   - the drawers can be assigned a number 0-7 (default is 7)
**/
var prepend = [drawer, drawer];

// Create 120 byte null-filled string (119 bytes data + 1 byte reportId)
var data = prepend.join('') + Array(120 - (prepend.length + 1)).fill(null).join('');
//                                                          ^-- Report ID is appended by QZ Tray automatically

// Connect to QZ Tray, claim, write, release
qz.websocket.connect().then(function() {
   return qz.hid.claimDevice(hid.vendor, hid.product);
}).then(function() {
   return qz.usb.sendData(hid.vendor, hid.product, data);
}).catch(function(sendErr) {
   console.error(sendErr);
}).then(function() {
    return qz.hid.releaseDevice(hid.vendor, hid.product);
}).catch(function(releaseErr) {
   console.error(sendErr);
});
        
Edit this page