serial_communicator Module

Communicator for Serial Communication

class CommunicatorCommon.serial_communicator.SerialCommunicator(port: str = 'dev/ttyACM0', baud_rate: int = 9600)

Bases: object

A class for communicating through a serial port.

__init__(port: str = 'dev/ttyACM0', baud_rate: int = 9600) None

Initialize the SerialCommunicator class.

Parameters:
  • port (str) – The name of the serial port to connect to.

  • "dev/ttyACM0". (Default is)

  • baud_rate (int) – The baud rate for the serial communication.

  • 9600. (Default is)

send_msg(message: str) None

Send a message through the serial port.

Parameters:

message (str) – The message to be sent.

receive_msg(timeout: float | None = None) str | None

Receive a message from the serial port.

Parameters:
  • timeout (Optional[float]) – Timeout in seconds for the operation.

  • provided (If not)

  • timeout. (there is no)

Returns:

The received message, or None if timeout is reached.

Return type:

str

Note

The function sets a temporary timeout for this specific read operation, if provided, and restores the original timeout after.

close() None

Close the serial connection.