[英]node.js usb InEndpoint Error under Ubuntu 12.04 Arm 7 Cortex
我目前在内部装有ARMv7的目标硬件(实用标准)上遇到了麻烦。 当将node.js与usb模块一起使用时,在我开发它的PC上可以很好地工作,但是现在使用usb模块的发送方法读取设备时,将其移植到目标时会出现问题。
这是系统的一些细节:
Linux utilite-ubuntu-desktop 3.0.35-cm-fx6-4 #123 SMP Thu Sep 12 10:41:30 IST 2013 armv7l armv7l armv7l GNU/Linux
libusb version: 1.0-9 or 1.0-18 (both tested)
node.js version: 0.10.22 (highest 0.10.x version to run on the target)
usb version: latest, (but also others tested downto 2.0)
我得到的错误如下(按此顺序):
{ [Error: **UNKNOWN**] errno: 6 }
要么
{ [Error: **UNKNOWN**] errno: 2 }
我查找了似乎直接来自libusb(errno.h)的错误号:
#define ENOFILE 2 /* No such file or directory */
#define ENOENT 2
#define ENXIO 6 /* No such device or address */
我的应用程序源代码是:
var usb = require('usb');
var panel_on_USB = usb.findByIds(conf.USB_VID, conf.USB_PID);
panel_on_USB.open();
console.log("interface :");
console.log(panel_on_USB.interface(0));
console.log("timeout :" + panel_on_USB.timeout);
var panel_interface = panel_on_USB.interface(0);
panel_interface.claim();
console.log("isKernelDriverActive: " + panel_interface.isKernelDriverActive());
console.log("descriptor: " + panel_interface.descriptor);
console.log("panel_interface: " + panel_interface.endpoints);
console.log("LIBUSB_ENDPOINT_IN = " + usb.LIBUSB_ENDPOINT_IN);
console.log("LIBUSB_ENDPOINT_OUT = " + usb.LIBUSB_ENDPOINT_OUT);
console.log(panel_interface.endpoint(1).direction);
console.log(panel_interface.endpoint(2).direction);
console.log(panel_interface.endpoint(131).direction);
console.log(panel_interface.endpoint(132).direction);
输出到控制台:
interface :
{ device:
{ busNumber: 2,
deviceAddress: 3,
deviceDescriptor:
{ bLength: 18,
bDescriptorType: 1,
bcdUSB: 512,
bDeviceClass: 0,
bDeviceSubClass: 0,
bDeviceProtocol: 0,
bMaxPacketSize0: 8,
idVendor: 1240,
idProduct: 62765,
bcdDevice: 0,
iManufacturer: 1,
iProduct: 2,
iSerialNumber: 0,
bNumConfigurations: 1 },
interfaces: [ [Circular] ] },
id: 0,
altSetting: 0,
descriptor:
{ bLength: 9,
bDescriptorType: 4,
bInterfaceNumber: 0,
bAlternateSetting: 0,
bNumEndpoints: 4,
bInterfaceClass: 255,
bInterfaceSubClass: 255,
bInterfaceProtocol: 255,
iInterface: 0,
extra: <Buffer >,
endpoints: [ [Object], [Object], [Object], [Object] ] },
interfaceNumber: 0,
endpoints:
[ { device: [Object],
descriptor: [Object],
address: 1,
transferType: 2 },
{ device: [Object],
descriptor: [Object],
address: 2,
transferType: 2 },
{ device: [Object],
descriptor: [Object],
address: 131,
transferType: 2 },
{ device: [Object],
descriptor: [Object],
address: 132,
transferType: 2 } ] }
timeout :1000
isKernelDriverActive: true
descriptor: [object Object]
panel_interface: [object Object],[object Object],[object Object],[object Object]
LIBUSB_ENDPOINT_IN = 128
LIBUSB_ENDPOINT_OUT = 0
out
out
in
in
产生错误的转接呼叫:
panel_interface.endpoint(131).transfer(Length_Total_Bytes, function(error, data){
if(error){
//if(conf.Debug_Console_Output){
console.log("USB_receive_Error:");
console.log(error);
//}
}
//...Data Handling done here...//
});
有任何想法吗?
由于在transfer()方法中实际接收到的数据长度和设置的数据长度不匹配而发生了问题。 以下代码解决了该问题,因为在我的情况下,设备总是将完整的缓冲区返回给主机(wMaxPacketSize):
var In_Transfer_Length = 1 * panel_interface.endpoint(131).descriptor.wMaxPacketSize;
panel_interface.endpoint(131).transfer(In_Transfer_Length, function(error, data){
有关此的更多详细信息,请参见github上的问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.