Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to claim interface using WebUSB?

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 complains about interface 1 not being available, as well as 0 or 2).

like image 632
Joris Blaak Avatar asked Dec 06 '16 13:12

Joris Blaak


1 Answers

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))
like image 98
Supersharp Avatar answered Oct 19 '22 05:10

Supersharp