224
Functions
Include library before calling serial functions:
require('serial')
Opens given port, returns: port handle, or, in case of error, nil plus error message
port, err = serial.open(device, params)
Parameters:
device port device name, required
params parameters table, optional, (defaults are in bold):
o baudrate 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
230400
o parity "none", "even", "odd"
o databits 5, 6, 7, 8
o stopbits 1, 2
o duplex "full", "half" (Note: "half" is required for RS-485)
Reads the specified number of bytes, execution is blocked until read is complete
res, err = port:read(bytes)
Parameters:
bytes number of bytes to read
Reads until timeout occurs or the specified number of bytes is received, whichever happens
first.
Returns data plus number of bytes read, or, in case of error, nil plus error message.
res, err = port:read(bytes, timeout)
Parameters:
bytes number of bytes to read
timeout maximum time to wait for read to complete, minimum value and timer
resolution is 0.1 seconds
Flushes any read/unsent bytes
port:flush()
Closes serial port, no other port functions may be called afterwards
port:close()