Skip to content

Instantly share code, notes, and snippets.

@KarbonDallas
Created February 18, 2013 00:49
Show Gist options
  • Save KarbonDallas/4974431 to your computer and use it in GitHub Desktop.
Save KarbonDallas/4974431 to your computer and use it in GitHub Desktop.
Barebones RFID module example.
var
serialport = require('serialport')
, stream = require('stream')
, util = require('util')
;
util.inherits(rfid, stream);
module.exports = rfid;
function rfid(opts, app) {
stream.call(this);
var mod = this;
this.config = function(dat, cb) {
app.log.debug("Received config request");
app.log.debug(dat);
cb(null, { });
}
this.device = new serialport.SerialPort("/dev/cu.usbserial-A100RV5D", {
baudrate : 9600
, parser : serialport.parsers.readline("\n")
});
this.device.on('open', function() {
console.log("RFID opened.");
this.on('data', function(dat) {
if(!dat) { return; }
mod.emit('data', dat);
app.log.debug("ninja-rfid: Scanned value: %s", dat);
});
this.on('error', function(err) {
app.log.error("ninja-rfid: %s", err);
});
this.on('close', function(err) {
app.log.debug("ninja-rfid: Serial connection closed");
})
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment