0
votes

i wanna get data from rfid tags using arduino and rfid-rc522 reader i can get tags data through arduino serial monitor but i can't receive the correct data with node.js all i get is the same numbers from all the tags (each tag should have it own number ) . what i get from arduino monitor which is correct :http://i.stack.imgur.com/3ukb7.png

and what i get from node.js : http://i.stack.imgur.com/wCXXN.png

my node.js code is :

  var SerialPort = require("serialport").SerialPort;
var serialport = new SerialPort("COM4",{baudrate:9600});
serialport.on('open', function(){

    serialport.on('data', function(data ){



            console.log(data[0]   );






    });
});;

any help to solve this would be appreciated .

1

1 Answers

0
votes

As nodejs is event based, you will get the string slice in block because the 'data' event is triggered every time a byte get received. Use node-serialport parsers to concat data received with previous until data have some 'x' char that denotes end of message.

var sp = new SerialPort("/dev/tty-usbserial1", {
  parser: serialport.parsers.readline("\n") // '\n' can be any character of your choice
});

hope that helps