Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inEndpoint.descriptor = endpointDesc;
const xferInEndpoint: usb.InEndpoint = inEndpoint.transfer(1, (error: string, data: Buffer) => inEndpoint);
inEndpoint.startPoll(1, 1);
inEndpoint.stopPoll(() => null);
const outEndpoint: usb.OutEndpoint = new usb.OutEndpoint(device, endpointDesc);
outEndpoint.direction = "out";
outEndpoint.transferType = 1;
outEndpoint.timeout = 1;
outEndpoint.descriptor = endpointDesc;
const xferOutEndpoint: usb.OutEndpoint = outEndpoint.transfer(new Buffer([]), (error: string) => null);
outEndpoint.transferWithZLP(new Buffer([]), (error: string) => null);
const findByDevice: usb.Device = usb.findByIds(1, 1);
usb.on("hey", (device: usb.Device) => null);
const deviceList: usb.Device[] = usb.getDeviceList();
usb.setDebugLevel(1);
const CHECK_LIBUSB_CLASS_PER_INTERFACE: number = usb.LIBUSB_CLASS_PER_INTERFACE;
const CHECK_LIBUSB_CLASS_AUDIO: number = usb.LIBUSB_CLASS_AUDIO;
const CHECK_LIBUSB_CLASS_COMM: number = usb.LIBUSB_CLASS_COMM;
const CHECK_LIBUSB_CLASS_HID: number = usb.LIBUSB_CLASS_HID;
const CHECK_LIBUSB_CLASS_PRINTER: number = usb.LIBUSB_CLASS_PRINTER;
const CHECK_LIBUSB_CLASS_PTP: number = usb.LIBUSB_CLASS_PTP;
const CHECK_LIBUSB_CLASS_MASS_STORAGE: number = usb.LIBUSB_CLASS_MASS_STORAGE;
const CHECK_LIBUSB_CLASS_HUB: number = usb.LIBUSB_CLASS_HUB;
const CHECK_LIBUSB_CLASS_DATA: number = usb.LIBUSB_CLASS_DATA;
const CHECK_LIBUSB_CLASS_WIRELESS: number = usb.LIBUSB_CLASS_WIRELESS;
const CHECK_LIBUSB_CLASS_APPLICATION: number = usb.LIBUSB_CLASS_APPLICATION;
const CHECK_LIBUSB_CLASS_VENDOR_SPEC: number = usb.LIBUSB_CLASS_VENDOR_SPEC;
// libusb_standard_request
const CHECK_LIBUSB_REQUEST_GET_STATUS: number = usb.LIBUSB_REQUEST_GET_STATUS;
return new Promise((resolve, reject) => {
var promises = usb.getDeviceList().map(UVCControl.validate)
Promise.all(promises).then(results => {
resolve(results.filter(w => w)) // rm nulls
}).catch(err => reject(err))
})
}
private loadDevices(): Promise> {
// Reset device cache
this.devices = {};
const devices = getDeviceList();
return this.serialPromises(this.loadDevice, devices);
}
async function testHid(){
var usb_devices = usb.getDeviceList();
var devs = getHIDDevicesByUsage(0xf1d0, 1);
if (devs.length == 0) {
throw 'No devices found'
}
console.log('Dev: ', devs[0]);
var dev = new HID.HID(devs[0].path);
console.log('Dev2: ', dev.getDeviceInfo());
dev.on('error', function(error) {
console.log('ERROR: ', error);
} );
var res = await dev.sendRecv(0x61, [0,0,0,0]);
console.log('Solo version is ', res);
return new Promise((resolve, reject) => {
let devices = usb.getDeviceList();
devices = devices.filter(device => device.deviceDescriptor.idVendor === vendorID);
if (devices.length === 0) {
return reject("No devices found");
}
process.stdin.setRawMode(true);
process.stdin.setEncoding("utf8");
process.stdin.on("readable", () => {
let input = process.stdin.read();
if (input === "\u0003") {
process.exit();
} else {
let index = parseInt(input);
if (index && index <= devices.length) {
process.stdin.setRawMode(false);
var usb = require('usb');
var devices = usb.getDeviceList();
devices.forEach(function(device) {
var vendorId = device.deviceDescriptor.idVendor;
var productId = device.deviceDescriptor.idProduct;
if (device.deviceDescriptor.iProduct) {
device.open();
var name = device.getStringDescriptor(device.deviceDescriptor.iProduct, function(error,product) {
console.log( product, '[ vId: 0x'+vendorId.toString(16), ' / pId: 0x'+productId.toString(16), ' ]');
device.close();
});
}
});
return new Promise((resolve, reject) => {
let devices = usb.getDeviceList();
devices = devices.filter(device => device.deviceDescriptor.idVendor === vendorID);
if (devices.length === 0) {
return reject("No devices found");
}
process.stdin.setRawMode(true);
process.stdin.setEncoding("utf8");
process.stdin.on("readable", () => {
let input = process.stdin.read();
if (input === "\u0003") {
process.exit();
} else {
let index = parseInt(input);
if (index && index <= devices.length) {
process.stdin.setRawMode(false);
private static getPrinterDevices(vid?: number): Device[] {
return getDeviceList()
.filter(device => !vid || device.deviceDescriptor.idVendor === vid)
.filter(device => {
try {
device.open();
return device.interfaces.some(iface => iface.descriptor.bInterfaceClass === PRINTER_CLASS);
} catch (err) {
return false;
} finally {
device.close();
}
});
}
BluetoothHciSocket.prototype.bindUser = function(devId) {
this._mode = 'user';
if (process.env.BLUETOOTH_HCI_SOCKET_USB_VID && process.env.BLUETOOTH_HCI_SOCKET_USB_PID) {
var usbVid = parseInt(process.env.BLUETOOTH_HCI_SOCKET_USB_VID);
var usbPid = parseInt(process.env.BLUETOOTH_HCI_SOCKET_USB_PID);
debug('using USB VID = ' + usbVid + ', PID = ' + usbPid);
if (process.env.BLUETOOTH_HCI_SOCKET_USB_BUS && process.env.BLUETOOTH_HCI_SOCKET_USB_ADDRESS) {
var usbBus = parseInt(process.env.BLUETOOTH_HCI_SOCKET_USB_BUS);
var usbAddress = parseInt(process.env.BLUETOOTH_HCI_SOCKET_USB_ADDRESS);
debug('using USB BUS = ' + usbBus + ', Address = ' + usbAddress);
var usbDevices = usb.getDeviceList();
for (var i = 0; i < usbDevices.length; i++) {
var usbDeviceDesc = usbDevices[i].deviceDescriptor;
if ((usbDeviceDesc.idVendor == usbVid) &&
(usbDeviceDesc.idProduct == usbPid) &&
(usbDevices[i].busNumber == usbBus) &&
(usbDevices[i].deviceAddress == usbAddress)) {
this._usbDevice = usbDevices[i];
}
}
} else {
this._usbDevice = usb.findByIds(usbVid, usbPid);
}
} else {
this._usbDevice = VENDOR_DEVICE_LIST