Last active
July 20, 2017 07:23
-
-
Save tuna-f1sh/5ab6957007a680b681c296a7b57b9119 to your computer and use it in GitHub Desktop.
Serial port buffer unload test
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'); | |
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