mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
docs(parsers): improve the parser examples
This commit is contained in:
parent
e8b73c2784
commit
41f1d2d2d6
28 changed files with 67 additions and 99 deletions
|
|
@ -2383,7 +2383,7 @@
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_byte-length.js.html">parsers/byte-length.js</a>, <a href="parsers_byte-length.js.html#line20">line 20</a>
|
||||
<a href="parsers_byte-length.js.html">parsers/byte-length.js</a>, <a href="parsers_byte-length.js.html#line18">line 18</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,14 +118,12 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>To use the `ByteLength` parser:
|
||||
```js
|
||||
<pre class="prettyprint"><code>// To use the `ByteLength` parser:
|
||||
const SerialPort = require('serialport');
|
||||
const ByteLength = SerialPort.parsers.ByteLength
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new ByteLength({length: 8}));
|
||||
parser.on('data', console.log); // will have 8 bytes per data event
|
||||
```</code></pre>
|
||||
parser.on('data', console.log); // will have 8 bytes per data event</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -285,7 +283,7 @@ parser.on('data', console.log); // will have 8 bytes per data event
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_cctalk.js.html">parsers/cctalk.js</a>, <a href="parsers_cctalk.js.html#line17">line 17</a>
|
||||
<a href="parsers_cctalk.js.html">parsers/cctalk.js</a>, <a href="parsers_cctalk.js.html#line15">line 15</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,14 +118,12 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>CCTalk Messages are emitted as buffers.
|
||||
```js
|
||||
<pre class="prettyprint"><code>// CCTalk Messages are emitted as buffers.
|
||||
const SerialPort = require('serialport');
|
||||
const CCTalk = SerialPort.parsers.CCTalk;
|
||||
const port = new SerialPort('/dev/ttyUSB0');
|
||||
const parser = port.pipe(new CCtalk());
|
||||
parser.on('data', console.log);
|
||||
```</code></pre>
|
||||
parser.on('data', console.log);</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -187,7 +185,7 @@ parser.on('data', console.log);
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_delimiter.js.html">parsers/delimiter.js</a>, <a href="parsers_delimiter.js.html#line17">line 17</a>
|
||||
<a href="parsers_delimiter.js.html">parsers/delimiter.js</a>, <a href="parsers_delimiter.js.html#line15">line 15</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,14 +118,12 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
```js
|
||||
<pre class="prettyprint"><code>// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
const SerialPort = require('serialport');
|
||||
const Delimiter = SerialPort.parsers.Delimiter;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') }));
|
||||
parser.on('data', console.log);
|
||||
```</code></pre>
|
||||
const parser = port.pipe(new Delimiter({ delimiter: '\n' }));
|
||||
parser.on('data', console.log);</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -187,7 +185,7 @@ parser.on('data', console.log);
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -576,7 +576,7 @@
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@
|
|||
ReadLineParser
|
||||
</h2>
|
||||
|
||||
<div class="class-description"><p>A transform stream that emits data after a newline delimiter is received.</p></div>
|
||||
<div class="class-description"><p>A transform stream that emits data after a newline delimiter is received.</p>
|
||||
<p> To use the <code>Readline</code> parser, provide a delimiter (defaults to <code>\n</code>). Data is emitted as string controllable by the <code>encoding</code> option (defaults to <code>utf8</code>).</p></div>
|
||||
|
||||
|
||||
</header>
|
||||
|
|
@ -69,7 +70,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_readline.js.html">parsers/readline.js</a>, <a href="parsers_readline.js.html#line17">line 17</a>
|
||||
<a href="parsers_readline.js.html">parsers/readline.js</a>, <a href="parsers_readline.js.html#line16">line 16</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,14 +119,11 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
<pre class="prettyprint"><code>const SerialPort = require('serialport');
|
||||
const Readline = SerialPort.parsers.Readline;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
|
||||
parser.on('data', console.log);
|
||||
```</code></pre>
|
||||
parser.on('data', console.log);</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -187,7 +185,7 @@ parser.on('data', console.log);
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@
|
|||
ReadyParser
|
||||
</h2>
|
||||
|
||||
<div class="class-description"><p>A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events</p></div>
|
||||
<div class="class-description"><p>A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events</p>
|
||||
<p>To use the <code>Ready</code> parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through.</p></div>
|
||||
|
||||
|
||||
</header>
|
||||
|
|
@ -69,7 +70,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_ready.js.html">parsers/ready.js</a>, <a href="parsers_ready.js.html#line18">line 18</a>
|
||||
<a href="parsers_ready.js.html">parsers/ready.js</a>, <a href="parsers_ready.js.html#line17">line 17</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,15 +119,12 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>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.
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
<pre class="prettyprint"><code>const SerialPort = require('serialport');
|
||||
const Ready = SerialPort.parsers.Ready;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Ready({ delimiter: 'READY' }));
|
||||
parser.on('ready', () => console.log('the ready byte sequence has been received'))
|
||||
parser.on('data', console.log); // all data after READY is received
|
||||
```</code></pre>
|
||||
parser.on('data', console.log); // all data after READY is received</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -292,7 +290,7 @@ parser.on('data', console.log); // all data after READY is received
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@
|
|||
RegexParser
|
||||
</h2>
|
||||
|
||||
<div class="class-description"><p>A transform stream that uses a regular expression to split the incoming text upon.</p></div>
|
||||
<div class="class-description"><p>A transform stream that uses a regular expression to split the incoming text upon.</p>
|
||||
<p>To use the <code>Regex</code> parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the <code>encoding</code> option (defaults to <code>utf8</code>).</p></div>
|
||||
|
||||
|
||||
</header>
|
||||
|
|
@ -69,7 +70,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="parsers_regex.js.html">parsers/regex.js</a>, <a href="parsers_regex.js.html#line17">line 17</a>
|
||||
<a href="parsers_regex.js.html">parsers/regex.js</a>, <a href="parsers_regex.js.html#line15">line 15</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
@ -118,14 +119,11 @@
|
|||
|
||||
<h5>Example</h5>
|
||||
|
||||
<pre class="prettyprint"><code>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`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
<pre class="prettyprint"><code>const SerialPort = require('serialport');
|
||||
const Regex = SerialPort.parsers.Regex;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }));
|
||||
parser.on('data', console.log);
|
||||
```</code></pre>
|
||||
parser.on('data', console.log);</code></pre>
|
||||
|
||||
|
||||
|
||||
|
|
@ -187,7 +185,7 @@ parser.on('data', console.log);
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -2981,7 +2981,7 @@ function writeAndDrain (data, callback) {
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ module.exports = BaseBinding;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ module.exports = Poller;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -2027,7 +2027,7 @@ port.write('ROBOT PLEASE RESPOND\n');
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ null
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ module.exports = SerialPort;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -47,14 +47,12 @@ const Transform = require('stream').Transform;
|
|||
* @param {Object} options parser options object
|
||||
* @param {Number} options.length the number of bytes on each data event
|
||||
* @example
|
||||
To use the `ByteLength` parser:
|
||||
```js
|
||||
// To use the `ByteLength` parser:
|
||||
const SerialPort = require('serialport');
|
||||
const ByteLength = SerialPort.parsers.ByteLength
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new ByteLength({length: 8}));
|
||||
parser.on('data', console.log); // will have 8 bytes per data event
|
||||
```
|
||||
*/
|
||||
class ByteLengthParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
@ -109,7 +107,7 @@ module.exports = ByteLengthParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -44,14 +44,12 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
* Parses the CCTalk protocol
|
||||
* @extends Transform
|
||||
* @example
|
||||
CCTalk Messages are emitted as buffers.
|
||||
```js
|
||||
// CCTalk Messages are emitted as buffers.
|
||||
const SerialPort = require('serialport');
|
||||
const CCTalk = SerialPort.parsers.CCTalk;
|
||||
const port = new SerialPort('/dev/ttyUSB0');
|
||||
const parser = port.pipe(new CCtalk());
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class CCTalkParser extends Transform {
|
||||
constructor() {
|
||||
|
|
@ -94,7 +92,7 @@ module.exports = CCTalkParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -44,14 +44,12 @@ const Transform = require('stream').Transform;
|
|||
* A transform stream that emits data each time a byte sequence is received.
|
||||
* @extends Transform
|
||||
* @example
|
||||
To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
```js
|
||||
// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
const SerialPort = require('serialport');
|
||||
const Delimiter = SerialPort.parsers.Delimiter;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') }));
|
||||
const parser = port.pipe(new Delimiter({ delimiter: '\n' }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class DelimiterParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
@ -102,7 +100,7 @@ module.exports = DelimiterParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ module.exports = {
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -42,16 +42,15 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
const DelimiterParser = require('./delimiter');
|
||||
/**
|
||||
* A transform stream that emits data after a newline delimiter is received.
|
||||
*
|
||||
* To use the `Readline` parser, provide a delimiter (defaults to `\n`). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
|
||||
* @extends DelimiterParser
|
||||
* @example
|
||||
To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Readline = SerialPort.parsers.Readline;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class ReadLineParser extends DelimiterParser {
|
||||
constructor(options) {
|
||||
|
|
@ -81,7 +80,7 @@ module.exports = ReadLineParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -42,17 +42,16 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
const Transform = require('stream').Transform;
|
||||
/**
|
||||
* A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events
|
||||
*
|
||||
* 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.
|
||||
* @extends Transform
|
||||
* @example
|
||||
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.
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Ready = SerialPort.parsers.Ready;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Ready({ delimiter: 'READY' }));
|
||||
parser.on('ready', () => console.log('the ready byte sequence has been received'))
|
||||
parser.on('data', console.log); // all data after READY is received
|
||||
```
|
||||
*/
|
||||
class ReadyParser extends Transform {
|
||||
/**
|
||||
|
|
@ -116,7 +115,7 @@ module.exports = ReadyParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -41,17 +41,15 @@
|
|||
const Transform = require('stream').Transform;
|
||||
/**
|
||||
* A transform stream that uses a regular expression to split the incoming text upon.
|
||||
*
|
||||
* 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`).
|
||||
* @extends Transform
|
||||
* @example
|
||||
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`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Regex = SerialPort.parsers.Regex;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
|
||||
*/
|
||||
class RegexParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
@ -103,7 +101,7 @@ module.exports = RegexParser;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -684,7 +684,7 @@ module.exports = SerialPort;
|
|||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 23:06:42 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
|
|
|||
|
|
@ -8,14 +8,12 @@ const Transform = require('stream').Transform;
|
|||
* @param {Object} options parser options object
|
||||
* @param {Number} options.length the number of bytes on each data event
|
||||
* @example
|
||||
To use the `ByteLength` parser:
|
||||
```js
|
||||
// To use the `ByteLength` parser:
|
||||
const SerialPort = require('serialport');
|
||||
const ByteLength = SerialPort.parsers.ByteLength
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new ByteLength({length: 8}));
|
||||
parser.on('data', console.log); // will have 8 bytes per data event
|
||||
```
|
||||
*/
|
||||
class ByteLengthParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -5,14 +5,12 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
* Parses the CCTalk protocol
|
||||
* @extends Transform
|
||||
* @example
|
||||
CCTalk Messages are emitted as buffers.
|
||||
```js
|
||||
// CCTalk Messages are emitted as buffers.
|
||||
const SerialPort = require('serialport');
|
||||
const CCTalk = SerialPort.parsers.CCTalk;
|
||||
const port = new SerialPort('/dev/ttyUSB0');
|
||||
const parser = port.pipe(new CCtalk());
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class CCTalkParser extends Transform {
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -5,14 +5,12 @@ const Transform = require('stream').Transform;
|
|||
* A transform stream that emits data each time a byte sequence is received.
|
||||
* @extends Transform
|
||||
* @example
|
||||
To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
```js
|
||||
// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
|
||||
const SerialPort = require('serialport');
|
||||
const Delimiter = SerialPort.parsers.Delimiter;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') }));
|
||||
const parser = port.pipe(new Delimiter({ delimiter: '\n' }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class DelimiterParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
const DelimiterParser = require('./delimiter');
|
||||
/**
|
||||
* A transform stream that emits data after a newline delimiter is received.
|
||||
*
|
||||
* To use the `Readline` parser, provide a delimiter (defaults to `\n`). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
|
||||
* @extends DelimiterParser
|
||||
* @example
|
||||
To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Readline = SerialPort.parsers.Readline;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
*/
|
||||
class ReadLineParser extends DelimiterParser {
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@ const Buffer = require('safe-buffer').Buffer;
|
|||
const Transform = require('stream').Transform;
|
||||
/**
|
||||
* A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events
|
||||
*
|
||||
* 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.
|
||||
* @extends Transform
|
||||
* @example
|
||||
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.
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Ready = SerialPort.parsers.Ready;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Ready({ delimiter: 'READY' }));
|
||||
parser.on('ready', () => console.log('the ready byte sequence has been received'))
|
||||
parser.on('data', console.log); // all data after READY is received
|
||||
```
|
||||
*/
|
||||
class ReadyParser extends Transform {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,17 +2,15 @@
|
|||
const Transform = require('stream').Transform;
|
||||
/**
|
||||
* A transform stream that uses a regular expression to split the incoming text upon.
|
||||
*
|
||||
* 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`).
|
||||
* @extends Transform
|
||||
* @example
|
||||
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`).
|
||||
```js
|
||||
const SerialPort = require('serialport');
|
||||
const Regex = SerialPort.parsers.Regex;
|
||||
const port = new SerialPort('/dev/tty-usbserial1');
|
||||
const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }));
|
||||
parser.on('data', console.log);
|
||||
```
|
||||
|
||||
*/
|
||||
class RegexParser extends Transform {
|
||||
constructor(options) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue