How to use the usb.findByIds function in usb

To help you get started, we’ve selected a few usb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github progman32 / hulk-button-usb / index.js View on Github external
.alias('t', 'timeout')
  .default('t', 300)

  .describe('d', 'Detach kernel driver first')
  .alias('d', 'detach-kernel-driver')
  .boolean('d')
  .default('d', true)


  .help('h')
  .argv;

var vid = parseInt(argv.v, 16);
var pid = parseInt(argv.p, 16);

var button = usb.findByIds(vid, pid);

if (button) {
  console.log('Found button at vid, pid: 0x' + vid.toString(16) + ', 0x' + pid.toString(16));

  try {
    button.open();
  } catch (e) {
    if (e.errnum === usb.LIBUSB_ERROR_ACCESS) {
      console.error('Access denied, you probably need to define a udev rule for your device. Check README for advice.');
      process.exit(EXIT_CODE_ACCESS_DENIED);
    }
  }

  if (button.interfaces.length !== 1) {
    // Maybe try to figure out which interface we care about?
    throw new Error('Expected a single USB interface, but found ' + button.interfaces.length);
github xdk2mam / xdk2mam / usb-scdard / xdk2mam-nodejs / xdk2mam-usb.js View on Github external
var usb = require('usb')
var colors = require('colors')
let sensordata = require('xdk2mam')
var IOTA = require('iota.lib.js')
var Mam = require('./node_modules/xdk2mam/mam.client.js')

// Enter your Node URL and port (be sure to use a node with PoW enabled)
let iota = new IOTA({
  'provider': 'http://you-pow-enabled-node:14265' //(Check https://iota.dance/)  
});

let mamState = Mam.init(iota,undefined,2)

//Check if the ids (idVendor, idProduct) are correct. Take a look at this function 'usb.getDeviceList()'
var xdk110 = usb.findByIds(4236, 379)

xdk110.open()

if(xdk110.interfaces[0].isKernelDriverActive())
	xdk110.interfaces[0].detachKernelDriver()

var inEndpoint = xdk110.interfaces[1].endpoints[0];

xdk110.interfaces[1].claim()

inEndpoint.startPoll(1, 800)

console.log('*********************')
console.log('*    ' + colors.green.bold('XDK2MAM-USB') + '    *')
console.log('*********************\n')
console.log('Listening...')
github Cryptonomic / ConseilJS / src / utils / Trezor.ts View on Github external
return new Promise((resolve, reject) => {
            device = usb.findByIds(usbIds[0], usbIds[1]);
            reject = (e) => {throw e};
            if (!device) reject("No device found");
            device.open();
        
            // Find interface - we want to connect to the first one hopefully
            if (device.interfaces.length <= 0) reject("No interface found");
            interf = device.interface(device.interfaces[0].id);
            interf.claim();
        
            for(let i = 0; i < interf.endpoints.length; i++){
                if (interf.endpoints[i].direction == 'in' && !inep) inep = interf.endpoint(interf.endpoints[i].address);
                if (interf.endpoints[i].direction == 'out' && !outep) outep = interf.endpoint(interf.endpoints[i].address);
                if (inep && outep) break;
            }
            if (!inep || !outep)  reject("Not enough endpoints found");
            // Set up polling
github abcminiuser / lufa / Demos / Device / ClassDriver / GenericHID / HostTestApp / test_generic_hid_libusb.js View on Github external
function getAndInitHidDeviceAndInterface()
{
    device = usb.findByIds(deviceVid, devicePid);
    if (!device) {
        console.log('No device found');
        process.exit(1);
    }
    device.open();

    var hidInterface = device.interface(0);
    if (hidInterface.isKernelDriverActive()) {
        hidInterface.detachKernelDriver();
    }
    hidInterface.claim();

    async.series([
        function(callback) {
            setConfiguration(0, function(error, data) {
                callback();
github abcminiuser / lufa / Demos / Device / LowLevel / CCID / HostTestApp / test_generic_ccid_libusb.js View on Github external
function getAndInitCcidDeviceAndInterface()
{
    device = usb.findByIds(deviceVid, devicePid);
    if (!device) {
        console.log('No device found');
        process.exit(1);
    }
    device.open();

    var ccidInterface = device.interface(0);
    if (ccidInterface.isKernelDriverActive()) {
        ccidInterface.detachKernelDriver();
    }
    ccidInterface.claim();

    return {ccidDevice:device, ccidInterface:ccidInterface};
}
github sandeepmistry / rtlsdrjs / lib / usb.js View on Github external
return new Promise((resolve, reject) => {
    for (let i = 0; i < filters.length; i++) {
      const filter = filters[i];

      const usbDevice = usb.findByIds(filter.vendorId, filter.productId);

      if (usbDevice) {
        return resolve(new USB(usbDevice));
      }
    }

    reject(new Error('No devices found!'));
  });
};
github diefarbe / node-lib / src / better.ts View on Github external
export async function connect() {
    var usb = require('usb');

    var device = usb.findByIds(0x24f0, 0x2020);

    device.open();

    var apply = [
        0x00, 0x2d, 0x64, 0x0f,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
github haavardlian / escpos / src / adapters / Usb.ts View on Github external
private static findDeviceOrThrow(vid: number, pid: number): Device {
        if (vid && pid) {
                return findByIds(vid, pid);
        } else {
            const devices = Usb.getPrinterDevices(vid);
            if (devices.length > 0) {
                return devices[0];
            }
        }
        throw new Error("No printer found");
    }
github diefarbe / node-lib / POC / init.js View on Github external
async function connect() {
    var usb = require('usb');

    var device = usb.findByIds(0x24f0, 0x2020);

    device.open();

    await sendAndConfirm(device, Buffer(first));
    await sendAndConfirm(device, Buffer(second));
    await getData(device);
    await getData(device);
    await sendData(device, Buffer(third));
}
github keyboardio / teensy-loader.js / src / lib / index.js View on Github external
___open(vid, pid) {
    this.__close();

    let device = usb.findByIds(vid, pid);

    if (!device) return null;

    device.open();
    try {
      if (process.platform != "win32") {
        if (device.interfaces[0].isKernelDriverActive()) {
          device.interfaces[0].detachKernelDriver();
        }
      }
      if (process.platform != "darwin") {
        device.interfaces[0].claim();
      }
    } catch (_) {
      return null;
    }