serial
The serial library enables communication over the serial port.
open
, read
, write
, and close
file handling
methods, as well as serial port configuration features.
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" |
serial
serial.open(port, config) | Creates and returns a new serial device instance: #serialdev. |
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. |
config
Serial port configuration table.
Can be given to #serialdev.configure and #serial.open functions:
config.baudRate
9600, 19200, 38400, 57600
and 115200
(as an integer).
config.flowControl
"none"
, "rtscts"
or "xon/xoff"
(as a string).
config.numDataBits
5, 6, 7
and 8
(as an integer).
config.numStopBits
1
to disable it, 2
to enable it (as an integer).
config.parity
"none"
, "odd"
, "even"
serial
serial.open(port, config)
port
:
the serial port to open. It can be given as a port number,
or as a POSIX device file path such as "/dev/ttyS0"
on POSIX operating
systems.
config
:
an optional #config table. { parity = "none", flowControl = "none", numDataBits = 8, numStopBits = 1, baudRate = 115200 }
nil
followed by an error message otherwise
serialdev
Serial class.
serialdev:close()
"ok"
on success.
nil
followed by an error message otherwise.
serialdev:configure(config)
config
:
a #config table.
"ok"
on success.
nil
followed by error string otherwise.
serialdev:flush()
"ok"
on success.
nil
followed by an error message otherwise.
serialdev:read(pattern)
pattern
:
can be a pattern string conforming to the
Lua File API,
or a number of bytes to read.
nil
followed by error string otherwise.
serialdev:write(buffer)
buffer
:
string containing data to send over the serial port.
nil
followed by an error message otherwise.