Skip to content

Commit 956de7e

Browse files
committed
docs: remove outdated samples, update descirptions
1 parent 7538995 commit 956de7e

File tree

6 files changed

+33
-58
lines changed

6 files changed

+33
-58
lines changed

packages/parser-inter-byte-timeout/lib/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ export interface InterByteTimeoutOptions extends TransformOptions {
88
}
99

1010
/**
11-
* Emits data if there is a pause between packets for the specified amount of time.
12-
*
13-
* A transform stream that emits data as a buffer after not receiving any bytes for the specified amount of time.
14-
* @example
15-
const SerialPort = require('serialport')
16-
const { InterByteTimeoutParser } = require('@serialport/parser-inter-byte-timeout')
17-
const port = new SerialPort('/dev/tty-usbserial1')
18-
const parser = port.pipe(new InterByteTimeoutParser({interval: 30}))
19-
parser.on('data', console.log) // will emit data if there is a pause between packets greater than 30ms
11+
* A transform stream that buffers data and emits it after not receiving any bytes for the specified amount of time or hitting a max buffer size.
2012
*/
2113

2214
export class InterByteTimeoutParser extends Transform {

packages/parser-readline/lib/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { DelimiterParser } from '@serialport/parser-delimiter'
22
import { TransformOptions } from 'stream'
33

44
export interface ReadlineOptions extends TransformOptions {
5-
/** defaults to false */
6-
includeDelimiter?: boolean
7-
/** defaults to \n */
5+
/** delimiter to use defaults to \n */
86
delimiter?: string | Buffer | number[]
7+
/** include the delimiter at the end of the packet defaults to false */
8+
includeDelimiter?: boolean
99
/** Defaults to utf8 */
1010
encoding?: BufferEncoding
1111
}

packages/parser-ready/lib/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import { Transform, TransformCallback, TransformOptions } from 'stream'
22

33
export interface ReadyParserOptions extends TransformOptions {
4+
/** delimiter to use to detect the input is ready */
45
delimiter: string | Buffer | number[]
56
}
67

78
/**
89
* A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events
910
*
1011
* To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through.
11-
* @example
12-
const SerialPort = require('serialport')
13-
const { ReadyParser } = require('@serialport/parser-ready')
14-
const port = new SerialPort('/dev/tty-usbserial1')
15-
const parser = port.pipe(new ReadyParser({ delimiter: 'READY' }))
16-
parser.on('ready', () => console.log('the ready byte sequence has been received'))
17-
parser.on('data', console.log) // all data after READY is received
1812
*/
1913
export class ReadyParser extends Transform {
2014
delimiter: Buffer

packages/parser-regex/lib/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { Transform, TransformCallback, TransformOptions } from 'stream'
22

33
export interface RegexParserOptions extends TransformOptions {
4+
/** The regular expression to use to split incoming text */
45
regex: RegExp | string | Buffer
6+
/** Defaults to utf8 */
7+
encoding?: BufferEncoding
58
}
69

710
/**
811
* A transform stream that uses a regular expression to split the incoming text upon.
912
*
1013
* To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
11-
*
12-
* @example
13-
const SerialPort = require('serialport')
14-
const Regex = require('@serialport/parser-regex')
15-
const port = new SerialPort('/dev/tty-usbserial1')
16-
const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }))
17-
parser.on('data', console.log)
1814
*/
1915
export class RegexParser extends Transform {
2016
regex: RegExp

packages/parser-slip-encoder/lib/decoder.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import { Transform, TransformCallback, TransformOptions } from 'stream'
22

33
export interface SlipDecoderOptions extends TransformOptions {
4+
/** Custom start byte */
45
START?: number
6+
/** Custom start escape byte */
7+
ESC_START?: number
8+
/** custom escape byte */
59
ESC?: number
10+
/** custom end byte */
611
END?: number
7-
ESC_START?: number
12+
/** custom escape end byte */
813
ESC_END?: number
14+
/** custom escape escape byte */
915
ESC_ESC?: number
1016
}
1117

1218
/**
13-
* A transform stream that decodes slip encoded data.
14-
* @extends Transform
15-
* @summary Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally,
16-
* custom slip escape and delimiters can be provided.
17-
* @example
18-
// Receive slip encoded data from a serialport and log decoded data
19-
const SerialPort = require('serialport')
20-
const { SlipDecoder } = require('@serialport/parser-slip-encoder')
21-
const port = new SerialPort('/dev/tty-usbserial1')
22-
const parser = port.pipe(new SlipDecoder())
23-
parser.on('data', console.log)
24-
*/
19+
* A transform stream that decodes slip encoded data.
20+
* @extends Transform
21+
*
22+
* Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally custom slip escape and delimiters can be provided.
23+
*/
2524
export class SlipDecoder extends Transform {
2625
opts: { START: number | undefined; ESC: number; END: number; ESC_START: number | undefined; ESC_END: number; ESC_ESC: number }
2726
buffer: Buffer

packages/parser-slip-encoder/lib/encoder.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import { Transform, TransformCallback, TransformOptions } from 'stream'
22

33
export interface SlipEncoderOptions extends TransformOptions {
4+
/** Custom start byte */
45
START?: number
6+
/** Custom start escape byte */
7+
ESC_START?: number
8+
/** custom escape byte */
59
ESC?: number
10+
/** custom end byte */
611
END?: number
7-
ESC_START?: number
12+
/** custom escape end byte */
813
ESC_END?: number
14+
/** custom escape escape byte */
915
ESC_ESC?: number
16+
/** Adds an END character at the beginning of each packet per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer" and allowed by RFC 1055 */
1017
bluetoothQuirk?: boolean
1118
}
1219

1320
/**
14-
* A transform stream that emits SLIP-encoded data for each incoming packet.
15-
* @extends Transform
16-
* @summary Runs in O(n) time, adding a 0xC0 character at the end of each
17-
* received packet and escaping characters, according to RFC 1055. Adds another
18-
* 0xC0 character at the beginning if the `bluetoothQuirk` option is truthy (as
19-
* per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer").
20-
* Optionally, custom slip escape and delimiters can be provided.
21-
* @example
22-
// Read lines from a text file, then SLIP-encode each and send them to a serial port
23-
const SerialPort = require('serialport')
24-
const { SlipEncoder } = require('@serialport/parser-slip-encoder')
25-
const Readline = require('parser-readline')
26-
const fileReader = require('fs').createReadStream('/tmp/some-file.txt');
27-
const port = new SerialPort('/dev/tty-usbserial1')
28-
const lineParser = fileReader.pipe(new Readline({ delimiter: '\r\n' }));
29-
const encoder = fileReader.pipe(new SlipEncoder({ bluetoothQuirk: false }));
30-
encoder.pipe(port);
31-
*/
21+
* A transform stream that emits SLIP-encoded data for each incoming packet.
22+
*
23+
* Runs in O(n) time, adding a 0xC0 character at the end of each
24+
* received packet and escaping characters, according to RFC 1055.
25+
*/
3226
export class SlipEncoder extends Transform {
3327
opts: {
3428
START: number | undefined

0 commit comments

Comments
 (0)