Skip to content

Commit 156e405

Browse files
committed
Define, document, and test flow control and setting port flags (#726)
We had ambiguous behavior and documentation around these settings and functions, this preserves all of the previous behavior and defines it in documentation and tests. This is a step towards separating out and cleaning up user supplied options to the constructor.
1 parent 8bc3eea commit 156e405

File tree

5 files changed

+286
-179
lines changed

5 files changed

+286
-179
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
"no-caller": 2,
1717
"max-depth": 2,
1818
"complexity": [2, 32],
19-
"max-statements": [2, 60],
19+
"max-statements": [2, 41],
2020
"no-else-return": 2, // maybe
2121
"wrap-iife": [2, "inside"],
2222
"new-cap": 2,

README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,23 +269,18 @@ Port configuration options.
269269
* `dataBits` Data Bits, defaults to 8. Must be one of: 8, 7, 6, or 5.
270270
* `stopBits` Stop Bits, defaults to 1. Must be one of: 1 or 2.
271271
* `parity` Parity, defaults to 'none'. Must be one of: 'none', 'even', 'mark', 'odd', 'space'
272-
* `rtscts`
273-
* `xon`
274-
* `xoff`
275-
* `xany`
276-
* `flowControl` One of the following `XON`, `XOFF`, `XANY`, `RTSCTS`
277-
* `bufferSize` Size of read buffer, defaults to 255. Must be an integer value.
272+
* `rtscts` defaults to false
273+
* `xon` defaults to false
274+
* `xoff` defaults to false
275+
* `xany` defaults to false
276+
* `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.
277+
* `bufferSize` Size of read buffer, defaults to 65536. Must be an integer value.
278278
* `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.
279-
* `encoding`
280-
* `dataCallback`
281-
* `disconnectedCallback`
282279
* `platformOptions` - sets platform specific options, see below.
283280

284-
**Note:** We have added support for either all lowercase OR camelcase of the options (thanks @jagautier), use whichever style you prefer.
285-
286281
#### Unix Platform Options
287282

288-
An object with the following properties:
283+
These properties are ignored for windows. An object with the following properties:
289284

290285
* `vmin` (default: 1) - see [`man termios`](http://linux.die.net/man/3/termios)
291286
* `vtime` (default: 0) - see [`man termios`](http://linux.die.net/man/3/termios)
@@ -374,6 +369,26 @@ Called once a connection is closed. The callback should be a function that looks
374369

375370
**Note:** Currently closing a connection will also remove all event listeners.
376371

372+
### .set (options, callback)
373+
374+
Sets flags on an open port. Uses [`SetCommMask`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363257(v=vs.85).aspx) for windows and [`ioctl`](http://linux.die.net/man/4/tty_ioctl) for mac and linux.
375+
376+
**_options (optional)_**
377+
378+
All options are operating system default when the port is opened. Every flag is set on each call to the provided or default values. If options isn't provided default options will be used.
379+
380+
* `brk` optional boolean, defaults to false
381+
* `cts` optional boolean, defaults to false
382+
* `dsr` optional boolean, defaults to false
383+
* `dtr` optional boolean, defaults to true
384+
* `rts` optional boolean, defaults to true
385+
386+
**_callback (optional)_**
387+
388+
`callback: function(err, results)`
389+
390+
Called once the port's flags have been set. `results` are the return of the underlying system command. If `.set` is called without an callback and there is an error, an error event will be emitted.
391+
377392
## Events
378393

379394
### .on('open', callback)

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"nan": "~2.2.1",
5252
"node-pre-gyp": "0.6.x",
5353
"node-pre-gyp-github": "^1.1.0",
54+
"object.assign": "^4.0.3",
5455
"optimist": "~0.6.1",
5556
"sf": "0.1.7"
5657
},
@@ -60,6 +61,7 @@
6061
],
6162
"devDependencies": {
6263
"chai": "*",
64+
"chai-subset": "^1.2.2",
6365
"eslint-config-standard": "^5.1.0",
6466
"eslint-plugin-promise": "^1.1.0",
6567
"eslint-plugin-standard": "^1.3.2",

0 commit comments

Comments
 (0)