Reading from usb device using node-usb

electron, node.js, usb

Solution

The code has no issue but my device has 2 interfaces , and my code checking the first interface when i change this line code :

var deviceINTF=device.interface(0);

to :

var deviceINTF=device.interface(1);

It works !

Hope this help anybody.

Problem

I am trying to read data from a USB device "connected to my PC" using tessel/node-usb in my electron application but i am not able to read anything or getting any error ! i am using following js : ``` 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 .."); } } ```

Original source