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"] : a string that indicates the RTS mode, defaulting to "off" (see Port-rts.html for other possible values)
  • ["dtr"] : a string that indicates the DTR control signal, defaulting to "disabled" (see Port-dtr.html for other possible values)
  • ["baudrate"] : a number that indicates the transmission speed, defaulting to 9600 (see Port-baudrate.html for other possible values)
  • ["bytesize"] : a number that indicates the byte size, defaulting to 8 (see Port-bytesize.html for other possible values)
  • ["parity"] : a string that indicates the parity mode, defaulting to "none" (see Port-parity.html for other possible values)
  • ["stopbits"] : a string 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