S
S
sir_genry2018-06-06 12:53:27
Node.js
sir_genry, 2018-06-06 12:53:27

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!');
});

On the screen I see:
331d9165z  &#" d
  &#" s

I don't understand anything! Why is the value of the wholeCardData variable flying off?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VoidVolker, 2018-06-06
@VoidVolker

Perhaps there is no text. Dump the data and check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question