This library is for use for simple serial output RFID readers. It was originally created for the Innovations RFID reader kit found at Sparkfun. It should work for any RFID reader that dumps its output to a serial port that node can read.
npm install serial-rfid-reader
var RFIDReader = require('serial-rfid-reader');
var rfid = new RFIDReader('/dev/tty0', 9600);
rfid.on("read", function(read){
console.log("RFID reader has read the following: ", read);
}).listen(function(err){
console.log("RFID Reader is now listening!");
})
The constructor accepts two arguments.
- port - A string representing the COM port to listen to. /dev/tty0 or COM4 are examples.
- options
- If it is a number, it is assumed that this is the baud rate.
- If it is an object, it will be passed to node-serialport as options. Baudrate must be included.
This will open the serial port and start listening for reads. Once open, it will call the cb and the "open" event, whichever you've defined (if any).
This closes the serial port.
There are three events you can subscribe to.
- serial - function(input, cb) - By default, this function will trim any non alphanumeric characters and spaces. This receives the raw input from the serial port. The callback function cb is function(err, parsedRead);
- read - function(read) - This is called with the parsedRead returned from serial port if err is null.
- open - function() - This is called when the serial port successfully opens.
This module makes use of node-serialport. This is a massive pain to compile on windows machines, so I suggest mozying on over to their github page. They have several excellent explanations there and on their wiki page that will help the install process.
Building node-serialport for NW is a pain on windows- moreso when its a sub-module. I wrote a helpful gist specifically for node-serialport, but can act as a helpful guide for building serial-rfid-reader for packaged NW apps.