mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
feat(open): Throw on incorrect baudrate option (#1347)
This was causing a lot of issues, lets make it easier on people.
This commit is contained in:
parent
c590021f62
commit
a3b8d35597
3 changed files with 11 additions and 1 deletions
|
|
@ -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)
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue