4

我正在尝试使用读卡器(https://www.ewen-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);
});

错误在这里:

device.claimInterface(0)

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

提前致谢!

4

1 回答 1

5

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

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

于 2019-02-27T20:30:59.680 回答