Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open() fails with NetworkError: Unable to claim interface #14

Closed
mibcat opened this issue Sep 24, 2020 · 4 comments
Closed

open() fails with NetworkError: Unable to claim interface #14

mibcat opened this issue Sep 24, 2020 · 4 comments

Comments

@mibcat
Copy link

mibcat commented Sep 24, 2020

Hi !
I like to use the linked npm package in an Angular application but I'm not able to open the serial port.

This is the test code:

    // implementation with web-serial-polyfill lib
    this.comPort = await serial.requestPort();
    if (this.comPort) {
      console.log(this.comPort);
      await this.comPort.open();
      console.log(this.comPort);
    }

The requestPort() function is working (permission access dialog is shown and populated with the device):

SerialPort {serialOptions_: {…}, device_: USBDevice}
device_: USBDevice {configurations: Array(1), deviceClass: 2, deviceProtocol: 0, deviceSubclass: 2, deviceVersionMajor: 2, …}
serialOptions_: {baudrate: 115200, databits: 8, stopbits: 1, parity: "none", buffersize: 255, …}
transferInterface_: USBInterface {alternates: Array(1), claimed: false, interfaceNumber: 1, alternate: null}
__proto__: Object

but the following open() function always fails:

core.js:4197 ERROR Error: Uncaught (in promise): Error: Error setting up device: NetworkError: Unable to claim interface.
Error: Error setting up device: NetworkError: Unable to claim interface.
    at SerialPort.open (serial.js:88)
    at resolvePromise (zone-evergreen.js:798)
    at zone-evergreen.js:705
    at rejected (tslib.es6.js:72)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Object.onInvoke (core.js:27430)
    at ZoneDelegate.invoke (zone-evergreen.js:363)
    at Zone.run (zone-evergreen.js:123)
    at zone-evergreen.js:857
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:27418)

What's the exact meaning of "Unable to claim interface" ?
The device shouldn't be blocked by an other application. It's listed under /dev/ttyACM0 and I can open it with a serial terminal program like cutecom without problems.

Thanks for any help !

Best regards,
Michael.

@reillyeon
Copy link
Collaborator

This library is a polyfill for the Serial API on platforms which do not have drivers for a USB serial port. If your system is detecting the device and creating /dev/ttyACM0 then you can use the real Serial API implementation in your browser. Enable it for development purposes using chrome://flags/#enable-experimental-web-platform-features or sign up for the Origin Trial here: https://developers.chrome.com/origintrials/#/view_trial/2992641952387694593

#10 tracks work to make the polyfill and browser implementations integrate more seamlessly.

@mibcat
Copy link
Author

mibcat commented Oct 5, 2020

OK - thanks for your feedback.

@helder-a-reis
Copy link

Hi, I am using this library to open a Serial connection on an Angular app running Chrome for Android and I'm getting a similar error. I was able to connect to the equipment using the WebUSB API, but that didn't provide the Serial connection, and the Serial API is not supported on Android, as far as I understand (even if enabling experimental features).
Should this library work for my use case? Thanks in advance. My code:

`import * as Serial from 'web-serial-polyfill';

public async connectSerial() {
    try {
        this.port = await Serial.serial.requestPort({ usbVendorId: 1546 });
        await this.port.open({ baudRate: 9600 });
        console.log(this.port);
    } catch (err) {
        console.error('There was an error opening the serial port:', err);
    }
}

`

@reillyeon
Copy link
Collaborator

If you are hitting an error claiming an interface on Android you are probably running into the case where the Android system has loaded a driver for the device even though it doesn't provide an API for applications to use that driver. We're looking at a solution for this in Chromium issue 1099521 but haven't had time to finish the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants