ioBuster framework v25.02.4 documentation


serialport

serialport

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:

  • ftdi
  • tty
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:

  • ftdi
  • tty
options serialport.FtdiOpenOptions | serialport.TtyOpenOptions

Serial port open options.

The following options are common across all serial port types:

Properties
Name Type Attributes Default Description
baudRate number

Baud Rate.

newline string <optional>
'\r\n'

Used in sendLine function.

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
Name Type Attributes Default Description
protocol string <optional>
null

transfer protocol Supported protocols

  • ymodem
timeoutMs number <optional>
30000

Y Modem timeout (ms)

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
Name Type Attributes Default Description
patterns Array

Pattern list. Each pattern should be a string or a RegExp.

timeoutMs number <optional>
30000

Timeout (ms)

flushBeforeWait boolean <optional>
false

To flush Rx Buffer before wait. if true, it finds patterns after flushing the previous Rx buffer.

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.

  • FTDI Vendor ID: 0x0403
options.product Number

FTDI product ID.

Product Number list:

  • FT232BM/L/Q, FT245BM/L/Q: 0x6001
  • FT232RL/Q, FT245RL/Q: 0x6001
  • FT2232C/D/L: 0x6010
  • FT2232HL/Q: 0x6010
  • FT4232HL/Q: 0x6011
  • FT232HL/Q: 0x6014
  • VNC1L with VDPS Firmware: 0x6001
  • VNC2 with FT232Slave: 0x6001
options.interface Number

FTDI interface.

Interface List:

  • INTERFACE_ANY: 0x0
  • INTERFACE_A: 0x1
  • INTERFACE_B: 0x2
  • INTERFACE_C: 0x3
  • INTERFACE_D: 0x4
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