serial

Provides methods for working with serial ports.

Methods

list()→ {undefined}

Returns list of available ports.

See https://github.com/EmergingTechnologyAdvisors/node-serialport#module_serialport--SerialPort.list for details about the structure of returned values.
Returns:
{0} - Array of port descriptions.

open(port, opts, bufferSize)→ {SerialPort}

Opens a serial port.

Data from the opened port will be automatically read line by line into a circular buffer. Once the buffer reaches it's maximum capacity specified by `bufferSize` argument, eldest entries are evicted to make room for new data.


Serial port properties with default values

{
  baudRate: 9600,
  dataBits: 8,        // Must be one of: 8, 7, 6, or 5.
  stopBits: 1,        // Must be one of: 1 or 2.
  parity: 'none'      // Must be one of: 'none', 'even', 'mark', 'odd', 'space'.
  rtscts: false,
  xon: false,
  xoff: false,
  xany: false
}
Parameters:
Name Type Description
port String Path to serial port. E.g. '/dev/tty-usbserial1', 'COM5', etc.
opts Object Port properties.
bufferSize Integer optionalSize of the input data buffer. Default is 65536 bytes.
Returns:
SerialPort - SerialPort object.

waitForText(pattern, timeout)

Waits for text to appear in the input data buffer.

Text pattern can be any of the supported string matching patterns.
Parameters:
Name Type Description
pattern String Text pattern.
timeout Integer optionalTimeout in milliseconds. Default is 60 seconds.

write(data)

Write data to the port.
Parameters:
Name Type Description
data {1} Data to send. Either a string or an array of bytes.