Skip to content

Instantly share code, notes, and snippets.

@vuongngo
Created August 21, 2017 22:16
Show Gist options
  • Save vuongngo/f6777479c4a8bdea811627522fd704aa to your computer and use it in GitHub Desktop.
Save vuongngo/f6777479c4a8bdea811627522fd704aa to your computer and use it in GitHub Desktop.
var SerialPort = require('serialport');
const Readline = SerialPort.parsers.Readline;
try {
var port = new SerialPort('/dev/ttyUSB0'); // default port for Zbee Explorer
// As I sent line separation message
const parser = new Readline();
port.pipe(parser);
port.on('open', function() {
// Try to establish initial connection with device
port.write('connecting', function(err) {
console.log(err);
});
});
parser.on('data', function(data) {
console.log('Recieve new data ', data);
});
port.on('error', function(err) {
console.log(err);
});
port.on('close', function() {
console.log('close');
});
} catch (e) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment