Last active
May 1, 2024 12:56
-
-
Save basham/806605 to your computer and use it in GitHub Desktop.
Revisions
-
basham revised this gist
Oct 4, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,10 @@ CODE REPOSITORY --------------- https://gist.github.com/806605 VIDEO DEMO ---------- http://www.flickr.com/photos/chrisbasham/5408620216/ CHANGE LOG ---------- 02/02/2011 - Refactored code and acknowledged contributors. Listening for other helpful stream Events. -
basham revised this gist
Feb 2, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,7 +69,7 @@ var ids = []; // ARGUMENT 2: // Simplifies restruction of stream if one bit comes at a time. // However, I don't know if or how this setting affects performance. fs.createReadStream('/dev/cu.usbserial-A600exqM', { bufferSize: 1 }) .on('open', function(fd) { -
basham revised this gist
Feb 2, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,6 +69,7 @@ var ids = []; // ARGUMENT 2: // Simplifies restruction of stream if one bit comes at a time. // However, I don't know if or how it affects performance with this setting. fs.createReadStream('/dev/cu.usbserial-A600exqM', { bufferSize: 1 }) .on('open', function(fd) { -
basham revised this gist
Feb 2, 2011 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /* DESCRIPTION ----------- 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 @@ -58,6 +58,7 @@ var fs = require('fs'); // Stores the RFID id as it reconstructs from the stream. var id = ''; // List of all RFID ids read var ids = []; // ARGUMENT 1: -
basham revised this gist
Feb 2, 2011 . 1 changed file with 48 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,12 +5,26 @@ 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 CODE REPOSITORY --------------- https://gist.github.com/806605 CHANGE LOG ---------- 02/02/2011 - Refactored code and acknowledged contributors. Listening for other helpful stream Events. 02/01/2011 - Created initial code. AUTHOR ------ Chris Basham @chrisbasham http://bash.am https://github.com/basham CONTRIBUTORS ------------ Elliott Cable https://github.com/elliottcable SOFTWARE -------- @@ -38,31 +52,49 @@ EXAMPLE RFID IDs */ // NodeJS includes var sys = require('sys'); var fs = require('fs'); // Stores the RFID id as it reconstructs from the stream. var id = ''; var ids = []; // ARGUMENT 1: // Stream path, 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. // ARGUMENT 2: // Simplifies restruction of stream if one bit comes at a time. fs.createReadStream('/dev/cu.usbserial-A600exqM', { bufferSize: 1 }) .on('open', function(fd) { sys.puts('Begin scanning RFID tags.'); }) .on('end', function() { sys.puts('End of data stream.'); }) .on('close', function() { sys.puts('Closing stream.'); }) .on('error', function(error) { sys.debug(error); }) .on('data', function(chunk) { chunk = chunk.toString('ascii').match(/\w*/)[0]; // Only keep hex chars if ( chunk.length == 0 ) { // Found non-hex char if ( id.length > 0 ) { // The ID isn't blank ids.push(id); // Store the completely reconstructed ID sys.puts(id); } id = ''; // Prepare for the next ID read return; } id += chunk; // Concat hex chars to the forming ID }); -
basham revised this gist
Feb 1, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,8 +61,8 @@ f.addListener('data', function(chunk) { if ( c == '' ) { // Found non-hex char if ( id != '' ) // The ID isn't blank sys.puts(id); // The complete ID is reconstructed id = ''; // Prepare for the next ID read return; } id += c; // Concat hex chars to the forming ID }); -
basham revised this gist
Feb 1, 2011 . 1 changed file with 12 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,14 @@ http://www.sparkfun.com/products/8628 EM4102 125 kHz RFID Tags http://www.trossenrobotics.com/store/p/3620-Blue-Key-Fob.aspx EXAMPLE RFID IDs ---------------- 2800F7D85D5A 3D00215B3671 31007E05450F 31007E195503 2800F77C5BF8 */ var sys = require('sys'); @@ -40,25 +48,21 @@ var fs = require('fs'); var serial = '/dev/cu.usbserial-A600exqM'; // Simplifies restruction of stream if one bit comes at a time. var f = fs.createReadStream(serial, { bufferSize: 1 }); // Stores the RFID id as it reconstructs from the stream. 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); // The complete ID is reconstructed id = ''; // Prepare for the next ID chunks return; } id += c; // Add to the ID }); -
basham revised this gist
Feb 1, 2011 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,15 +32,21 @@ 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) { -
basham created this gist
Feb 1, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ /* 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'); // Simplifies restruction of stream if one bit comes at a time. var f = fs.createReadStream('/dev/cu.usbserial-A600exqM', { 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 });