Serial Controlller Module

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)

Initializes a new instance of the ControllerBase.

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.

Note:

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

Args:

*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.

Returns:

instance(ControllerBase): The new instance of the class that has been created.

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 the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.

Returns:

bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.