Skip to content

Commit c47b924

Browse files
authored
Baudrate.250000 (#1239)
* Test for 250k baud rate
1 parent 9a826e5 commit c47b924

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ Changes the baud rate for an open port. Throws if you provide a bad argument. Em
477477
| Param | Type | Description |
478478
| --- | --- | --- |
479479
| [options] | <code>object</code> | Only supports `baudRate`. |
480-
| [options.baudRate] | <code>number</code> | The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. |
480+
| [options.baudRate] | <code>number</code> | The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. |
481481
| [callback] | [<code>errorCallback</code>](#module_serialport--SerialPort..errorCallback) | Called once the port's baud rate changes. If `.update` is called without a callback, and there is an error, an error event is emitted. |
482482

483483

@@ -1069,7 +1069,7 @@ A callback called with an error or an object with the modem line values (cts, ds
10691069
| Name | Type | Default | Description |
10701070
| --- | --- | --- | --- |
10711071
| autoOpen | <code>boolean</code> | <code>true</code> | Automatically opens the port on `nextTick`. |
1072-
| baudRate | <code>number</code> | <code>9600</code> | The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. |
1072+
| baudRate | <code>number</code> | <code>9600</code> | The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. |
10731073
| dataBits | <code>number</code> | <code>8</code> | Must be one of these: 8, 7, 6, or 5. |
10741074
| highWaterMark | <code>number</code> | <code>16384</code> | The size of the read and write buffers defaults to 16k. |
10751075
| lock | <code>boolean</code> | <code>true</code> | Prevent other processes from opening the port. Windows does not currently support `false`. |

lib/serialport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function allocNewReadPool(poolSize) {
6464
/**
6565
* @typedef {Object} openOptions
6666
* @property {boolean} [autoOpen=true] Automatically opens the port on `nextTick`.
67-
* @property {number=} [baudRate=9600] The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.
67+
* @property {number=} [baudRate=9600] The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.
6868
* @property {number} [dataBits=8] Must be one of these: 8, 7, 6, or 5.
6969
* @property {number} [highWaterMark=16384] The size of the read and write buffers defaults to 16k.
7070
* @property {boolean} [lock=true] Prevent other processes from opening the port. Windows does not currently support `false`.
@@ -244,7 +244,7 @@ SerialPort.prototype.open = function(callback) {
244244
/**
245245
* Changes the baud rate for an open port. Throws if you provide a bad argument. Emits an error or calls the callback if the baud rate isn't supported.
246246
* @param {object=} options Only supports `baudRate`.
247-
* @param {number=} [options.baudRate] The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.
247+
* @param {number=} [options.baudRate] The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.
248248
* @param {module:serialport~errorCallback=} [callback] Called once the port's baud rate changes. If `.update` is called without a callback, and there is an error, an error event is emitted.
249249
*/
250250
SerialPort.prototype.update = function(options, callback) {

test/bindings.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ function testBinding(bindingName, Binding, testPort) {
208208
});
209209
});
210210

211+
testFeature('baudrate.250000', 'supports a custom baudRate of 1000000', () => {
212+
const customRates = Object.assign({}, defaultOpenOptions, { baudRate: 250000 });
213+
return binding.open(testPort, customRates).then(() => {
214+
assert.equal(binding.isOpen, true);
215+
return binding.close();
216+
});
217+
});
218+
211219
describe('optional locking', () => {
212220
it('locks the port by default', () => {
213221
const binding2 = new Binding({ disconnect });
@@ -323,12 +331,6 @@ function testBinding(bindingName, Binding, testPort) {
323331
it('updates baudRate', () => {
324332
return binding.update({ baudRate: 57600 });
325333
});
326-
327-
testFeature('baudrate.25000', 'updates baudRate to a custom rate', () => {
328-
return binding.update({ baudRate: 25000 }).then(() => {
329-
return binding.update({ baudRate: defaultOpenOptions.baudRate });
330-
});
331-
});
332334
});
333335

334336
describe('#write', () => {

0 commit comments

Comments
 (0)