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 ChoosePort(forbidden: list[str] = []) str
Systems checks user’s Operating System, and chooses ports accordingly.
- Parameters:
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:
String name of the port.
- Return type:
str
- static GetAllPortNames() list[str]
Finds all the available COM ports on the user’s computer and appends them to an accessible list.
- Returns:
List containing the names of available COM ports.
- Return type:
list[str]
- static GetSelectPortNames(forbidden: list[str] = []) list[str]
Gets the names of all available ports.
- Parameters:
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 of port names.
- Return type:
list[str]
- static _ChoosePortLinux(forbidden: list[str] = []) str
User picks Serial port in Linux.
- Parameters:
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:
String name of the port.
- Return type:
str
- static _ChoosePortWindows(forbidden: list[str] = []) str
User picks COM port in Windows.
- Parameters:
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:
String name of the port.
- Return type:
str
Morelia.Devices.SerialPorts.SerialComm module
- class Morelia.Devices.SerialPorts.SerialComm.PortIO(port: str | int, baudrate: int = 9600)
Bases:
object
COM_io handles serial communication (read/write) using COM ports.
- __serialInst
Instance-level serial COM port.
- Type:
Serial
- CloseSerialPort() None
Closes the instance serial port if it is open.
- Flush() bool
Reset the input and output serial buffer.
- Returns:
True of the buffers are flushed, False otherwise.
- Return type:
bool
- GetPortName() str | None
Gets the name of the open port.
- Returns:
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.
- Return type:
str|None
- IsSerialClosed() bool
Returns False if the serial instance port is open, True otherwise.
- Returns:
True if the COM port is closed, False otherwise.
- Return type:
bool
- IsSerialOpen() bool
Returns True if the serial instance port is open, false otherwise.
- Returns:
True if the COM port is open, False otherwise.
- Return type:
bool
- OpenSerialPort(port: str | int, baudrate: int = 9600) None
First, it closes the serial port if it is open. Then, it opens a serial port with a set baud rate.
- Parameters:
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: int, timeout_sec: int | float = 5) bytes | None
Reads a specified number of bytes from the open serial port.
- Parameters:
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:
If the serial port is open, it will return a set number of read bytes. If it is closed, it will return None.
- Return type:
bytes|None
- ReadLine() bytes | None
Reads until a new line is read from the open serial port.
- Returns:
If the serial port is open, it will return a complete read line. If closed, it will return None.
- Return type:
bytes|None
- ReadUntil(eol: bytes) bytes | None
Reads until a set character from the open serial port.
- Parameters:
eol (bytes) – end-of-line character.
- Returns:
If the serial port is open, it will return a read line ending in eol. If closed, it will return None.
- Return type:
bytes|None
- SetBaudrate(baudrate: int) bool
Sets the baud rate of the serial port
- Parameters:
baudrate (int) – Baud rate, or signals per second.
- Returns:
True if the baudrate was set, False otherwise.
- Return type:
bool
- Write(message: bytes) None
Write a set message to the open serial port.
- Parameters:
message (bytes) – byte string containing the message to write.
- __BuildPortName(port: str | int) str
Converts the port parameter into the “COM”+<number> format for Windows or “/dev/tty…”+<number> for Linux.
- Parameters:
port (str | int) – Name of a COM port. Can be an integer or string.
- Returns:
Name of the COM port.
- Return type:
str