/* ABOUT ----- Use NodeJS to read RFID ids through the USB serial stream. Code derived from this forum: http://groups.google.com/group/nodejs/browse_thread/thread/e2b071b6a70a6eb1/086ec7fcb5036699 AUTHOR ------ Chris Basham @chrisbasham http://bash.am 02/01/2011 SOFTWARE -------- NodeJS, version 0.2.6 http://nodejs.org HARDWARE -------- Sparkfun RFID USB Reader http://www.sparkfun.com/products/8852 RFID Reader ID-20 http://www.sparkfun.com/products/8628 EM4102 125 kHz RFID Tags http://www.trossenrobotics.com/store/p/3620-Blue-Key-Fob.aspx */ var sys = require('sys'); var fs = require('fs'); // This will be unique to your hardware. // List your available USB serial streams via terminal and choose one: // ls /dev | grep usb // Had trouble with TTY, so used CU. var serial = '/dev/cu.usbserial-A600exqM'; // Simplifies restruction of stream if one bit comes at a time. var f = fs.createReadStream(serial, { bufferSize: 1 }); var id = ''; f.addListener('open', function(fd) { sys.puts('SCAN RFID TAGS'); sys.puts('--------------'); }); f.addListener('data', function(chunk) { var c = chunk.toString('ascii').match(/\w*/)[0]; // Only keep hex chars if ( c == '' ) { // Found non-hex char if ( id != '' ) // The ID isn't blank sys.puts(id); id = ''; // Prepare for the next ID chunks return; } id += c; // Add to the ID });