Я пытаюсь писать и читать с устройства IDTech. Когда я впервые проводил по карте, мне удалось получить 64 байта данных 5 раз, и я добавляю эти данные для дальнейшего использования. Когда я снова проведу по той же карте, я получу первые 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](https://i.stack.imgur.com/bk61y.png)
Второй вывод времени: ![Second Time output](https://i.stack.imgur.com/jmoHW.png)