Members
Binding :AbstractBinding
The Binding
is how Node-SerialPort talks to the underlying system. By default, we auto detect Windows, Linux and OS X, and load the appropriate module for your system. You can assign SerialPort.Binding
to any binding you like. Find more by searching at npm.
Prevent auto loading the default bindings by requiring SerialPort with:
var SerialPort = require('@serialport/stream');
SerialPort.Binding = MyBindingClass;
Type:
- Since:
- 5.0.0
- Source:
Type Definitions
errorCallback(errornullable)
A callback called with an error or null.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
error |
error |
<nullable> |
- Source:
listCallback(errornullable, ports)
This callback type is called requestCallback
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
error |
error |
<nullable> |
|
ports |
array | an array of objects with port info |
- Source:
modemBitsCallback(errornullable, statusnullable)
A callback called with an error or an object with the modem line values (cts, dsr, dcd).
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
error |
error |
<nullable> |
|||||||||||||||||||||
status |
object |
<nullable> |
Properties
|
- Source:
openOptions
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
autoOpen |
boolean |
<optional> |
true | Automatically opens the port on |
baudRate |
number |
<optional> |
9600 | The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. |
dataBits |
number |
<optional> |
8 | Must be one of these: 8, 7, 6, or 5. |
highWaterMark |
number |
<optional> |
65536 | The size of the read and write buffers defaults to 64k. |
lock |
boolean |
<optional> |
true | Prevent other processes from opening the port. Windows does not currently support |
stopBits |
number |
<optional> |
1 | Must be one of these: 1 or 2. |
parity |
string |
<optional> |
none | Must be one of these: 'none', 'even', 'mark', 'odd', 'space'. |
rtscts |
boolean |
<optional> |
false | flow control setting |
xon |
boolean |
<optional> |
false | flow control setting |
xoff |
boolean |
<optional> |
false | flow control setting |
xany |
boolean |
<optional> |
false | flow control setting |
bindingOptions |
object |
<optional> |
sets binding-specific options |
|
Binding |
Binding |
<optional> |
The hardware access binding. |
|
bindingOptions.vmin |
number |
<optional> |
1 | see |
bindingOptions.vtime |
number |
<optional> |
0 | see |
- Source:
Parsers
The default Parsers
are Transform streams that process incoming data. To use the parsers, you must create them and then pipe the Serialport to the parser. Be careful to only write to the SerialPort object and not the parser.
Parsers are collection of transform streams to processes incoming data
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
ByteLength |
Transform | |
CCtalk |
Transform | |
Delimiter |
Transform | |
Readline |
Transform | |
Ready |
Transform | |
Regex |
Transform |
- Since:
- 5.0.0
- Source:
Example
```js
const SerialPort = require('serialport');
const Readline = SerialPort.parsers.Readline;
const port = new SerialPort('/dev/tty-usbserial1');
const parser = new Readline();
port.pipe(parser);
parser.on('data', console.log);
port.write('ROBOT PLEASE RESPOND\n');
// Creating the parser and piping can be shortened to
// const parser = port.pipe(new Readline());
```
Events
close
The close
event's callback is called with no arguments when the port is closed. In the case of a disconnect it will be called with a Disconnect Error object (err.disconnected == true
). In the event of a close error (unlikely), an error event is triggered.
- Source:
data
Listening for the data
event puts the port in flowing mode. Data is emitted as soon as it's received. Data is a Buffer
object with a varying amount of data in it. The readLine
parser converts the data into string lines. See the parsers section for more information on parsers, and the Node.js stream documentation for more information on the data event.
- Source:
error
The error
event's callback is called with an error object whenever there is an error.
- Source:
open
The open
event's callback is called with no arguments when the port is opened and ready for writing. This happens if you have the constructor open immediately (which opens in the next tick) or if you open the port manually with open()
. See Useage/Opening a Port for more information.
- Source: