Collection of serial port functions
Methods
(static) close(portIdentifier)
Close a serial port.
Parameters:
Name | Type | Description |
---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
(static) flushReadBuffer(portIdentifier, offsetopt)
Flush the read buffer for the given port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
portIdentifier |
Number | String | Serial port device index or string ID |
||
offset |
Number |
<optional> |
0
|
If non-zero value is set, only specific number of bytes will flushed from the beginning. |
(static) getDeviceList() → {Array.<serialport.SerialPortDeviceInfo>}
Returns all available serial ports
Returns:
- Type
- Array.<serialport.SerialPortDeviceInfo>
(static) getEnumeratedPorts() → {Promise.<Array>}
Get enumerated ports with metadata and string IDs
Returns:
Array of discovered port information from DeviceManager
- Type
- Promise.<Array>
(static) getReadBuffer(portIdentifier, lastLinesopt) → {String}
Read the read buffer for the given port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
portIdentifier |
Number | String | Serial port device index or string ID |
||
lastLines |
Number |
<optional> |
0
|
If non-zero value is set, only specific number of lines will be returned. |
Returns:
- Type
- String
(static) open(options) → {number}
Open a serial port device
Parameters:
Name | Type | Description |
---|---|---|
options |
serialport.SerialPortOpenOptions | Options object for TTY port |
Returns:
Device index
- Type
- number
(static) pipe(portIdentifier, logname)
Continuously data read from a serial port to a file.
Example
logger.create('serial', 'serial.log')
serialport.pipe('debug0', 'serial')
Parameters:
Name | Type | Description |
---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
logname |
string | Log descriptor name for a logger. |
(static) send(portIdentifier, message, flushBeforeSendopt)
Send a message to a serial port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
||
message |
string | Buffer | A message to write |
||
flushBeforeSend |
boolean |
<optional> |
false
|
To flush Rx Buffer before send. |
(static) sendFile(portIdentifier, path, options) → {number}
Send a file to a serial port.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
|||||||||||||||
path |
string | A file path. This path is relative to the current script path. |
|||||||||||||||
options |
object | Send options. Properties
|
Returns:
The number of transferred bytes
- Type
- number
(static) sendLine(portIdentifier, message, flushBeforeSendopt)
Send a message with a newline character to a serial port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
||
message |
string | A message to write |
||
flushBeforeSend |
boolean |
<optional> |
false
|
To flush Rx Buffer before send. |
(static) unpipe(portIdentifier)
Stop sending read data to a file.
Parameters:
Name | Type | Description |
---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
(static) wait(portIdentifier, options) → {string|array}
Wait matched patterns from serial.
If matched with RegExp, it returns an array of matched patterns. If matched with string, it returns the pattern.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
portIdentifier |
number | string | Serial port device index or string ID. |
||||||||||||||||||||
options |
object | Pattern options. Properties
|
Returns:
A matched pattern(string pattern) or matched patterns(RegExp pattern).
- Type
- string | array
Type Definitions
SerialPortDeviceInfo
Properties:
Name | Type | Description |
---|---|---|
devicePath |
String | Device path |
serial |
String | Serial number |
interfaceNumber |
Number | Interface number |
Type:
- Object
SerialPortOpenOptions
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
baudRate |
Number | Baud Rate |
||
devicePath |
String |
<optional> |
Serial Port device path |
|
serial |
String |
<optional> |
Serial Port USB serial number |
|
interfaceNumber |
Number |
<optional> |
Serial Port USB interface number |
|
newline |
String |
<optional> |
'\r\n'
|
Used in sendLine function |
Type:
- Object