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.

class can.Listener[source]

Bases: object


Override to cleanup any open resources.


class can.BufferedReader[source]

Bases: can.CAN.Listener

A BufferedReader is a subclass of Listener which implements a message buffer: that is, when the can.BufferedReader instance is notified of a new message it pushes it into a queue of messages waiting to be serviced.


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 Message if there is one, or None if there is not.


class can.Logger[source]

Bases: object

Logs CAN messages to a file.

The format is determined from the file format which can be one of:


class can.Printer(output_file=None)[source]

Bases: can.CAN.Listener

The Printer class is a subclass of Listener which simply prints any messages it receives to the terminal.

Parameters:output_file – An optional file to “print” to.

CSVWriter & SqliteWriter

These Listeners simply create csv and sql files with the messages received.

class can.CSVWriter(filename)[source]

Bases: can.CAN.Listener

Writes a comma separated text file of timestamp, arbitrationid, flags, dlc, data for each messages received.

class can.SqliteWriter(filename)[source]

Bases: can.CAN.Listener

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.


Logs CAN data to an ASCII log file compatible with other CAN tools such as Vector CANalyzer/CANoe and other. Since no official specification exists for the format, it has been reverse- engineered from existing log files. One description of the format can be found here.

class can.ASCWriter(filename)[source]

Bases: can.CAN.Listener

Logs CAN data to an ASCII log file (.asc)


Stops logging and closes the file.