Module serial The serial library enables communication over the serial port.
It provides the usual open, read, write, and close file handling methods, as well as serial port configuration features.

Type config

config.baudRate to set the baudrate of the serial port
accepted values are: 9600, 19200, 38400, 57600 and 115200 (as an integer).
config.flowControl to configure flow control on the serial port
accepted values are: "none", "rtscts" or "xon/xoff" (as a string).
config.numDataBits to set the number of data bits in each character
accepted values are: 5, 6, 7 and 8 (as an integer).
config.numStopBits to configure the serial port stop bit
accepted values are: 1 to disable it, 2 to enable it (as an integer).
config.parity to set serial port parity
accepted values are (as a string): "none", "odd", "even"

Type serial

serial.open(port, config) Creates and returns a new serial device instance: #serialdev.

Type serialdev

serialdev:close() Closes the serial library instance.
serialdev:configure(config) Configures the serial port.
serialdev:flush() Flushes pending data.
serialdev:read(pattern) Reads data from the serial port.
serialdev:write(buffer) Writes buffer to the serial port.

Type config

Serial port configuration table.

Can be given to #serialdev.configure and #serial.open functions:

Field(s)

config.baudRate

to set the baudrate of the serial port
accepted values are: 9600, 19200, 38400, 57600 and 115200 (as an integer).

config.flowControl

to configure flow control on the serial port
accepted values are: "none", "rtscts" or "xon/xoff" (as a string).

config.numDataBits

to set the number of data bits in each character
accepted values are: 5, 6, 7 and 8 (as an integer).

config.numStopBits

to configure the serial port stop bit
accepted values are: 1 to disable it, 2 to enable it (as an integer).

config.parity

to set serial port parity
accepted values are (as a string): "none", "odd", "even"

Type serial

Field(s)

serial.open(port, config)

Creates and returns a new serial device instance: #serialdev.

Parameters

Return values

  1. #serialdev: a new instance of #serialdev as a table when successful
  2. nil followed by an error message otherwise

Type serialdev

Serial class.

Field(s)

serialdev:close()

Closes the serial library instance.
Once close has been successfully called, the serialdev instance becomes unusable. A new one may be created if needed.

Return values

  1. "ok" on success.
  2. nil followed by an error message otherwise.

serialdev:configure(config)

Configures the serial port.

Parameter

Return values

  1. "ok" on success.
  2. nil followed by error string otherwise.

serialdev:flush()

Flushes pending data.

Return values

  1. "ok" on success.
  2. nil followed by an error message otherwise.

serialdev:read(pattern)

Reads data from the serial port.

Parameter

Return values

  1. the read data, as a string, on success.
  2. nil followed by error string otherwise.

serialdev:write(buffer)

Writes buffer to the serial port.

Parameter

Return values

  1. the number of bytes written on success.
  2. nil followed by an error message otherwise.