Google chrome extension Chrome USB API中断传输失败
我无法使用与usb设备建立通信 我试了一整天,但总是犯同样的错误 usb.interruptTransfer:传输失败 代码: } 接口:Google chrome extension Chrome USB API中断传输失败,google-chrome-extension,usb,google-chrome-app,Google Chrome Extension,Usb,Google Chrome App,我无法使用与usb设备建立通信 我试了一整天,但总是犯同样的错误 usb.interruptTransfer:传输失败 代码: } 接口: 我做错了什么?因此,今天我遇到了一个类似的问题,我的USB设备不想工作,并且出现了相同的“传输失败”错误。这是一个很老的问题,但我现在把它发布给将来可能会发现它的人 我的解决方案有两个方面: 在所有信息中也指定interfaceId(以及供应商和产品ID),例如{“vendorId”:1118,“productId”:672,“interfaceId”:0
我做错了什么?因此,今天我遇到了一个类似的问题,我的USB设备不想工作,并且出现了相同的“传输失败”错误。这是一个很老的问题,但我现在把它发布给将来可能会发现它的人 我的解决方案有两个方面:
{“vendorId”:1118,“productId”:672,“interfaceId”:0}
chrome.usb.interruptTransfer
和chrome.usb.releaseInterface
之前,请确保我调用了chrome.usb.claimiInterface
chrome.usb.interruptTransfer中的回调中,用try-catch将所有内容包围起来
您的设备是否在中断管道上发布数据供您读取?它可能会失败,因为什么都没有。我建议您在主机和设备之间安装一个USB协议分析器,这样您就可以在线查看USB数据-在这样的情况下,从提供更详细错误代码的USB API中提取出来会特别有用。您用于编写供应商ID和产品ID的基础应该是无关的decimal和hex只是在Javascript中编写相同数字的两种方式。同意,但在实践中似乎确实很重要。google文档指出manifest.json必须有十进制值,但我发现这也适用于代码的其余部分。
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");
}
});