3

我想使用 USB 实验 api 开发一个 chrome 扩展。我从来没有设法找到我的 USB 设备已连接。我对这个扩展的起点是这个代码: 旋钮示例 我更改了 vid 和 pid 以匹配我的 USB 设备,但没有任何成功。我在 Windows 上尝试了 canary 和 dev 通道。

看到我没有结果,我将清单修改为:

{
    "name": "USB Spinner",
    "version": "0.1",
    "manifest_version": 2,
    "app": {
        "background": {
            "scripts": ["background.js"]
        }
    },
    "permissions": [
        "app.window",
        "experimental",
        "usb"
    ]
}

我在权限中添加了实验性的 ans usb 字段。但仍然没有结果。

我访问 USB 设备的代码是:

var VENDOR_ID = 0x1234;
var PRODUCT_ID = 0x0006;

var usb = chrome.experimental.usb;

var deviceOptions = {
    onEvent: function(usbEvent) {
    }
};

usb.findDevice(
    VENDOR_ID,
    PRODUCT_ID,
    deviceOptions,
    function(device) {
        if (!device) {
            console.log('device not found');
            return;
        }
        console.log('Found device: ' + device.handle);
    }
);

任何帮助将非常感激。

我错过了什么?

4

1 回答 1

0

As mangini says, chrome.usb cannot access HID-class devices because the underlying operating system acquires them before that API implementation gets a chance. Fortunately, we're fixing that. Follow the tracking bug for adding USB HID support and please provide feedback on the suitability of the API and the quality of the implementation.

于 2014-03-06T17:29:48.417 回答