From 079777b694a12a94d86e87d2ed4aa8ac7abdf126 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Mon, 23 May 2016 23:45:11 -0400 Subject: [PATCH] Flowcontrol (#821) Remove the extra flow control settings --- README.md | 9 ++++---- lib/serialport.js | 18 ++++----------- test/serialport.js | 57 +++++++++++++++------------------------------- 3 files changed, 26 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 3c4de8e69..9487a9f24 100644 --- a/README.md +++ b/README.md @@ -316,11 +316,10 @@ Port configuration options. * `dataBits` Data Bits, defaults to 8. Must be one of: 8, 7, 6, or 5. * `stopBits` Stop Bits, defaults to 1. Must be one of: 1 or 2. * `parity` Parity, defaults to 'none'. Must be one of: 'none', 'even', 'mark', 'odd', 'space' -* `rtscts` defaults to false -* `xon` defaults to false -* `xoff` defaults to false -* `xany` defaults to false -* `flowControl` `true` for `rtscts` or an array with one or more of the following strings to enable them `xon`, `xoff`, `xany`, `rtscts`. Overwrites any individual settings. +* `rtscts` flow control, defaults to false +* `xon` flow control, defaults to false +* `xoff` flow control, defaults to false +* `xany` flow control, defaults to false * `bufferSize` Size of read buffer, defaults to 65536. Must be an integer value. * `parser` The parser engine to use with read data, defaults to rawPacket strategy which just emits the raw buffer as a "data" event. Can be any function that accepts EventEmitter as first parameter and the raw buffer as the second parameter. * `platformOptions` - sets platform specific options, see below. diff --git a/lib/serialport.js b/lib/serialport.js index 349ee8795..12174f87e 100644 --- a/lib/serialport.js +++ b/lib/serialport.js @@ -67,8 +67,7 @@ var LOWERCASE_OPTIONS = [ 'dataBits', 'stopBits', 'bufferSize', - 'platformOptions', - 'flowControl' + 'platformOptions' ]; function correctOptions(options) { @@ -127,18 +126,9 @@ function SerialPort(path, options, openImmediately, callback) { return callback(new Error('Invalid "parity": ' + settings.parity)); } - var fc = settings.flowControl; - if (fc === true) { - // Why!? - settings.rtscts = true; - } else if (Array.isArray(fc)) { - for (var i = fc.length - 1; i >= 0; i--) { - var fcSetting = fc[i].toLowerCase(); - if (FLOWCONTROLS.indexOf(fcSetting) > -1) { - settings[fcSetting] = true; - } else { - return callback(new Error('Invalid flowControl option: ' + fcSetting)); - } + for (var i = FLOWCONTROLS.length - 1; i >= 0; i--) { + if (typeof settings[FLOWCONTROLS[i]] !== 'boolean') { + return callback(new Error('Invalid "' + FLOWCONTROLS[i] + '" is not boolean')); } } diff --git a/test/serialport.js b/test/serialport.js index 18f7b61d1..0162cf6da 100644 --- a/test/serialport.js +++ b/test/serialport.js @@ -29,7 +29,7 @@ describe('SerialPort', function() { describe('Constructor', function() { it('opens the port immediately', function(done) { this.port = new SerialPort('/dev/exists', function(err) { - expect(err).to.not.be.ok; + assert.isNull(err); done(); }); }); @@ -76,47 +76,26 @@ describe('SerialPort', function() { }); }); - describe('flowControl', function() { - it('errors with invalid flow control', function(done) { - var opts = { flowcontrol: ['pumpkins'] }; - this.port = new SerialPort('/dev/exists', opts, false, function(err) { - assert.instanceOf(err, Error); - done(); - }); - }); - - it('sets valid flow control', function(done) { - var port = new SerialPort('/dev/exists', { flowcontrol: ['xon', 'XOFF', 'xany', 'RTSCTS'] }, false); - assert.isTrue(port.options.xon); - assert.isTrue(port.options.xoff); - assert.isTrue(port.options.xany); - assert.isTrue(port.options.rtscts); - done(); - }); - - it('sets rtscts to true if flow control is true', function(done) { - var port = new SerialPort('/dev/exists', { flowcontrol: true }, false); - assert.isFalse(port.options.xon); - assert.isFalse(port.options.xoff); - assert.isFalse(port.options.xany); - assert.isTrue(port.options.rtscts); + it('errors with invalid flow control', function(done) { + this.port = new SerialPort('/dev/exists', { xon: 'pumpkins' }, false, function(err) { + assert.instanceOf(err, Error); done(); }); + }); - it('sets valid flow control individually', function(done) { - var options = { - xon: true, - xoff: true, - xany: true, - rtscts: true - }; - var port = new SerialPort('/dev/exists', options, false); - assert.isTrue(port.options.xon); - assert.isTrue(port.options.xoff); - assert.isTrue(port.options.xany); - assert.isTrue(port.options.rtscts); - done(); - }); + it('sets valid flow control individually', function(done) { + var options = { + xon: true, + xoff: true, + xany: true, + rtscts: true + }; + var port = new SerialPort('/dev/exists', options, false); + assert.isTrue(port.options.xon); + assert.isTrue(port.options.xoff); + assert.isTrue(port.options.xany); + assert.isTrue(port.options.rtscts); + done(); }); it('allows optional options', function(done) {