Skip to content

Instantly share code, notes, and snippets.

@tuna-f1sh
Last active July 20, 2017 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuna-f1sh/5ab6957007a680b681c296a7b57b9119 to your computer and use it in GitHub Desktop.
Save tuna-f1sh/5ab6957007a680b681c296a7b57b9119 to your computer and use it in GitHub Desktop.
Serial port buffer unload test
var SerialPort = require('serialport');
var port = new SerialPort('/dev/ttyUSB0', {
baudRate: 4800
});
port.on('open', function() {
port.write(new Buffer(256), function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
console.log('Calling drain');
port.drain(() => {
console.log('Drain callback returned');
// Now the data has "left the pipe" (tcdrain[1]/FlushFileBuffers[2] finished blocking).
// [1] http://linux.die.net/man/3/tcdrain
// [2] http://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aportx
});
});
});
// Open errors will be emitted as an error event
port.on('error', function(err) {
console.log('Error: ', err.message);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment