Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ before_install:
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
- echo "Publishing native platform Binary Package? ->" $PUBLISH_BINARY

# Cleanup the output of npm
- npm config set progress false
- npm config set spin false

install:
# ensure source install works
- npm install --build-from-source
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ Enjoy and do cool things with this code.
### SerialPort ⏏
**Kind**: Exported class
**Emits**: <code>[open](#module_serialport--SerialPort+event_open)</code>, <code>[data](#module_serialport--SerialPort+event_data)</code>, <code>[close](#module_serialport--SerialPort+event_close)</code>, <code>[error](#module_serialport--SerialPort+event_error)</code>, <code>[disconnect](#module_serialport--SerialPort+event_disconnect)</code>
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | The system path or name of the serial port. Read Only. |


-

Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ install:
}
true;

# Cleanup the output of npm
- ps: >
npm config set progress false
npm config set spin false

# We don't currently have a port to test on windows
# - ps: $env:TEST_PORT = "COM1";

Expand Down
43 changes: 12 additions & 31 deletions lib/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,6 @@ var defaultSetFlags = {
rts: true
};

// deprecate the lowercase version of these options next major release
var LOWERCASE_OPTIONS = [
'baudRate',
'dataBits',
'stopBits',
'bufferSize',
'platformOptions'
];

function correctOptions(options) {
LOWERCASE_OPTIONS.forEach(function(name) {
var lowerName = name.toLowerCase();
if (options.hasOwnProperty(lowerName)) {
var value = options[lowerName];
delete options[lowerName];
options[name] = value;
}
});
return options;
}

/**
* A callback called with an error or null.
* @typedef {function} errorCallback
Expand Down Expand Up @@ -110,6 +89,7 @@ function correctOptions(options) {
* @param {module:serialport~openOptions=} options - Port configuration options
* @param {module:serialport~errorCallback=} openCallback - Called when a connection has been opened. If this is not provided and an error occurs, it will be emitted on the ports `error` event. The callback will NOT be called if autoOpen is set to false in the openOptions as the open will not be performed.
* @throws {TypeError} When given invalid arguments a TypeError will be thrown.
* @property {string} path The system path or name of the serial port. Read Only.
* @emits module:serialport#open
* @emits module:serialport#data
* @emits module:serialport#close
Expand All @@ -122,6 +102,8 @@ function SerialPort(path, options, callback) {
return new SerialPort(path, options, callback);
}

stream.Stream.call(this);

if (typeof callback === 'boolean') {
throw new TypeError('`openImmediately` is now called `autoOpen` and is a property of options');
}
Expand All @@ -131,19 +113,19 @@ function SerialPort(path, options, callback) {
options = {};
}

options = options || {};
var settings = assign({}, defaultSettings, options);

stream.Stream.call(this);
Object.defineProperty(this, 'path', {
enumerable: true,
writable: false,
value: path
});

if (!path) {

if (!this.path) {
throw new TypeError('No path specified');
}

this.path = path;

var correctedOptions = correctOptions(options);
var settings = assign({}, defaultSettings, correctedOptions);

if (typeof settings.baudRate !== 'number') {
throw new TypeError('Invalid "baudRate" must be a number got: ' + settings.baudRate);
}
Expand Down Expand Up @@ -269,8 +251,7 @@ SerialPort.prototype.update = function(options, callback) {
return this._error(new Error('Port is not open'), callback);
}

var correctedOptions = correctOptions(options);
var settings = assign({}, defaultSettings, correctedOptions);
var settings = assign({}, defaultSettings, options);
this.options.baudRate = settings.baudRate;

SerialPortBinding.update(this.fd, this.options, function(err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"stress": "mocha --no-timeouts test/arduinoTest/stress.js",
"lint": "eslint *.js lib/**/*.js test/**/*.js bin/**/*.js examples/**/*.js",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha test/*.js test/arduinoTest/integration.js test/integration-lite.js",
"test:unit": "mocha test/*.js test/arduinoTest/integration.js test/integration-lite.js",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"valgrind": "valgrind --leak-check=full --show-possibly-lost=no node --expose-gc --trace-gc node_modules/.bin/grunt test"
},
Expand Down
26 changes: 17 additions & 9 deletions test/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ describe('SerialPort', function() {
done();
}
});

it('takes lowercase options', function(done) {
var port = new SerialPort.SerialPort('/dev/exists', { baudrate: 14400, autoOpen: false });
assert.equal(port.options.baudRate, 14400);
done();
});

});

describe('Constructor', function() {
Expand Down Expand Up @@ -118,7 +111,7 @@ describe('SerialPort', function() {

it('errors with invalid databits', function(done) {
try {
this.port = new SerialPort('/dev/exists', { databits: 19 });
this.port = new SerialPort('/dev/exists', { dataBits: 19 });
} catch(err){
assert.instanceOf(err, Error);
done();
Expand All @@ -127,7 +120,7 @@ describe('SerialPort', function() {

it('errors with invalid stopbits', function(done) {
try {
this.port = new SerialPort('/dev/exists', { stopbits: 19 });
this.port = new SerialPort('/dev/exists', { stopBits: 19 });
} catch(err){
assert.instanceOf(err, Error);
done();
Expand Down Expand Up @@ -173,6 +166,21 @@ describe('SerialPort', function() {
});
});

describe('Properties', function() {
describe('.path', function(){
it('is a read only property set during construction', function(){
var port = new SerialPort('/dev/exists', {autoOpen: false});
assert.equal(port.path, '/dev/exists');
try {
port.path = 'foo';
} catch(e) {
assert.instanceOf(e, TypeError);
}
assert.equal(port.path, '/dev/exists');
});
});
});

describe('Methods', function() {
describe('#open', function() {
it('passes the port to the bindings', function(done) {
Expand Down