Listeners¶
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 Notifier object(s) which ensure they are notified whenever a new message is received.
Subclasses of Listener that do not override on_message_received will cause NotImplementedError to be thrown when a message is received on the CAN bus.
BufferedReader¶
-
class
can.BufferedReader¶ A BufferedReader is a subclass of
Listenerwhich implements a message buffer: that is, when thecan.BufferedReaderinstance is notified of a new message it pushes it into a queue of messages waiting to be serviced.-
get_message(timeout=0.5)¶ Attempts to retrieve the latest message received by the instance. If no message is available it blocks for given timeout or until a message is received (whichever is shorter),
Parameters: timeout (float) – The number of seconds to wait for a new message. Returns: the Messageif there is one, or None if there is not.
-
Logger¶
-
class
can.Logger¶ Logs CAN messages to a file.
- The format is determined from the file format which can be one of:
- .asc:
can.ASCWriter - .csv:
can.CSVWriter - .db:
can.SqliteWriter - other:
can.Printer
- .asc:
Printer¶
CSVWriter & SqliteWriter¶
These Listeners simply create csv and sql files with the messages received.
-
class
can.CSVWriter(filename)¶ Writes a comma separated text file of timestamp, arbitrationid, flags, dlc, data for each messages received.
-
class
can.SqliteWriter(filename)¶ Logs received CAN data to a simple SQL database.
The sqlite database may already exist, otherwise it will be created when the first message arrives.