Skip to content

Instantly share code, notes, and snippets.

@Tom-Kuhn
Created April 26, 2018 10:32
Show Gist options
  • Save Tom-Kuhn/538988bd68bbb5ce08997cc6c65c35cd to your computer and use it in GitHub Desktop.
Save Tom-Kuhn/538988bd68bbb5ce08997cc6c65c35cd to your computer and use it in GitHub Desktop.
var SerialPort = require('serialport');
var port = new SerialPort('COM4', function (err) {
if (err) {
return console.log('Error: ', err.message);
}
});
port.on('data', function (data) {
// general debug function: print serial data
console.log('Data:', data.toString());
// initial setup: the Arduino sends a'r' character when it's ready to start in its setup() method.
if(data.toString() == 'r') {
serAvailable();
}
});
port.on('open', function() {
});
function serAvailable() {
port.write('0', function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment