@serialport/stream
Advanced tools
Comparing version 10.2.2 to 10.3.0
/// <reference types="node" /> | ||
import { Duplex } from 'stream'; | ||
import { SetOptions, BindingInterface, PortInterfaceFromBinding, OpenOptions as BindingOpenOptions } from '@serialport/bindings-interface'; | ||
interface InternalSettings<T extends BindingInterface> extends OpenOptions<T> { | ||
import { SetOptions, BindingInterface, PortInterfaceFromBinding, OpenOptionsFromBinding } from '@serialport/bindings-interface'; | ||
export declare class DisconnectedError extends Error { | ||
disconnected: true; | ||
constructor(message: string); | ||
} | ||
interface InternalSettings<T extends BindingInterface> { | ||
binding: T; | ||
autoOpen: boolean; | ||
@@ -18,8 +23,9 @@ endOnClose: boolean; | ||
}) => void; | ||
export declare type OpenOptions<T extends BindingInterface = BindingInterface> = StreamOptions<T> & OpenOptionsFromBinding<T>; | ||
/** | ||
* Options to open a port | ||
*/ | ||
export interface OpenOptions<T extends BindingInterface> extends BindingOpenOptions { | ||
export interface StreamOptions<T extends BindingInterface> { | ||
/** | ||
* The hardware access binding. `Bindings` are how Node-Serialport talks to the underlying system. By default we auto detect Windows (`WindowsBinding`), Linux (`LinuxBinding`) and OS X (`DarwinBinding`) and load the appropriate module for your system. | ||
* The hardware access binding. `Bindings` are how Node-Serialport talks to the underlying system. If you're using the `serialport` package, this defaults to `'@serialport/bindings-cpp'` which auto detects Windows (`WindowsBinding`), Linux (`LinuxBinding`) and OS X (`DarwinBinding`) and load the appropriate module for your system. | ||
*/ | ||
@@ -38,6 +44,2 @@ binding: T; | ||
} | ||
export declare class DisconnectedError extends Error { | ||
disconnected: true; | ||
constructor(message: string); | ||
} | ||
export declare class SerialPortStream<T extends BindingInterface = BindingInterface> extends Duplex { | ||
@@ -49,12 +51,5 @@ port?: PortInterfaceFromBinding<T>; | ||
closing: boolean; | ||
readonly settings: InternalSettings<T>; | ||
readonly settings: InternalSettings<T> & OpenOptionsFromBinding<T>; | ||
/** | ||
* Create a new serial port object for the `path`. In the case of invalid arguments or invalid options, when constructing a new SerialPort it will throw an error. The port will open automatically by default, which is the equivalent of calling `port.open(openCallback)` in the next tick. You can disable this by setting the option `autoOpen` to `false`. | ||
* @param {OpenOptions=} options - Port configuration options | ||
* @param {ErrorCallback=} openCallback - If `autoOpen` is true (the default) it will be provided to `port.open()` and run after the port is opened. The callback will be ignored if `autoOpen` is set to `false`. | ||
* @property {number} baudRate The port's baudRate. Use `.update` to change it. Read-only. | ||
* @property {string} path The system path or name of the serial port. Read-only. | ||
* @property {boolean} isOpen `true` if the port is open, `false` otherwise. Read-only. | ||
* @property {InternalSettings} settings The current settings of the port | ||
* @throws {TypeError} When given invalid arguments, a `TypeError` will be thrown. | ||
* @emits open | ||
@@ -61,0 +56,0 @@ * @emits data |
@@ -10,2 +10,9 @@ "use strict"; | ||
const debug = (0, debug_1.default)('serialport/stream'); | ||
class DisconnectedError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.disconnected = true; | ||
} | ||
} | ||
exports.DisconnectedError = DisconnectedError; | ||
const defaultSetFlags = { | ||
@@ -22,19 +29,5 @@ brk: false, | ||
} | ||
class DisconnectedError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.disconnected = true; | ||
} | ||
} | ||
exports.DisconnectedError = DisconnectedError; | ||
class SerialPortStream extends stream_1.Duplex { | ||
/** | ||
* Create a new serial port object for the `path`. In the case of invalid arguments or invalid options, when constructing a new SerialPort it will throw an error. The port will open automatically by default, which is the equivalent of calling `port.open(openCallback)` in the next tick. You can disable this by setting the option `autoOpen` to `false`. | ||
* @param {OpenOptions=} options - Port configuration options | ||
* @param {ErrorCallback=} openCallback - If `autoOpen` is true (the default) it will be provided to `port.open()` and run after the port is opened. The callback will be ignored if `autoOpen` is set to `false`. | ||
* @property {number} baudRate The port's baudRate. Use `.update` to change it. Read-only. | ||
* @property {string} path The system path or name of the serial port. Read-only. | ||
* @property {boolean} isOpen `true` if the port is open, `false` otherwise. Read-only. | ||
* @property {InternalSettings} settings The current settings of the port | ||
* @throws {TypeError} When given invalid arguments, a `TypeError` will be thrown. | ||
* @emits open | ||
@@ -41,0 +34,0 @@ * @emits data |
{ | ||
"name": "@serialport/stream", | ||
"version": "10.2.2", | ||
"version": "10.3.0", | ||
"main": "./dist/index.js", | ||
@@ -29,3 +29,3 @@ "types": "./dist/index.d.ts", | ||
"funding": "https://opencollective.com/serialport/donate", | ||
"gitHead": "e8be807d39ad084ffc7e8609693da5a94cf8a9cb" | ||
"gitHead": "ceba41c8f89d911de210f2513aaae85fff3ab457" | ||
} |
@@ -1,2 +0,2 @@ | ||
# @serialport/Stream | ||
# @serialport/stream | ||
@@ -8,10 +8,10 @@ The serialport stream interface. This package requires bindings to work. | ||
This is how you use it. | ||
```js | ||
const SerialPort = require('@serialport/stream') | ||
```ts | ||
const { SerialPortStream } = require('@serialport/stream') | ||
const { autoDetect } = require('@serialport/bindings-cpp') | ||
SerialPort.Binding = autoDetect() | ||
const port = new Serialport('/dev/ttyay') | ||
const binding = autoDetect() | ||
const port = new SerialPortStream({ binding, path: '/dev/ttyay', baudRate: 9600 }) | ||
``` | ||
Learn more at our [stream documentation](https://serialport.io/docs/api-stream) page. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29502
558