Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(open): Throw on incorrect baudrate option #1347

Merged
merged 1 commit into from
Sep 24, 2017
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
2 changes: 1 addition & 1 deletion examples/socketio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const serialport = require('serialport');
const SerialPort = serialport.SerialPort;

const serial = new SerialPort('/dev/cu.usbmodem1411', {
baudrate: 9600,
baudRate: 9600,
parser: SerialPort.parsers.byteLength(1)
});

Expand Down
4 changes: 4 additions & 0 deletions lib/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ function SerialPort(path, options, callback) {
throw new TypeError(`"path" is not defined: ${path}`);
}

if (settings.baudrate) {
throw new TypeError(`"baudrate" is an unknown option, did you mean "baudRate"?`);
}

if (typeof settings.baudRate !== 'number') {
throw new TypeError(`"baudRate" must be a number: ${settings.baudRate}`);
}
Expand Down
6 changes: 6 additions & 0 deletions test/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ describe('SerialPort', () => {
}
});

it('throws an error when given bad baudrate even with a callback', function() {
assert.throws(() => {
this.port = new SerialPort('/dev/exists', { baudrate: 9600 }, () => {});
});
});

it('errors with a non number baudRate', function(done) {
try {
this.port = new SerialPort('/bad/port', { baudRate: 'whatever' });
Expand Down