节点HID附加收到的较早数据

时间:2019-06-06 15:05:32

标签: javascript node.js hid

我正在尝试从IDTech芯片和引脚设备进行读写。第一次刷卡时,我可以连续5次获取64字节的数据,并附加这些数据以备将来使用。当我再次刷同一张卡时,我会两次获得前64个字节的数据。我不知道我在做什么错。

public getIDTechDevice(writeCommandByteArray) {
    eHID.devices().forEach((device, index, records) => {
      this.deviceFound = (device.vendorId === this.VENDOR_ID);
      if (device.vendorId === this.VENDOR_ID && (this.deviceRecord === null || this.isCanceled)) {
        this.deviceRecord = device;
        this.deviceHandle = new eHID.HID(device.vendorId, device.productId);
        try {
          this.deviceHandle.write(writeCommandByteArray);
        } catch (error) {
          console.log("Failed to write----->", error);
        }
        this.deviceHandle.on("data", (data) => {
          this.rawDataHexConversion(data);
        });
        this.deviceHandle.on("error", (onerror) => {
          this.notifyInfo.error(onerror);
        });
      } else {
        // this.notifyInfo.error("IDTech Chip and Pin Not connected");
      }
    });
  }

  public rawDataHexConversion(data) {
    console.log("Raw", data.toString("hex"));
    this.hex = this.hex + data.slice(1, 64).toString("hex"); // Remove first element of the array and convert to hex
    const timeOutErrorCode = this.hex.slice(22, 24);
    if (timeOutErrorCode === "08") {
      console.log("Swipe Timeout Error");
      this.hex = "";
    }
    this.tempArray = data;
    this.streamArray = this.streamArray.concat(this.tempArray);
    if (this.streamArray.length === 5) {
      console.log("Final Hex--", this.hex);
      this.streamArray = [];
      this.tempArray = [];
      this.hex = "";
      // this.tractOneTrackTwoDataParsing(this.hex);

    }
    this.deviceRecord = null;
    this.isCanceled = false;
  }

首次输出First time output

第二时间输出:Second Time output

0 个答案:

没有答案