0
我试图从我的电脑上使用tessel/node-usb在我的电子应用程序 中连接到USB设备读取数据,但我无法读取任何内容或出现任何错误! 我使用以下JS:使用node-usb从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 ..");
}
}