我正在尝试通过 WebUSB API 使用带有以下代码的 POS 打印机,但它失败.claimInterface()
并出现错误DOMException: Unable to claim interface
。所有测试均在 Linux 上的 Chrome 80.0.3987.116 上完成。我该如何调试呢?
(更新)我找到了这个演示,但它导致了同样的错误。
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);
}
当然,我在 localhost 服务器(即“安全上下文”start()
)上运行它并使用用户手势调用函数。
我还确认没有其他进程正在使用该设备。
% 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
下面是 的输出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