Created
April 26, 2018 10:32
-
-
Save Tom-Kuhn/538988bd68bbb5ce08997cc6c65c35cd to your computer and use it in GitHub Desktop.
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 characters
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