Created
August 21, 2017 22:16
-
-
Save vuongngo/f6777479c4a8bdea811627522fd704aa to your computer and use it in GitHub Desktop.
This file contains 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'); | |
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