Skip to content

Instantly share code, notes, and snippets.

@teezzan
Created January 3, 2021 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teezzan/cb6866372d9130ef10b343e09cc785fc to your computer and use it in GitHub Desktop.
Save teezzan/cb6866372d9130ef10b343e09cc785fc to your computer and use it in GitHub Desktop.
let usb = require('usb')
function connectdevice(vID, pId) {
var device = usb.findByIds(vID, pId);
device.open();
var deviceINTF = device.interface(0);
if (deviceINTF.isKernelDriverActive())
deviceINTF.detachKernelDriver();
deviceINTF.claim();
var ePs = deviceINTF.endpoints;
var epIN;
$.each(ePs, function (index, ep) {
if (ep.direction == "in") {
epIN = ep;
}
});
if (epIN) {
epIN.on('data', function (data) {
alert("1" + data);
});
epIN.transferType = 2;
alert("non empty port : " + epIN);
epIN.transfer(64, function (error, data) {
console.log(error, data);
});
alert("after transfer");
} else {
alert("unable to read ..");
}
}
connectdevice(325, 18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment