Wednesday, 3 May 2017

Reading from usb device using node-usb

I am trying to read data from a USB device "connected to my PC" using tessel/node-usb 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 .."); 
}
}



via k.elgohary

No comments:

Post a Comment