Skip to content

Instantly share code, notes, and snippets.

@lkptrzk
Created November 11, 2014 21:20
Show Gist options
  • Save lkptrzk/3ec978af003d3283d362 to your computer and use it in GitHub Desktop.
Save lkptrzk/3ec978af003d3283d362 to your computer and use it in GitHub Desktop.
var SerialPort = require('serialport').SerialPort;
var util = require('util');
if (!process.argv[2]) {
console.error('specify device');
process.exit(1);
}
var PATH = process.argv[2];
var DATA = {};
var serialPort = new SerialPort(PATH, {}, false);
serialPort.open(function () {
serialPort.on('data', function (data) {
console.log(data);
var str = data.toString();
if (DATA[str] == null) DATA[str] = 0;
DATA[str] += 1;
});
});
process.on('SIGINT', function () {
console.log(util.inspect(DATA, { depth: null }));
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment