Bus Listener Module

class mtf.network_port.bus_listener.BusListener

Listening to frames on a specific communication bus

__init__(bus_name: str, *args, **kwargs)
get_queue() Queue[BusEvent]

Return the queue containing the events or messages related to the communication bus Return:

Queue[BusEvent]

reset()

Reset the state of the bus listener by clearing its history and emptying the event queue

start_listening(silent_mode: bool = False) bool

Start listening for events on a communication bus Args:

silent_mode (bool): Specify whether the listening should be done in silent mode or not

Return:

bool

stop_listening() bool

Stop listening for events on a communication bus Return:

bool

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.

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)
callback_(data_frame: BusEvent)

used as a callback function when an event or frame is received on the communication bus Args:

data_frame (BusEvent): The data frame

clean_up()

Clean up all controller instances.

Return:

bool

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

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

class mtf.network_port.bus_listener.CanBusListener

Manage event listening on a CAN bus

__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)

used as a callback function when an event or frame is received on the communication bus Args:

data_frame (BusEvent): The data frame

clean_up()

Clean up all controller instances.

Return:

bool

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

get_queue() Queue[BusEvent]

Return the queue containing the events or messages related to the communication bus Return:

Queue[BusEvent]

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()

Reset the state of the bus listener by clearing its history and emptying the event queue

start_listening(silent_mode: bool = False) bool

Start listening for events on a communication bus Args:

silent_mode (bool): Specify whether the listening should be done in silent mode or not

Return:

bool

stop_listening() bool

Stop listening for events on a communication bus Return:

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)
class mtf.network_port.bus_listener.LinBusListener

Manage event listening on a LIN bus

__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)

used as a callback function when an event or frame is received on the communication bus Args:

data_frame (BusEvent): The data frame

clean_up()

Clean up all controller instances.

Return:

bool

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

get_queue() Queue[BusEvent]

Return the queue containing the events or messages related to the communication bus Return:

Queue[BusEvent]

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()

Reset the state of the bus listener by clearing its history and emptying the event queue

start_listening(silent_mode: bool = False) bool

Start listening for events on a communication bus Args:

silent_mode (bool): Specify whether the listening should be done in silent mode or not

Return:

bool

stop_listening() bool

Stop listening for events on a communication bus Return:

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)
class mtf.network_port.bus_listener.IoListener

Manage event listening on a IO bus

__init__(bus_name: str)
property last_value

Returns a deep copy of the last value in a queue

adapt_queue_elements() Queue[BaseEvent]

ensure the object.timestamp, object.payload

get_queue() Queue[IoEvent]

Return the queue containing the events or messages related to the IO communication bus Return:

Queue[IoEvent]

register_callback(callback_fnc)
Parameters:

callback_fnc – callback function with parameter of type IoEvent

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

def my_callback(msg: IoEvent):
    # 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. 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.

unregister_callback(callback_fnc)
Parameters:

callback_fnc – callback function with parameter of type BusEvent, which has been registered

:Example def io_listener_callabck(io_event :IoEvent)

callback_(io_event: IoEvent)

used as a callback function when an event or frame is received on the communication bus Args:

data_frame (BusEvent): The data frame

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

Initialize a new instance of the ControllerBase.

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

clean_up()

Clean up all controller instances.

Return:

bool

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

reset()

Reset the state of the bus listener by clearing its history and emptying the event queue

start_listening(silent_mode: bool = False) bool

Start listening for events on a communication bus Args:

silent_mode (bool): Specify whether the listening should be done in silent mode or not

Return:

bool

stop_listening() bool

Stop listening for events on a communication bus Return:

bool

class mtf.network_port.bus_listener.FlexrayBusListener

Manage event listening on a Flexray bus

__init__(bus_name: str)
get_queue() Queue[FlexrayBusEvent]

Return the queue containing the events or messages related to the Flexray communication bus Return:

Queue[FlexrayBusEvent]

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

callback_fnc – callback function with parameter of type FlexrayBusEvent

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

def my_callback(msg: FlexrayBusEvent):
    # 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. 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.

unregister_callback(callback_fnc)
Parameters:

callback_fnc – callback function with parameter of type FlexrayBusEvent, which has been registered

:Example def flexray_bus_listener_callabck(data_frame :FlexrayBusEvent)

callback_(data_frame: BusEvent)

used as a callback function when an event or frame is received on the communication bus Args:

data_frame (BusEvent): The data frame

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

clean_up()

Clean up all controller instances.

Return:

bool

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.

reset()

Reset the state of the bus listener by clearing its history and emptying the event queue

start_listening(silent_mode: bool = False) bool

Start listening for events on a communication bus Args:

silent_mode (bool): Specify whether the listening should be done in silent mode or not

Return:

bool

stop_listening() bool

Stop listening for events on a communication bus Return:

bool

class mtf.network_port.bus_listener.LegacyBusesListener
__init__(channels_name: set[str])
get_history() list[BusEvent]
start_listening(direction: ~mtf.libs.mtf_pybinder.ListenerDirection = <ListenerDirection.Any: 2>, silent_mode: bool = False) bool
stop_listening() bool
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.

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)
callback_(data_frame: BusEvent)
static __new__(cls, *args, **kwargs)

Initialize a new instance of the ControllerBase.

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

clean_up() bool

Clean up all controller instances.

Return:

bool

classmethod controllers_cleanup()

Clean up all controller instances.

Calls the clean_up() method for each instance.