Skip to content

Serial Interface

The Serial Interface is used to access serial port.

SerialInterface

Provides a serial/UART interface

Methods:

Name Description
__init__

Create and open a new serial port interface. If the port could not be opened,

close

Close the serial port interface.

flush_input

Flush the input buffer.

flush_output

Flush the output buffer.

in_waiting

Return the number of bytes currently in the input buffer.

read

Read data from the serial interface.

write

Write data to the serial interface.

__init__(port, baudrate=9600, bytesize=SerialByteSize.EIGHT, parity=SerialParity.NONE, stopbits=SerialStopBits.ONE, read_timeout=None, write_timeout=None, sw_flow_control=False, hw_rtscts_flow_control=False, hw_dsrdtr_flow_control=False)

Create and open a new serial port interface. If the port could not be opened, a SerialInterfaceException is thrown

Parameters:

Name Type Description Default
port str

Name of the port to open

required
baudrate int

Baudrate of the port (9600 by default)

9600
bytesize SerialByteSize

Size, in bits, of a byte

EIGHT
parity SerialParity

Parity checking value

NONE
stopbits SerialStopBits

Number of stopbits

ONE
read_timeout float

Timeout of read operations (in seconds). None for infinite timeout; 0 for non-blocking.

None
write_timeout float

Timeout of write operations (in seconds). Defaults to blocking.

None
sw_flow_control bool

Enables software flowcontrol

False
hw_rtscts_flow_control bool

Enables hardware RTS/CTS flowcontrol

False
hw_dsrdtr_flow_control bool

Enables hardware DSR/DTR flowcontrol

False

close()

Close the serial port interface.

flush_input()

Flush the input buffer.

flush_output()

Flush the output buffer.

in_waiting()

Return the number of bytes currently in the input buffer.

read(size=1)

Read data from the serial interface.

Parameters:

Name Type Description Default
size int

Number of bytes to read (defaults to 1).

1

Returns:

Type Description
bytes

Bytes read from the serial interface (or None in case of error).

write(data)

Write data to the serial interface.

Parameters:

Name Type Description Default
data bytes | bytearray

Data to write to port

required

Returns:

Type Description
int

Number of bytes written to port.