【发布时间】:2015-12-20 16:48:49
【问题描述】:
我在使用 chrome.usb APIs 与 USB 设备建立通信时遇到问题 我一直在尝试一整天,但总是遇到同样的错误。
usb.interruptTransfer:传输失败
代码:
var PRODUCT_INFO = {
"vendorId": idhere,
"productId": idhere
}
function allInOne() {
// find and open USB device
chrome.usb.findDevices(PRODUCT_INFO, function (arrayConnection) {
if (arrayConnection && arrayConnection.length > 0) {
console.log("Device opened");
var connectionHandle = arrayConnection[0];
console.log(connectionHandle);
// list all interfaces
chrome.usb.listInterfaces(connectionHandle, function (interfaces) {
console.log(interfaces);
//choose the first
var interface = interfaces[0];
//claim the interface
chrome.usb.claimInterface(connectionHandle, interface.interfaceNumber, function () {
//transfer
chrome.usb.interruptTransfer(connectionHandle, {
"direction": interface.endpoints[0].direction,
"endpoint": interface.endpoints[0].address,
"length": interface.endpoints[0].maximumPacketSize
}, function (event) {
//log data
console.log(event);
});
});
});
} else {
console.log("device not found");
}
});
}
界面:
我做错了什么?
【问题讨论】:
-
您的设备是否在中断管道上发布数据供您读取?它可能会失败,因为没有可用的东西。我推荐一个 USB 协议分析器,它可以连接在你的主机和你的设备之间,这样你就可以在线查看 USB 数据——在你从提供更详细的 USB API 中抽象出来的情况下,它会特别有用错误代码。
标签: google-chrome-extension usb google-chrome-app