WebUSB:请求的接口实现了受保护的类

Ale*_*eli 4 javascript webusb

我正在尝试使用读卡器 ( https://www.ewent-online.com/tcpdf/pdf/ew/p/EW1052/ ) 来读取健康卡。

这是代码(从官方文档复制粘贴:https : //developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web):

var device;

navigator['usb'].requestDevice({ filters: [] })
.then(selectedDevice => {
    device = selectedDevice;
    return device.open(); // Begin a session.
})
.then(() => device.selectConfiguration(1)) // Select configuration #1 forhe device.
.then(() => device.claimInterface(0)) // Request exclusive control over     interface #2.
.then(() => device.controlTransferOut({
    requestType: 'class',
    recipient: 'interface',
    request: 0x22,
    value: 0x01,
    index: 0x00}
)) // Ready to receive data
.then(() => device.transferIn(5, 64)) // Waiting for 64 bytes of data from endpoint #5.
.then(result => {
    let decoder = new window['TextDecoder']();
    console.log('Received: ' + decoder.decode(result.data));
})
.catch(error => {
    console.log(error);
});
Run Code Online (Sandbox Code Playgroud)

错误在这里:

device.claimInterface(0)
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我无法在课堂上访问。我不知道如何让它工作,我已经阅读了所有与 stackoverflow 相关的线程,但没有找到解决方案。

提前致谢!

Rei*_*ant 5

您的设备实现了 USB CCID 类,该类位于受 Chrome 保护的类列表中,如下文所述。无法通过 WebUSB 声明实现这些类的接口。

https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/LZXocaeCwDw/GLfAffGLAAAJ