【问题标题】:Cannot open the device if it is a composite device (with two interfaces) using webUSB APIs如果是使用 webUSB API 的复合设备(有两个接口),则无法打开设备
【发布时间】:2019-02-18 09:53:30
【问题描述】:

我在 Windows 10 上使用 Chrome 浏览器 v72.0.3626.109(Official Build)(32-bit)。

  1. 试图声明供应商特定复合 USB 设备的 USB 接口,其中 1 个接口是供应商特定的,另一个 DFU 运行时接口加载 winusb 驱动程序。 我已确保尚未加载供应商特定的驱动程序

    通过 webUSB API device.open() 打开设备失败,代码:18 (SecurityError: Access denied.)

    document.addEventListener('DOMContentLoaded', event => {
      let button = document.getElementById('connect')

      button.addEventListener('click', async() => {
        let device
        const VENDOR_ID = 0x04xx
    const PRODUCT_ID = 0x6xxx

        try {
          device = await navigator.usb.requestDevice({
            filters: [{
          vendorId: VENDOR_ID,
          productId: PRODUCT_ID
            }]
          })

      await device.open(); //Begin a session
      await device.selectConfiguration(1); 
      await device.claimInterface(0); 
      await device.releaseInterface(0); 
      await device.close(); 
    } catch (error) {
      console.log(error)
    }
      await device.close()
  })
})

我尝试过的其他场景...

  1. 我的 USB 设备只有 1 个接口(供应商特定的批量接口)并且没有加载驱动程序。该设备未在 requestDevice 打开的设备选择菜单中列出。

  2. 我的 USB 设备只有 1 个接口(DFU 运行时接口),并加载了 winusb 驱动程序。设备被列出、打开并声称接口可以使用 webUSB API 工作。

使用 webUSB API 列出和打开供应商特定的 USB 设备是否有限制?有什么我遗漏的吗?

【问题讨论】:

    标签: webusb


    【解决方案1】:

    可以使用 WebUSB 打开供应商特定接口,但需要针对它加载 WinUSB 驱动程序。这是浏览器用来打开设备的 Windows API 的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 2013-01-20
      相关资源
      最近更新 更多