Answer the question
In order to leave comments, you need to log in
Strange behavior of console.log()?
Hello!
There is a simple code for working with a card reader (HID device):
'use strict';
const express = require('express');
const app = express();
const HID = require('node-hid');
const device = new HID.HID(2303, 9);
let partsCount = 0;
let wholeCardData = '';
device.on("data", function(data) {
// 331d9165z
partsCount++;
wholeCardData += data.toString();
if (partsCount === 18) {
let zPos = wholeCardData.indexOf("z");
if (zPos !== -1) {
wholeCardData = wholeCardData.substr(0, zPos);
}
console.log(wholeCardData + ' d');
console.log(wholeCardData + ' s');
partsCount = 0;
wholeCardData = '';
}
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
331d9165z &#" d
&#" s
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question