javascript - WebUSB - "Unable to claim interface" error - Stack Overflow

I'm tryng to use an POS printer through WebUSB API with the code below but it fails at .claimInter

I'm tryng to use an POS printer through WebUSB API with the code below but it fails at .claimInterface() with an error of DOMException: Unable to claim interface. All tests are done on Chrome 80.0.3987.116 on Linux. How can I debug this?

(update) I found this demo but it results same error.

async function start () {
    const device = await navigator.usb.requestDevice({
        filters: [{
            vendorId: 0x04b8,
            productId: 0x0202
        }]
    });
    await device.open();
    await device.selectConfiguration(device.configurations[0].configurationValue);
    await device.claimInterface(device.configurations[0].interfaces[0].interfaceNumber);
}

Of cource I'm running it on localhost server (which is "secure context") and calling start() function with user gesture.

I also confirmed that no other processes are using the device.

% lsof /dev/bus/usb/001/011
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
chrome  4156 ikr7  393u   CHR 189,10      0t0 331233 /dev/bus/usb/001/011

And below is the output of lsusb -vs 001:011.

Bus 001 Device 011: ID 04b8:0202 Seiko Epson Corp. Receipt Printer M129C/TM-T70
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04b8 Seiko Epson Corp.
  idProduct          0x0202 Receipt Printer M129C/TM-T70
  bcdDevice            2.00
  iManufacturer           1 EPSON
  iProduct                2 EPSON UB-U01III
  iSerial                 3 20110125210031250M02C
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      2 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0001
  Self Powered

I'm tryng to use an POS printer through WebUSB API with the code below but it fails at .claimInterface() with an error of DOMException: Unable to claim interface. All tests are done on Chrome 80.0.3987.116 on Linux. How can I debug this?

(update) I found this demo but it results same error.

async function start () {
    const device = await navigator.usb.requestDevice({
        filters: [{
            vendorId: 0x04b8,
            productId: 0x0202
        }]
    });
    await device.open();
    await device.selectConfiguration(device.configurations[0].configurationValue);
    await device.claimInterface(device.configurations[0].interfaces[0].interfaceNumber);
}

Of cource I'm running it on localhost server (which is "secure context") and calling start() function with user gesture.

I also confirmed that no other processes are using the device.

% lsof /dev/bus/usb/001/011
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
chrome  4156 ikr7  393u   CHR 189,10      0t0 331233 /dev/bus/usb/001/011

And below is the output of lsusb -vs 001:011.

Bus 001 Device 011: ID 04b8:0202 Seiko Epson Corp. Receipt Printer M129C/TM-T70
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04b8 Seiko Epson Corp.
  idProduct          0x0202 Receipt Printer M129C/TM-T70
  bcdDevice            2.00
  iManufacturer           1 EPSON
  iProduct                2 EPSON UB-U01III
  iSerial                 3 20110125210031250M02C
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      2 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0001
  Self Powered
Share Improve this question asked Mar 21, 2020 at 17:25 ikr7ikr7 1011 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The problem was usblp driver that was automatically loaded by Linux kernel. Adding it to the blacklist solved the problem. Here's my /etc/modprobe.d/blacklistusblp.conf file.

blacklist usblp

Note that blacklisting usblp disables all USB printers that uses usblp driver but fortunately most people including me use CUPS as a printer driver.

(update) Figured out it would be better to write an udev rule that automatically detaches the kernel's default drivers rather than blacklisting. Here's my /etc/udev/rules.d/99-escpos.rules.

SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0202", MODE="0664", GROUP="wheel", RUN+="/bin/sh -c 'echo -n $id:1.0 > /sys/bus/usb/drivers/usblp/unbind && echo -n $id:1.0 > /sys/bus/usb/drivers/usbfs/unbind'"

This rule also unloads usbfs which occasionally loaded by the kernel when usblp is detached.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343528a4623439.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信