javascript - 尝试声明接口(interface)时出现 Google Chrome WebUSB API 错误

标签 javascript google-chrome webusb

我正在尝试使用 Google Chrome webUSB api 访问通过 USB 连接到我的计算机的读卡器。

按照说明操作 here ,一切正常,直到我尝试声明给我一个错误的界面:

“无法声明接口(interface) 0:设备或资源繁忙”

看来我的操作系统 (linux mint) 已经访问了这个设备,但不允许运算符(operator)访问。

有什么克服这个问题的建议吗?

编辑:

当我解除绑定(bind)驱动程序时,出现以下错误:

“无法声明接口(interface) 0:没有这样的文件或目录”

这也是此设备的 lsusb -v 的输出:

Bus 001 Device 012: ID 0ca6:a050 Castles Technology Co., Ltd 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0ca6 Castles Technology Co., Ltd
  idProduct          0xa050 
  bcdDevice            0.00
  iManufacturer           1 Linux 2.6.32.9 with dwc_otg_pcd
  iProduct                2 EFT-POS Terminal
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           67
    bNumInterfaces          2
    bConfigurationValue     2
    iConfiguration          3 EFT-POS Terminal
    bmAttributes         0xc0
      Self Powered
    MaxPower                2mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              4 CDC Abstract Control Model (ACM)
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x00
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 
      iInterface              5 CDC ACM Data
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0001
  Self Powered

最佳答案

“没有这样的文件或目录”(错误代码 ENOENT)通常表示提供的接口(interface)号不存在,但是从描述符来看显然不是这种情况,Chrome 会拒绝 claimInterface 返回的 promise “提供的接口(interface)号当前配置的设备不支持。”如果在向内核提交请求之前认为接口(interface)号无效。

但是,我注意到,此设备支持的单一配置的 bConfigurationValue 为 2。当驱动程序未绑定(bind)时,系统可能会取消配置设备,现在 Chrome 知道设备的当前配置与系统不同步。如果你在 /sys/bus/usb/devices 中找到设备并打印文件 bConfigurationValue 它会告诉你设备的真实当前配置,我猜会为 0。

不幸的是,目前无法通过 WebUSB API 修复这种不匹配,但是在解除绑定(bind)内核驱动程序后重新启动 Chrome 将允许它在正确的时间读取此文件并且不会不同步。

如果这对您有用,请在 crbug.com/new 提交错误我们可以找出最好的方法来避免将来出现这个问题。

关于javascript - 尝试声明接口(interface)时出现 Google Chrome WebUSB API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45520008/

相关文章:

javascript - 在 ES6 中加载 SASS 变量

javascript - Angular Controller 内的立即调用函数,好的做法?

javascript - location.hash 阻止 Chrome 中的页面加载

google-chrome - 如何规避 Chrome/Chromium 中 RTCRtpTransceiver 缺失的 .stop() 实现

使用rust STM32 : webUSB publishing sensors

javascript - 从 d3 事件处理程序访问类函数

javascript - 使用nodejs在目录中递归获取所有目录

javascript - 在 Chrome 扩展中使用 HTML5 Canvas

google-chrome - WebUSB API 找不到兼容设备

javascript - 在 Chrome 网络蓝牙 API 中未经用户许可连接到配对设备?