javascript - WebUSB:请求的接口(interface)实现了一个 protected 类

标签 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);
});

错误在这里:

device.claimInterface(0)

出于某种原因,我无法在类里面访问。我不知道如何让它工作,我已经阅读了 alla stackoverflow 相关的线程但没有找到解决方案。

提前致谢!

最佳答案

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

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

关于javascript - WebUSB:请求的接口(interface)实现了一个 protected 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54910706/

相关文章:

javascript - 如何使用一些图像或图例添加到工具提示?

javascript - 使用 d3 的 chrome 扩展

python - USB : usb_device_handle_win. cc:1020 在 Windows10 上使用 Selenium 的 ChromeDriver v87/Chrome v87 无法从节点连接错误中读取描述符

javascript - 使用javascript将DataView对象转换为位图

javascript - 如何查找用于与 USB 设备交互的函数

javascript - 将 Html.EditorFor 替换为 Bootstrap Toggle

javascript - HTML5 和 JavaScript 中的视频音量 slider

javascript - 在 JavaScript 中向现有数组添加新值

html - 跨跨源 iframe 启用 webUSB,无需共享权限

javascript - 使用 WebUSB 从串行设备读取整个响应