Serial Controlller Module

mtf.network_port.serial_controlller.safe_decode(msg)

Decode safely the serial lisener messages

Args:

msg (str or list[int]): The serial message

Returns:

str or bytes: The decoded message

class mtf.network_port.serial_controlller.SerialTransmitter
transmitter
classmethod transmit_message(channel_name: str, message: str)
class mtf.network_port.serial_controlller.SerialListener
__init__(channel_name: str)
get_queue() Queue[SerialEvent]

Get the queue

reset()

cleanup the queue

start_listening(keep_cache: bool = False, silent_mode: bool = True, get_messages_as_string: bool = True) bool
stop_listening() bool
register_callback(callback_fnc: Callable[[SerialEvent], None])

Register a callback function that will be triggered when a Serial event occurs.

Parameters:

callback_fnc – Callback function with parameters (event: SerialEvent)

Setting a callback
def my_callback(event: SerialEvent):
    # do things

# ... creating listener
# register our callback
listener.register_callback(my_callback)

Warning

The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically.

unregister_callback(callback_fnc: Callable[[SerialEvent], None])

Unregister a previously registered callback function.

Parameters:

callback_fnc – Callback function with parameters (event: SerialEvent)

adapt_queue_elements() Queue[BaseEvent]

ensure the object.timestamp, object.payload

static __new__(cls, *args, **kwargs)

Creates a new instance.

Args:

*args: The variable arguments list. **wargs: The keyword arguments list.

Returns:

ControllersBase: The newly created instance.

Note:

Note

The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.

Important

Do not override this method in subclasses to maintain this functionality.

clean_up()

This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.

Returns:

bool: Returns True if the cleanup is successfully done. False if an exception occurs.

classmethod controllers_cleanup()

Cleans up all controller instances.

It calls clean_up() for each controller in the list. If a cleanup fails, an error is raised, but the method continues processing the remaining controllers.

Returns:
bool: True indicating that all controllers were cleaned up successfully.

Otherwise, False is returned when an error occurs during the cleanup process.

set_queue_size(max_size: int)

This call of set queue size will clear the queue and resize it better to call it at the beginning : before start listening if max_size <= 0 the queue size is infinite