Port:open([state]) method
Open the Port for serial communication with another connected device.
Parameters
[state]
An optional table
to configure the serial communication, using the following optional fields :
["rts"]
: astring
that indicates the RTS mode, defaulting to"off"
(see Port-rts.html for other possible values)["dtr"]
: astring
that indicates the DTR control signal, defaulting to"disabled"
(see Port-dtr.html for other possible values)["baudrate"]
: anumber
that indicates the transmission speed, defaulting to9600
(see Port-baudrate.html for other possible values)["bytesize"]
: anumber
that indicates the byte size, defaulting to8
(see Port-bytesize.html for other possible values)["parity"]
: astring
that indicates the parity mode, defaulting to"none"
(see Port-parity.html for other possible values)["stopbits"]
: astring
that indicates the stop bits mode, defaulting to"one"
(see Port-stopbits.html for other possible values)
Return value
Returns true if serial Port has been successfully opened.In case of error, returns false. Error message can be obtained with the sys.error property.
Example
local serial = require "serial"
local COM1 = serial.Port("COM1")
if COM1:open() then
print("COM1 serial port is now open")
else
print("Failed to open COM1 serial port")
end