CanBusListener

class mtf.network_port.bus_listener.CanBusListener
__init__(bus_name: str)
static __new__(cls, *args, **kwargs)

Initialize a new instance of the ControllerBase.

The instance will be automatically added to the list of controllers.

adapt_queue_elements() Queue[BaseEvent]

ensure the object.timestamp, object.payload

callback_(data_frame: BusEvent)
clean_up()
classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

get_queue() Queue[BusEvent]

Get the queue

register_callback(callback_fnc: Callable[[BusEvent], None])
Parameters:

callback_fnc – callback function with parameter of type BusEvent

Setting a callback
# ...
from mtf.mtf_types import BusEvent
# ...

def my_bus_event_callback(msg: BusEvent):
    # do things

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

Warning

The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.

reset()

cleanup the queue

start_listening(silent_mode: bool = False) bool
stop_listening() bool
unregister_callback(callback_fnc)
Parameters:

callback_fnc – callback function with parameter of type BusEvent

Setting a callback
# ...
from mtf.mtf_types import BusEvent
# ...

def my_bus_event_callback(msg: BusEvent):
    # do things

# ... creating listener, register callback, do work
# register our callback
listener.register_callback(my_bus_event_callback)