从 NFC reader 直接读取到桌面 Web 应用程序?

Reading from an NFC reader directly into a desktop web application?

我在 Linux 终端上使用 LibNFC 识别我的 ACR122U Reader,我想知道是否有方法让它在 [=] 上通过 Chrome 工作45=] 桌面,因为它非常类似于 Android 支持,所有 NFC 设备处理都由 libnfc 完成,浏览器只需要知道这个库,而不是每种类型的 USB 或其他可以执行 NFC 的设备。

我试过使用 WebNFC API 连接它:

document.getElementById("scanButton").addEventListener("click", async () => {
    log.innerHTML = "NFC Register started...";

    try {
      const ndef = new NDEFReader();
      await ndef.scan();
      log.innerHTML = ("> Scan started");
  
      ndef.addEventListener("readingerror", () => {
        log.innerHTML = ("Argh! Cannot read data from the NFC tag. Try another one?");
      });
  
      ndef.addEventListener("reading", ({ message, serialNumber }) => {
        log.innerHTML = ("ID  ${serialNumber} logged @" + dt.toLocaleTimeString());   });
    } catch (error) {
      log.innerHTML = (error);
    }
  });

  document.getElementById("stopButton").onclick = function(){
    log.innerHTML = "NFC Register stopped @ " + new Date().toLocaleTimeString();
    }; 

但我遇到了 Error: NFC Permission Request denied

和 WebUSB API 连接它:

var usbd = {};
let device;
let deviceEndpoint = 0x02;

let powerUpDevice = new Uint8Array([0x62,0x00, 0x00, 0x00, 0x00,0x00,0x00,0x01,0x00, 0x00]).buffer;
let getCardUID = new Uint8Array([0xff,0xca,0x00,0x00,0x04]).buffer;

(function() {
    'use strict';

    usbd.authorize = function(){
        navigator.usb.requestDevice({ filters: [{ vendorId: 0x072f }] })
            .then(selectedDevice => {
                device = selectedDevice;
                console.log(device.configuration.interfaces[0].interfaceNumber);
                console.log(device.manufacturerName);
                console.log(device.productName);
                console.log(device);
                return device.open()
                    .then(() => {
                        if (device.configuration === null) {
                            return device.selectConfiguration(1);
                        }
                    });
            })
            .then(() => device.claimInterface(0))

但我遇到了 Error: ...blocked because it implements a protected interface class 即不受支持,所以这是不行的。

有没有办法合并 libusb/libnfc 库或任何其他方法来直接连接 NFC reader 以读取网络 browser/application?

截至 2021 年 2 月,

Web NFC 仅在 Android 上受支持。参见 https://web.dev/nfc/

WebUSB 错误表明您请求的接口实现了受保护的 class(如下所示):

  // USB Class Codes are defined by the USB-IF:
  // https://www.usb.org/defined-class-codes
  const uint8_t kProtectedClasses[] = {
      0x01,  // Audio
      0x03,  // HID
      0x08,  // Mass Storage
      0x0B,  // Smart Card
      0x0E,  // Video
      0x10,  // Audio/Video
      0xE0,  // Wireless Controller (Bluetooth and Wireless USB)
  };

我想知道这是否是 linux 的事情,因为我能够通过 WebUSB 与 ACR122U 和 SCL3711 NFC reader USB 设备通信。参见 https://github.com/beaufortfrancois/chrome-nfc

您有没有先尝试 WebHID?参见 https://web.dev/hid