diff --git a/lib/serialport.js b/lib/serialport.js index 92d08029b..45489d834 100644 --- a/lib/serialport.js +++ b/lib/serialport.js @@ -105,7 +105,7 @@ function SerialPort(path, options, callback) { stream.Stream.call(this); - if (typeof callback === 'boolean') { + if (typeof callback === 'boolean' || typeof options === 'boolean') { throw new TypeError('`openImmediately` is now called `autoOpen` and is a property of options'); } diff --git a/test/serialport.js b/test/serialport.js index 6abbe13e2..a851dda2e 100644 --- a/test/serialport.js +++ b/test/serialport.js @@ -402,12 +402,48 @@ describe('SerialPort', function() { describe('#write', function() { it('errors when the port is not open', function(done) { var cb = function() {}; - var port = new SerialPort('/dev/exists', false, cb); + var port = new SerialPort('/dev/exists', {autoOpen: false}, cb); port.write(null, function(err) { assert.instanceOf(err, Error); done(); }); }); + + it('writes to the bindings layer', function(done){ + var port = new SerialPort('/dev/exists'); + port.on('open', function(){ + var data = new Buffer('Crazy!'); + port.write(data, function(){ + var lastWrite = hardware.fds[port.fd].lastWrite; + assert.deepEqual(data, lastWrite); + done(); + }); + }); + }); + + it('converts strings to buffers', function(done){ + var port = new SerialPort('/dev/exists'); + port.on('open', function(){ + var data = 'Crazy!'; + port.write(data, function(){ + var lastWrite = hardware.fds[port.fd].lastWrite; + assert.deepEqual(new Buffer(data), lastWrite); + done(); + }); + }); + }); + + it('converts arrays to buffers', function(done){ + var port = new SerialPort('/dev/exists'); + port.on('open', function(){ + var data = [0,32,44,88]; + port.write(data, function(){ + var lastWrite = hardware.fds[port.fd].lastWrite; + assert.deepEqual(new Buffer(data), lastWrite); + done(); + }); + }); + }); }); describe('#set', function() {