Serial
Extends:
A node-serialport wrapper that keeps track of port state and allows from on-the-fly port path/name changes (automatically attaches/detaches event listeners and keeps config).
Constructor Summary
Public Constructor | ||
public |
constructor(parser: Function, baud: Number) Constructor: the place for setting the baud rate and parser. |
Member Summary
Private Members | ||
private |
Holds the desired serial baud rate. |
|
private |
_log: * Logger instance. |
|
private |
Holds the parsing function. |
|
private |
Holds the current port path. |
|
private |
_port: SerialPort Holds the current node-serialport instance. |
|
private |
Holds current state. |
Method Summary
Public Methods | ||
public |
Closes the serialport. |
|
public |
Opens the serialport, creating it if needed. |
|
public |
Sets a new path to all future serialport instances. |
Protected Methods | ||
protected |
Creates the serialport instance and attaches all relevant event listeners that forward data and errors and keep track of state. |
|
protected |
Destroys the current serialport instance. |
|
protected |
_updateState(state: String) Shortcut for updating state that changes this._state and emits a stateChange event with one call. |
Public Constructors
Private Members
Public Methods
public close(): Promise source
Closes the serialport.
Emit:
* |
stateChange(state): Serial#_state} has changed. |
* |
error(error): An error ocurred in node-serialport. |
public open(): Promise source
Opens the serialport, creating it if needed.
Emit:
* |
data(packet): New data arrived (after being parsed by Serial#_parser). |
* |
stateChange(state): Serial#_state has changed. |
* |
error(error): An error ocurred in node-serialport. |
public setPath(path: *): Promise source
Sets a new path to all future serialport instances. If a port is already open, it is automatically closed and a new one is opened with the new path (keeps event listeners).
Params:
Name | Type | Attribute | Description |
path | * |
Emit:
* |
data(packet): New data arrived (after being parsed by Serial#_parser). |
* |
stateChange(state): Serial#_state has changed. |
* |
error(error): An error ocurred in node-serialport. |
Protected Methods
protected _createPort(): Promise source
Creates the serialport instance and attaches all relevant event listeners that forward data and errors and keep track of state.
Emit:
* |
data(packet): New data arrived (after being parsed by Serial#_parser). |
* |
stateChange(state): Serial#_state has changed. |
* |
error(error): An error ocurred in node-serialport. |