1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
Notifier and Listeners
======================
.. _notifier:
Notifier
--------
The Notifier object is used as a message distributor for a bus. The Notifier
uses an event loop or creates a thread to read messages from the bus and
distributes them to listeners.
.. autoclass:: can.Notifier
:members:
.. _listeners_doc:
Listener
--------
The Listener class is an "abstract" base class for any objects which wish to
register to receive notifications of new messages on the bus. A Listener can
be used in two ways; the default is to **call** the Listener with a new
message, or by calling the method **on_message_received**.
Listeners are registered with :ref:`notifier` object(s) which ensure they are
notified whenever a new message is received.
.. literalinclude:: ../examples/print_notifier.py
:language: python
:linenos:
:emphasize-lines: 8,9
Subclasses of Listener that do not override **on_message_received** will cause
:class:`NotImplementedError` to be thrown when a message is received on
the CAN bus.
.. autoclass:: can.Listener
:members:
There are some listeners that already ship together with `python-can`
and are listed below.
Some of them allow messages to be written to files, and the corresponding file
readers are also documented here.
.. note ::
Please note that writing and the reading a message might not always yield a
completely unchanged message again, since some properties are not (yet)
supported by some file formats.
.. note ::
Additional file formats for both reading/writing log files can be added via
a plugin reader/writer. An external package can register a new reader
by using the ``can.io.message_reader`` entry point. Similarly, a writer can
be added using the ``can.io.message_writer`` entry point.
The format of the entry point is ``reader_name=module:classname`` where ``classname``
is a :class:`can.io.generic.BaseIOHandler` concrete implementation.
::
entry_points={
'can.io.message_reader': [
'.asc = my_package.io.asc:ASCReader'
]
},
BufferedReader
--------------
.. autoclass:: can.BufferedReader
:members:
.. autoclass:: can.AsyncBufferedReader
:members:
RedirectReader
--------------
.. autoclass:: can.RedirectReader
:members:
|