mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
- Constructor now throws errors when given invalid options - The Constructor’s callback is given to `.open()` if `openImmediately` is set - Depreciation warning when using the old style SerialPort.SerialPort
25 lines
897 B
JavaScript
25 lines
897 B
JavaScript
'use strict';
|
|
|
|
var SerialPort = require('serialport');
|
|
var port = new SerialPort('/dev/cu.Cubelet-RGB');
|
|
|
|
port.on('open', function() {
|
|
var largeMessage = new Buffer(1024 * 10).fill('!');
|
|
console.log('Calling write');
|
|
port.write(largeMessage, function() {
|
|
console.log('Write callback returned');
|
|
// At this point, data may still be buffered and not sent out over the port yet
|
|
// write function returns asynchronously even on the system level.
|
|
console.log('Calling drain');
|
|
port.drain(function() {
|
|
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
|
|
});
|
|
});
|
|
});
|
|
|
|
port.on('data', function(data) {
|
|
console.log('Received: \t', data);
|
|
});
|