Morelia.Devices.SerialPorts package

Submodules

Morelia.Devices.SerialPorts.PortAccess module

class Morelia.Devices.SerialPorts.PortAccess.FindPorts

Bases: object

Contains methods for the user to view and select a serial port.

static choose_port(forbidden=[])

Systems checks user’s Operating System, and chooses ports accordingly.

Return type:

str

Args:

forbidden (list[str], optional): List of port names that the user should not use. This may be because these ports are already in use or that the port is not a POD device. Defaults to [].

Returns:

str: String name of the port.

static get_all_port_names()

Finds all the available COM ports on the user’s computer and appends them to an accessible list.

Return type:

list[str]

Returns:

list[str]: List containing the names of available COM ports.

static get_select_port_names(forbidden=[])

Gets the names of all available ports.

Return type:

list[str]

Args:

forbidden (list[str], optional): List of port names that the user should not use. This may be because these ports are already in use or that the port is not a POD device. Defaults to [].

Returns:

list[str]: List of port names.

Morelia.Devices.SerialPorts.SerialComm module

class Morelia.Devices.SerialPorts.SerialComm.PortIO(port, baudrate=9600)

Bases: object

COM_io handles serial communication (read/write) using COM ports.

Attributes:

__serial_inst (Serial): Instance-level serial COM port.

close_serial_port()

Closes the instance serial port if it is open.

Return type:

None

flush()

Reset the input and output serial buffer.

Return type:

bool

Returns:

bool: True of the buffers are flushed, False otherwise.

get_port_name()

Gets the name of the open port.

Return type:

str | None

Returns:

str|None: If the serial port is open, it will return a string of the port’s name. If the port is closed, it will return None.

is_serial_closed()

Returns False if the serial instance port is open, True otherwise.

Return type:

bool

Returns:

bool:True if the COM port is closed, False otherwise.

is_serial_open()

Returns True if the serial instance port is open, false otherwise.

Return type:

bool

Returns:

bool: True if the COM port is open, False otherwise.

open_serial_port(port, baudrate=9600)

First, it closes the serial port if it is open. Then, it opens a serial port with a set baud rate.

Return type:

None

Args:

port (str | int): String of the serial port to be opened. baudrate (int, optional): Integer baud rate of the opened serial port. Defaults to 9600.

Raises:

Exception: Port does not exist.

read(numBytes, timeout_sec=5)

Reads a specified number of bytes from the open serial port.

Return type:

bytes | None

Args:

numBytes (int): Integer number of bytes to read. timeout_sec (int|float, optional): Time in seconds to wait for serial data. Defaults to 5.

Raises:

Exception: Timeout for serial read.

Returns:

bytes|None: If the serial port is open, it will return a set number of read bytes. If it is closed, it will return None.

read_line()

Reads until a new line is read from the open serial port.

Return type:

bytes | None

Returns:

bytes|None: If the serial port is open, it will return a complete read line. If closed, it will return None.

read_until(eol)

Reads until a set character from the open serial port.

Return type:

bytes | None

Args:

eol (bytes): end-of-line character.

Returns:

bytes|None: If the serial port is open, it will return a read line ending in eol. If closed, it will return None.

set_baudrate(baudrate)

Sets the baud rate of the serial port

Return type:

bool

Args:

baudrate (int): Baud rate, or signals per second.

Returns:

bool: True if the baudrate was set, False otherwise.

write(message)

Write a set message to the open serial port.

Return type:

None

Args:

message (bytes): byte string containing the message to write.

Module contents