【问题标题】:Can't open usb device via webUSB无法通过 webUSB 打开 USB 设备
【发布时间】:2020-10-02 14:35:27
【问题描述】:

我需要使用 webUSB 将设备连接到浏览器,连接后我调用 open 方法并且此错误属于“Uncaught (in promise) DOMException: Access denied.”。如何解决?

ngOnInit(): void {
    const button = document.getElementById('connectButton');
    button.addEventListener('click', async () => {
      let device;
      try {
        device = await navigator.usb.requestDevice({ filters: []});
      } catch (err) {
      }

      device.open()
        .then(() => device.selectConfiguration(1))
        .then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber));
    });
  }

【问题讨论】:

    标签: angular webusb


    【解决方案1】:

    你在什么平台上运行?

    在 Linux 上,如果当前用户无权打开 USB 设备,您将收到此错误。您需要配置 udev 规则以允许用户访问它。

    在 Windows 上,如果没有为设备加载 WinUSB 驱动程序,您将收到此错误。您可以使用Zadig 工具强制 Windows 加载设备的特定驱动程序。

    给网站的错误信息是故意含糊的。检查 chrome://device-log 以查看有关浏览器在尝试打开设备时遇到的错误的更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 2014-05-07
      相关资源
      最近更新 更多