在使用 navigator.usb.requestDevice
获得对连接设备的访问权限后,我尝试打开与连接设备的连接,如下所示:
device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(1))
它似乎成功地选择了配置,但是 claimInterface
步骤会产生以下错误:
DOMException: Unable to claim interface.
我在 Ubuntu 16.10 上运行带有 --disable-webusb-security
标志的 Chrome 55.0.2883.75 beta root(没有那些我没有得到任何设备)。
如何建立并运行连接?
编辑:
似乎 cdc_acm 驱动程序已经声明了接口(interface),因为我试图连接的设备是一个串行设备,卸载驱动程序将允许您声明该设备(但是在此之后它提示接口(interface) 1 不可用,因为以及 0 或 2)。
最佳答案
选择配置后,您可以在 device.configuration.interfaces[0].interfaceNumber
中找到正确的接口(interface)编号:
device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber))
关于javascript - 如何使用WebUSB声明接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996858/