Skip to content

Commit 6b0e85f

Browse files
authored
chore: update docs and examples (#2429)
Just a lot of cleanup
1 parent b3bead4 commit 6b0e85f

File tree

15 files changed

+108
-326
lines changed

15 files changed

+108
-326
lines changed

UPGRADE_GUIDE.md

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,3 @@
1-
Upgading from 9x to 10x
2-
-------------
3-
4-
- Typscript types are now available for all packages
5-
- Serialport no longer supports Node 10
6-
- SerialPort stream (from npm `serialport` and `@serialport/stream`) now take an options object with a required `path` and `baudRate`. They no longer default to a `baudRate` of 9600 as that's slow and usually not what's needed.
7-
- All packages now have named exports. They export their types and all relevant classes.
8-
- The package `serialport` no longer exports `serialport/test` but instead who classes `{ SerialPort, SerialPortMock }` where the mock is pre-configured with a mock binding.
9-
- Bindings have moved from `@serialport/bindings` to `@serialport/bindings-cpp` they are shipped with `prebuildify` and no longer require a post install download.
10-
- `@serialport/bindings-cpp` leverages N-API and shouldn't need to be upgraded for every node release or rebuild for electron
11-
- Bindings in general now have a new interface with the `@serialport/bindings-interface` type package that replaces `@serialport/bindings-abstract`
12-
- `SerialPortStream` from `@serialport/stream` no longer has a `list()` method as that was a direct call to the bindings.
13-
- `SerialPort` class from the `serialport` package no longer has a static `Bindings` property as it provides the OS specific bindings from `@serialport/bindings-cpp` if you need control of the bindings use `SerialPortStream`.
14-
- `SerialPortStream` methods (and by extension `SerialPort` methods) no longer throw when called with invalid input, their callbacks or the error event will convey input errors. This is because the binding layer now handles input validation as it's different on each platform.
15-
- `SerialPort` is now delivering a few more parsers
16-
- `@serialport/terminal` no longer has a default baudRate
17-
18-
TODO
19-
- stop bits are incorrect
20-
21-
22-
Upgrading from 8.x to 9.x
23-
-------------
24-
- Serialport no longer supports Node 8
25-
- We no longer provide 32 bit linux prebuild builds, you may still build these binaries yourself however.
26-
27-
28-
Upgrading from 7.x to 8.x
29-
-------------
30-
- Serialport cli tools are now their own packages. See https://serialport.io/docs/guide-cli for more information on how to use them.
31-
- `SerialPort.list()` and `Bindings.list()` no longer take a callback and only return a promise.
32-
- `comName` has been renamed `path` in the `PortInfo` objects returned from `SerialPort.list()` or `Bindings.list()` you'll get a deprecation warning if you access `comName` until the next major version where it will be absent.
33-
- `@serialport/terminal` now takes a `--path` argument instead of a `--port` argument
34-
- Bindings now use async functions and no longer throw errors, they only reject errors. If you relied on this behavior you can now simplify your code to only looking for promise rejections.
35-
36-
37-
Upgrading from 6.x to 7.x
38-
-------------
39-
We dropped support for Node.js 4, so you'll have to upgrade if you're running 4. We also split into many packages. See https://serialport.io/docs/api-overview for an overview of the new packages. Binaries have moved into `@serialport/bindings` so if you're distributing serialport in an electron app, you may have to make some changes.
40-
41-
42-
Upgrading from 5.x to 6.x
43-
-------------
44-
TLDR: You probably don't have to change anything. You might need to enable `rtscts` in your open options.
45-
46-
* **binaries:** We switched to `prebuild` a breaking change because it's substantially changes our install processes. It's also possible the install flags to ensure downloading or building from source has changed slightly. That's not our api per se, but it's enough for a breaking change.
47-
* **windows:** We previously hard coded to have RTS on for windows at all times it now default to off.
48-
49-
50-
Upgrading from 4.x to 5.x
51-
-------------
52-
Node SerialPort 5.0.0 is a major rewrite that improves stability, compatibility and performance. While the api surface is similar there have been a number of changes to ensure consistent error handling and operation of a serial port.
53-
54-
### Platforms
55-
- Drop NodeJS 0.10, 0.12, 5, and 7 support
56-
- Add node 8 support (we now only support LTS node versions)
57-
58-
### The SerialPort Object
59-
- Node SerialPort is now a [duplex stream](https://nodejs.org/api/stream.html) and can be paused and resumed on all platforms.
60-
- `isOpen` is now a property
61-
- `SerialPort.list` now has more consistent output across all platforms. This means the data in the objects may be different than 4x. Notably the path on OSX now returns the `tty` instead of the `cu` path and the `0x` has been removed from values on linux and osx.
62-
- `port.path` is now read only
63-
- removed lowercase options all options are now only accepted camelCase
64-
- Changed parsers to be transform streams. There are replacements for the built in parsers but custom parsers will have to be modified.
65-
66-
### Open options
67-
- `bufferSize` is now `highWaterMark` and defaults to 64k.
68-
- `parser` is removed in favor of using the new transform streams parsers
69-
70-
### Opening and closing
71-
- Removed the `disconnect` event. The `close` event now fires with a disconnect error object in the event of a disconnection.
72-
- `port.isOpen` is now a property not a function
73-
74-
### Reading and writing.
75-
- `port.on('data')` still works but `port.read()` and the `readable` event is now the preferred way to get data.
76-
- `port.read()` is now the best way to read data
77-
- `port.drain()` now waits for the current javascript write to complete before calling the system level drain.
78-
79-
### Other
80-
- We now conform to NodeJS error message formats. Most messages have changed.
81-
- The event loop is no longer held open if there are no active reads or writes
82-
- `SerialPort.list` has slightly different output with more information, decoded strings and `0x` prefixes removed from some properties.
83-
- `SerialPort.list` now returns a promise if no call back is provided
84-
85-
Upgrading from 3.x to 4.x
86-
-------------
87-
4.x brings a lot of changes please see the [changelog](./changelog.md) for the full list of changes. We'll review the api and behavior changes here.
88-
89-
The constructor has changed. We've removed an argument, changed how errors are thrown and it is returned when you `require('serialport');`
90-
91-
- Requiring `serialport` now returns the SerialPort constructor function instead of a factory object. `SerialPort.SerialPort` is now deprecated.
92-
- `SerialPort` constructor now throws on argument errors immediately.
93-
- Removed `openImmediately` from the constructor's api, the functionality is now named `autoOpen` on the options object.
94-
- Removed extraneous flow control settings from the `flowControl` option, use the specific options to set these flags now.
95-
- Removed undocumented callbacks from the options object `disconnectedCallback` and `dataCallback`
96-
97-
Write had a major change
98-
99-
- `.write(writeCallback)` now only calls it's callback once after the entire write operation, it used to be called for each write cycle and return the bytes written. This reduces the number of callbacks by hundreds of thousands over a megabyte at low bandwidth.
100-
101-
Callbacks changed a little
102-
103-
- All callbacks are called in the context of the port, `this` now equals the port.
104-
- Disconnections now always attempt to close the port, and you'll always get a `close` event after a `disconnect` event
105-
106-
Renamed our binaries
107-
108-
- Reanmed `serialportlist` to `serialport-list`
109-
- Renamed `serialportterm` to `serialport-term`
110-
111-
We fixed a bunch of bugs too
112-
113-
- [unix] `.drain` and `.set` now properly report errors
114-
- [windows] Fixed a bug where we weren't properly opening ports (provides better support virtual com ports too) thanks to @RogerHardiman
115-
- [windows] known issue `lock` false doesn't work (no change in behavior)
116-
117-
And added a new features
118-
119-
- [unix] Ports are now locked by default with the new `lock` options matches windows default behavior
120-
- [windows] `.update()` now supports windows for changing baud rates
121-
122-
Upgrading from 2.x to 3.x
123-
-------------
124-
3.0 brought a single major breaking change and a lot of minor improvements.
125-
126-
We stopped removing event listeners, if you wrote code to work around that, we're sorry we made you do it.
127-
128-
- `close` and `disconnect` events no longer call `removeAllListeners` and removes your event listeners. This was particularly bad for the `error` event. This is the only change and if you didn't have a special code to deal with this behavior you should probably upgrade from v2.1.2
129-
130-
New Features
131-
132-
- Added support for node 6.0
133-
- Update the cli tools. serialportterm can now list ports, serialportlist can now output in different formats
134-
- [unix] Better unix error messages
135-
136-
Fixed bugs
137-
138-
- [linux] bug fix in `.list()` where we weren't filtering out non block devices that are named like serial ports
139-
- [unix] Update now has less memory leaks, documentation and better error messages
140-
- [windows] Better error messages for opening ports
1+
# Upgrade Guide
1412

3+
Moved to https://serialport.io/docs/guide-upgrade

packages/parser-byte-length/lib/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ export interface ByteLengthOptions extends TransformOptions {
99
* Emit data every number of bytes
1010
*
1111
* A transform stream that emits data as a buffer after a specific number of bytes are received. Runs in O(n) time.
12-
* @example
13-
const SerialPort = require('serialport')
14-
const ByteLength = require('@serialport/parser-byte-length')
15-
const port = new SerialPort('/dev/tty-usbserial1')
16-
const parser = port.pipe(new ByteLength({length: 8}))
17-
parser.on('data', console.log) // will have 8 bytes per data event
1812
*/
1913
export class ByteLengthParser extends Transform {
2014
length: number

packages/parser-cctalk/lib/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import { Transform, TransformCallback } from 'stream'
55
* @extends Transform
66
*
77
* A transform stream that emits CCTalk packets as they are received.
8-
* @example
9-
import { CCTalkParser } from '@serialport/parser-cctalk'
10-
const SerialPort = require('serialport')
11-
const port = new SerialPort('/dev/ttyUSB0')
12-
const parser = port.pipe(new CCtalk())
13-
parser.on('data', console.log)
148
*/
159
export class CCTalkParser extends Transform {
1610
array: number[]

packages/parser-delimiter/lib/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ export interface DelimiterOptions extends TransformOptions {
1212
* @extends Transform
1313
*
1414
* To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes. Runs in O(n) time.
15-
* @example
16-
const SerialPort = require('serialport')
17-
const {DelimiterParser} = require('@serialport/parser-delimiter')
18-
const port = new SerialPort('/dev/tty-usbserial1')
19-
const parser = port.pipe(new DelimiterParser({ delimiter: '\n' }))
20-
parser.on('data', console.log)
2115
*/
2216
export class DelimiterParser extends Transform {
2317
includeDelimiter: boolean

packages/parser-packet-length/lib/index.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,18 @@ export interface PacketLengthOptions extends TransformOptions {
1414
}
1515

1616
/**
17-
* A transform stream that decodes packets with a delimiter and length of payload
18-
* specified within the data stream.
19-
* @extends Transform
20-
* @summary Decodes packets of the general form:
21-
* [delimiter][len][payload0] ... [payload0 + len]
22-
*
23-
* The length field can be up to 4 bytes and can be at any offset within the packet
24-
* [delimiter][header0][header1][len0][len1[payload0] ... [payload0 + len]
25-
*
26-
* The offset and number of bytes of the length field need to be provided in options
27-
* if not 1 byte immediately following the delimiter.
28-
* @example
29-
// Parse length encoded packets received on the serial port
30-
const SerialPort = require('serialport')
31-
const PacketLengthParser = require('@serialport/packet-length-parser')
32-
const port = new SerialPort('/dev/tty-usbserial1')
33-
const parser = port.pipe(new PacketLengthParser({
34-
delimiter: 0xbc,
35-
packetOverhead: 5,
36-
lengthBytes: 2,
37-
lengthOffset: 2,
38-
}))
39-
*/
17+
* A transform stream that decodes packets with a delimiter and length of payload
18+
* specified within the data stream.
19+
* @extends Transform
20+
* @summary Decodes packets of the general form:
21+
* [delimiter][len][payload0] ... [payload0 + len]
22+
*
23+
* The length field can be up to 4 bytes and can be at any offset within the packet
24+
* [delimiter][header0][header1][len0][len1[payload0] ... [payload0 + len]
25+
*
26+
* The offset and number of bytes of the length field need to be provided in options
27+
* if not 1 byte immediately following the delimiter.
28+
*/
4029
export class PacketLengthParser extends Transform {
4130
buffer: Buffer
4231
start: boolean

packages/parser-readline/lib/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ export interface ReadlineOptions extends TransformOptions {
1313
/**
1414
* A transform stream that emits data after a newline delimiter is received.
1515
* @summary To use the `Readline` parser, provide a delimiter (defaults to `\n`). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
16-
* @example
17-
const SerialPort = require('serialport')
18-
const {ReadlineParser} = require('@serialport/parser-readline')
19-
const port = new SerialPort('/dev/tty-usbserial1')
20-
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
21-
parser.on('data', console.log)
22-
*/
16+
*/
2317
export class ReadlineParser extends DelimiterParser {
2418
constructor(options?: ReadlineOptions) {
2519
const opts = {

packages/serialport/README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your roboti
55
> Go to https://serialport.io/ to learn more, find guides and api documentation.
66
77
## Quick Links
8+
89
- [**Guides**](https://serialport.io/docs/guide-about)
910
- [**API Docs**](https://serialport.io/docs/api-serialport)
10-
- [The `serialport` package api docs](https://serialport.io/docs/api-serialport)
11-
1211

1312
### Serialport
13+
1414
- [`serialport`](https://serialport.io/docs/api-serialport) Chances are you're looking for the `serialport` package which provides a good set of defaults for most projects. However it is quite easy to mix and match the parts of serialport you need.
1515

1616
### Bindings
17+
1718
The Bindings provide a low level interface to work with your serialport. It is possible to use them alone but it's usually easier to use them with an interface.
19+
1820
- [`@serialport/bindings-cpp`](https://serialport.io/docs/api-bindings) bindings for Linux, Mac and Windows
19-
- [`@serialport/binding-abstract`](https://serialport.io/docs/api-bindings-abstract) as an abstract class to use if you're making your own bindings
21+
- [`@serialport/binding-interface`](https://serialport.io/docs/api-bindings-interface) a typescript interface to use if you're making your own bindings
2022
- [`@serialport/binding-mock`](https://serialport.io/docs/api-binding-mock) for a mock binding package for testing
2123

2224
### Interfaces
25+
2326
Interfaces take a binding object and provide a different API on top of it. Currently we only ship a Node Stream Interface.
2427

2528
- [`@serialport/stream`](https://serialport.io/docs/api-stream) our traditional Node.js Stream interface
@@ -41,33 +44,28 @@ Parsers are traditionally Transform streams, but Duplex streams and other non st
4144
## Developing
4245

4346
### Developing node serialport projects
47+
4448
1. Clone this repo `git clone git@github.com:serialport/node-serialport.git`
4549
1. Run `npm install` to setup local package dependencies (run this any time you depend on a package local to this repo)
4650
1. Run `npm test` to ensure everything is working properly
4751
1. Add dev dependencies to the root package.json and package dependencies to the package's one.
4852

4953
### Developing Docs
5054

51-
You can develop the docs by running
52-
53-
```bash
54-
npm run docs:dev
55-
```
56-
57-
And build them by running
58-
```bash
59-
npm run docs
60-
```
55+
You can develop the docs with in the [website repo](https://github.com/serialport/website).
6156

62-
Docs are automatically built with [netlify](https://www.netlify.com/pricing/) including previews on branches. The master branch is deployed to https://serialport.io
57+
Docs are automatically built with [vercel](https://vercel.com/) including previews on branches. The main branch is deployed to https://serialport.io
6358

6459
## License
60+
6561
SerialPort packages are all [MIT licensed](LICENSE) and all it's dependencies are MIT licensed.
6662

6763
## Code of Conduct
64+
6865
SerialPort follows the [Nodebots Code of Conduct](http://nodebots.io/conduct.html). While the code is MIT licensed participation in the community has some rules to make this a good place to work and learn.
6966

7067
### TLDR
68+
7169
- Be respectful.
7270
- Abusive behavior is never tolerated.
7371
- Data published to NodeBots is hosted at the discretion of the service administrators, and may be removed.
@@ -84,7 +82,7 @@ SerialPort is currently employees a [governance](https://medium.com/the-node-js-
8482

8583
If you have a PR that improves the project people in any or all of the above people will help you land it.
8684

87-
**Maintainers**
85+
### Maintainers
8886

8987
- [Francis Gulotta](https://twitter.com/reconbot) | [reconbot](https://github.com/reconbot)
9088
- [Nick Hehr](https://twitter.com/hipsterbrown) | [hipsterbrown](https://github.com/hipsterbrown)

packages/serialport/examples/mocking.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable node/no-missing-require */
22

33
// Load Serialport with mock bindings
4-
// const SerialPort = require('../test'); // from inside the serialport repo
54
const { SerialPortMock: SerialPort } = require('serialport') // when installed as a package
65
const { MockBinding } = SerialPort
76

packages/serialport/lib/serialport.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,6 @@ const DetectedBinding = autoDetect()
66
export type SerialPortOpenOptions<T extends AutoDetectTypes> = Omit<StreamOptions<T>, 'binding'> & OpenOptionsFromBinding<T>
77

88
export class SerialPort<T extends AutoDetectTypes = AutoDetectTypes> extends SerialPortStream<T> {
9-
/**
10-
* Retrieves a list of available serial ports with metadata. Only the `path` is guaranteed. If unavailable the other fields will be undefined. The `path` is either the path or an identifier (eg `COM1`) used to open the SerialPort.
11-
*
12-
* We make an effort to identify the hardware attached and have consistent results between systems. Linux and OS X are mostly consistent. Windows relies on 3rd party device drivers for the information and is unable to guarantee the information. On windows If you have a USB connected device can we provide a serial number otherwise it will be `undefined`. The `pnpId` and `locationId` are not the same or present on all systems. The examples below were run with the same Arduino Uno.
13-
* Resolves with the list of available serial ports.
14-
* @example
15-
```js
16-
// OSX example port
17-
{
18-
path: '/dev/tty.usbmodem1421',
19-
manufacturer: 'Arduino (www.arduino.cc)',
20-
serialNumber: '752303138333518011C1',
21-
pnpId: undefined,
22-
locationId: '14500000',
23-
productId: '0043',
24-
vendorId: '2341'
25-
}
26-
27-
// Linux example port
28-
{
29-
path: '/dev/ttyACM0',
30-
manufacturer: 'Arduino (www.arduino.cc)',
31-
serialNumber: '752303138333518011C1',
32-
pnpId: 'usb-Arduino__www.arduino.cc__0043_752303138333518011C1-if00',
33-
locationId: undefined,
34-
productId: '0043',
35-
vendorId: '2341'
36-
}
37-
38-
// Windows example port
39-
{
40-
path: 'COM3',
41-
manufacturer: 'Arduino LLC (www.arduino.cc)',
42-
serialNumber: '752303138333518011C1',
43-
pnpId: 'USB\\VID_2341&PID_0043\\752303138333518011C1',
44-
locationId: 'Port_#0003.Hub_#0001',
45-
productId: '0043',
46-
vendorId: '2341'
47-
}
48-
```
49-
50-
```js
51-
var SerialPort = require('serialport');
52-
53-
// promise approach
54-
SerialPort.list()
55-
.then(ports) {...});
56-
.catch(err) {...});
57-
```
58-
*/
599
static list = DetectedBinding.list
6010
static readonly binding = DetectedBinding
6111

packages/serialport/test-manual/drain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable node/no-missing-require */
22

3-
const SerialPort = require('../')
3+
const { SerialPort } = require('../')
44
const port = process.env.TEST_PORT
55
// number of bytes to send
66
const size = 512

0 commit comments

Comments
 (0)