【问题标题】:Chrome USB API interruptTransfer failedChrome USB API 中断传输失败
【发布时间】: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


【解决方案1】:

所以我今天遇到了类似的问题,我的 USB 设备只是不想工作,而且我遇到了同样的“传输失败”错误。现在这个问题已经很老了,但我将这个问题发布给将来可能会发现这个问题的任何人。

我的解决方案有两个:

  1. 还要在所有 INFO 中指定 interfaceId(以及供应商和产品 ID),例如{ "vendorId": 1118, "productId": 672, "interfaceId": 0 }

  2. VendorId 和 ProductId 应始终为十进制数字,而不是十六进制数字(即使 Google 示例显示不同)。此 API 的文档似乎与当前的现实略有不同步。

  3. 确保在我完成后尝试调用chrome.usb.interruptTransferchrome.usb.releaseInterface 之前调用了chrome.usb.claimInterface

  4. chrome.usb.interruptTransfer 的回调中使用 try-catch 包围所有内容

下面是一个我知道可行的工作示例代码的链接,也许它可以帮助您确定您的代码可能出了什么问题: https://github.com/sverrirs/XboxBigButton/blob/master/Examples/ChromeApp/xboxusb.js

【讨论】:

  • 你用来写vendor ID和product ID的base应该是无关的;十进制和十六进制只是在 Javascript 中编写相同数字的两种方式。
  • 同意,但实际上这似乎很重要。谷歌文档表明 manifest.json 必须有十进制值,但我发现这也适用于其余代码。 developer.chrome.com/apps/app_usb#manifest
猜你喜欢
  • 1970-01-01
  • 2011-06-07
  • 2017-02-28
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多