Collection of serial port functions
Methods
(static) close(devIdx)
Close a serial port.
Parameters:
Name | Type | Description |
---|---|---|
devIdx |
number | Serial port device index. |
(static) flushReadBuffer(devIdx, offsetopt)
Flush the read buffer for the given devIdx.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
devIdx |
Number | Serial port device index |
||
offset |
Number |
<optional> |
0
|
If non-zero value is set, only specific number of bytes will flushed from the beginning. |
(static) getDeviceList(type) → {Array.<serialport.FtdiDeviceInfo>|Array.<serialport.TtyDeviceInfo>}
Returns all available serial ports
Parameters:
Name | Type | Description |
---|---|---|
type |
string | Serial port type. Available serial port types:
|
Returns:
- Type
- Array.<serialport.FtdiDeviceInfo> | Array.<serialport.TtyDeviceInfo>
(static) getReadBuffer(devIdx, lastLinesopt) → {String}
Read the read buffer for the given devIdx.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
devIdx |
Number | Serial port device index |
||
lastLines |
Number |
<optional> |
0
|
If non-zero value is set, only specific number of lines will be returned. |
Returns:
- Type
- String
(static) open(type, options) → {number}
Open a serial port device
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
string | Serial port type. Available serial port types:
|
|||||||||||||||
options |
serialport.FtdiOpenOptions | serialport.TtyOpenOptions | Serial port open options. The following options are common across all serial port types: Properties
|
Returns:
Device index.
- Type
- number
(static) pipe(devIdx, logname)
Continuously data read from a serial port to a file.
Example
logger.create('serial', 'serial.log')
serialport.pipe(index, 'serial')
Parameters:
Name | Type | Description |
---|---|---|
devIdx |
number | Serial port device index. |
logname |
string | Log descriptor name for a logger. |
(static) send(devIdx, message, flushBeforeSendopt)
Send a message to a serial port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
devIdx |
number | Serial port device index. |
||
message |
string | Buffer | A message to write |
||
flushBeforeSend |
boolean |
<optional> |
false
|
To flush Rx Buffer before send. |
(static) sendFile(devIdx, path, options) → {number}
Send a file to a serial port.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
devIdx |
number | Serial port device index. |
|||||||||||||||
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(devIdx, message, flushBeforeSendopt)
Send a message with a newline character to a serial port.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
devIdx |
number | Serial port device index. |
||
message |
string | A message to write |
||
flushBeforeSend |
boolean |
<optional> |
false
|
To flush Rx Buffer before send. |
(static) unpipe(devIdx)
Stop sending read data to a file.
Parameters:
Name | Type | Description |
---|---|---|
devIdx |
number | Serial port device index. |
(static) wait(devIdx, 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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
devIdx |
number | Serial port device index. |
||||||||||||||||||||
options |
object | Pattern options. Properties
|
Returns:
A matched pattern(string pattern) or matched patterns(RegExp pattern).
- Type
- string | array
Type Definitions
FtdiDeviceInfo
Properties:
Name | Type | Description |
---|---|---|
vendorId |
Number | Vendor ID |
productId |
Number | Product ID |
description |
String | Product Description |
serial |
String | Serial Number |
vendor |
String | Vendor Description |
Type:
- Object
FtdiOpenOptions
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options.vendor |
Number | FTDI vendor ID.
|
||
options.product |
Number | FTDI product ID. Product Number list:
|
||
options.interface |
Number | FTDI interface. Interface List:
|
||
options.description |
Number |
<optional> |
FTDI description string. |
|
options.serial |
Number |
<optional> |
FTDI serial string. |
|
options.readInterval |
Number |
<optional> |
50
|
Poll interval for serial port read (ms). |
Type:
- Object
TtyDeviceInfo
Properties:
Name | Type | Description |
---|---|---|
devicePath |
Number | Serial Number |
serial |
Number | Vendor Description |
interfaceNumber |
Number | Vendor Description |
Type:
- Object
TtyOpenOptions
Properties:
Name | Type | Description |
---|---|---|
options.devicePath |
String | Serial Port device path |
options.serial |
String | Serial Port USB serial number |
options.interfaceNumber |
Number | Serial Port USB interface number |
Type:
- Object