最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to claim interface using WebUSB? - Stack Overflow

programmeradmin0浏览0评论

After obtaining access to an attached device using navigator.usb.requestDevice I'm trying to open a connection with an attached device as follows:

device.open()
    .then(() => device.selectConfiguration(1))
    .then(() => device.claimInterface(1))

It seemingly successfully selects the configuration, however the claimInterface step will produce the following error:

DOMException: Unable to claim interface.

I'm running Chrome 55.0.2883.75 beta with the --disable-webusb-security flag as root (without those I didn't get any devices) on Ubuntu 16.10.

How can I get the connection up and running?

Edit:

It seems that the cdc_acm driver already claimed the interface since device I'm trying to attach is a serial device, unloading the driver will allow you to claim the device (however after this it plains about interface 1 not being available, as well as 0 or 2).

After obtaining access to an attached device using navigator.usb.requestDevice I'm trying to open a connection with an attached device as follows:

device.open()
    .then(() => device.selectConfiguration(1))
    .then(() => device.claimInterface(1))

It seemingly successfully selects the configuration, however the claimInterface step will produce the following error:

DOMException: Unable to claim interface.

I'm running Chrome 55.0.2883.75 beta with the --disable-webusb-security flag as root (without those I didn't get any devices) on Ubuntu 16.10.

How can I get the connection up and running?

Edit:

It seems that the cdc_acm driver already claimed the interface since device I'm trying to attach is a serial device, unloading the driver will allow you to claim the device (however after this it plains about interface 1 not being available, as well as 0 or 2).

Share Improve this question edited Dec 7, 2016 at 7:33 Joris Blaak asked Dec 6, 2016 at 13:45 Joris BlaakJoris Blaak 3982 silver badges10 bronze badges 1
  • 1 Since this device has multiple interfaces we should make sure that you're claiming the right one. Please include the output of lsusb -v for your device which will list the full device descriptors. A USB CDC device will indeed be difficult to use with WebUSB because of the existing drivers that are loaded however forcing the driver to unload should release the interface. When you get an error like "Unable to claim interface" Chrome will provide possibly more detail about the error in chrome://device-log. – Reilly Grant Commented May 5, 2017 at 23:54
Add a ment  | 

1 Answer 1

Reset to default 2

Once the configuration is selected, you can find the right interface number in device.configuration.interfaces[0].interfaceNumber:

device.open()
    .then(() => device.selectConfiguration(1))
    .then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber))
发布评论

评论列表(0)

  1. 暂无评论