Skip to content

Instantly share code, notes, and snippets.

@amcjen
Created April 25, 2014 00:10
Show Gist options
  • Save amcjen/11273834 to your computer and use it in GitHub Desktop.
Save amcjen/11273834 to your computer and use it in GitHub Desktop.
var serialport = require('serialport');
var bindexof = require('buffer-indexof');
var ready = new Buffer("> ");
function die(err)
{
console.log(err);
process.exit(1);
}
var tested = 0;
serialport.list(function (err, ports) {
if(err) return die(err);
var com;
ports.forEach(function(port) {
if(port.pnpId.indexOf('Pinoccio') > -1 || port.manufacturer.indexOf('Pinoccio') > -1) com = port.comName;
});
if(!com) die("no scout found");
console.log(com);
serial = new serialport.SerialPort(com, {
baudrate: 115200,
buffersize: 16*1024
});
serial.on('open',function(err){
if(err) die(err);
}).on('error',function(err){
console.error('serial error: ',err);
}).on('data',function(buf){
process.stdout.write(buf);
if(tested) return;
if(bindexof(buf,ready) != 0) return;
tested = 1;
serial.write(" print millis;\n");
serial.write(" print millis;\n");
serial.write(" print millis;\n");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment