Asyncio support¶
│ │ │ -The asyncio
module built into Python 3.4 and later can be used to write
│ │ │ +
The asyncio
module built into Python 3.4 and later can be used to write
│ │ │ asynchronous code in a single thread. This library supports receiving messages
│ │ │ asynchronously in an event loop using the can.Notifier
class.
There will still be one thread per CAN bus but the user application will execute │ │ │ entirely in the event loop, allowing simpler concurrency without worrying about │ │ │ threading issues. Interfaces that have a valid file descriptor will however be │ │ │ supported natively without a thread.
│ │ │You can also use the can.AsyncBufferedReader
listener if you prefer
│ │ ├── ./usr/share/doc/python-can-doc/html/bcm.html
│ │ │ @@ -330,15 +330,15 @@
│ │ │
The class based api for the broadcast manager uses a series of
│ │ │ mixin classes.
│ │ │ All mixins inherit from CyclicSendTaskABC
│ │ │ which inherits from CyclicTask
.
-
│ │ │
-
│ │ │ class
can.broadcastmanager.
CyclicTask
[source]¶
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
Abstract Base for all cyclic tasks.
│ │ │-
│ │ │
-
│ │ │
stop
()[source]¶
│ │ │ Cancel this periodic task.
│ │ ││ │ │
│ │ │ @@ -359,15 +359,15 @@ │ │ │ Message send task with defined period
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ @@ -378,16 +378,16 @@ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- message (can.Message) – The message to be sent periodically. │ │ │ -
- period (float) – The rate in seconds at which to send the message. │ │ │ +
- period (float) – The rate in seconds at which to send the message. │ │ │
Message send task with a defined duration and period.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ @@ -401,17 +401,17 @@ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- message (can.Message) – The message to be sent periodically. │ │ │ -
- period (float) – The rate in seconds at which to send the message. │ │ │ -
- duration (float) – The duration to keep sending this message at given rate. │ │ │ +
- period (float) – The rate in seconds at which to send the message. │ │ │ +
- duration (float) – The duration to keep sending this message at given rate. │ │ │
│ │ │
│ │ │ │ │ │ │ │ │ @@ -422,15 +422,15 @@ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │ │ │ │Adds support for modifying a periodic message
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- message (can.Message) – The message to be sent periodically. │ │ │ -
- period (float) – The rate in seconds at which to send the message. │ │ │ +
- period (float) – The rate in seconds at which to send the message. │ │ │
-
│ │ │
-
│ │ │ @@ -457,15 +457,15 @@
│ │ │
Adds support for restarting a stopped cyclic task
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- message (can.Message) – The message to be sent periodically. │ │ │ -
- period (float) – The rate in seconds at which to send the message. │ │ │ +
- period (float) – The rate in seconds at which to send the message. │ │ │
-
│ │ │ @@ -490,15 +490,15 @@
│ │ │
│ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- bus (can.BusABC) – A CAN bus which supports sending. │ │ │
- message (can.Message) – Message to send periodically. │ │ │ -
- period (float) – The minimum time between sending messages. │ │ │ +
- period (float) – The minimum time between sending messages. │ │ │
│ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/bus.html │ │ │ @@ -73,44 +73,44 @@ │ │ │ as it handles generic tasks like applying filters. │ │ │Returns: │ │ │A started task instance
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- channel – The can interface identifier. Expected type is backend dependent. │ │ │ -
- can_filters (list) – See
set_filters()
for details.
│ │ │ - - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │ +
- can_filters (list) – See
set_filters()
for details.
│ │ │ + - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │
│ │ │API¶
│ │ │-
│ │ │
-
│ │ │ class
can.
BusABC
(channel, can_filters=None, **kwargs)[source]¶
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
The CAN Bus Abstract Base Class that serves as the basis │ │ │ for all concrete interfaces.
│ │ │This class may be used as an iterator over the received messages.
│ │ │Construct and open a CAN bus instance of the specified type.
│ │ │Subclasses should call though this method with all given parameters │ │ │ as it handles generic tasks like applying filters.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- channel – The can interface identifier. Expected type is backend dependent. │ │ │ -
- can_filters (list) – See
set_filters()
for details.
│ │ │ - - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │ +
- can_filters (list) – See
set_filters()
for details.
│ │ │ + - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │
-
│ │ │
-
│ │ │ @@ -159,17 +159,17 @@
│ │ │
- │ │ │
│ │ │recv
(timeout=None)[source]¶ - │ │ │
Block waiting for a message from the Bus.
│ │ ││ │ │
│ │ │ @@ -182,15 +182,15 @@ │ │ ││ │ │ │ │ │ │ │ │ - Parameters: timeout (float or None) – seconds to wait for a message or None to wait indefinitely │ │ │ + │ │ │ -Parameters: timeout (float or None) – seconds to wait for a message or None to wait indefinitely │ │ │Return type: can.Message or None │ │ │ + │ │ │Return type: can.Message or None │ │ │ │ │ │Returns: None on timeout or a │ │ │can.Message
object. │ │ │ │ │ │Raises: can.CanError – if an error occurred while reading │ │ │Override this method to enable the transmit path.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │ @@ -215,18 +215,18 @@ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
│ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – Message to transmit │ │ │ -
- period (float) – Period in seconds between each message │ │ │ -
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ +
- period (float) – Period in seconds between each message │ │ │ +
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ no duration is provided, the task will continue indefinitely. │ │ │ -
- store_task (bool) – If True (the default) the task will be attached to this Bus instance. │ │ │ +
- store_task (bool) – If True (the default) the task will be attached to this Bus instance. │ │ │ Disable to instead manage tasks manually. │ │ │
Returns: │ │ │ @@ -305,15 +305,15 @@ │ │ │A started task instance. Note the task can be stopped (and depending on │ │ │ the backend modified) by calling the
│ │ │stop()
method.- │ │ │
│ │ │stop_all_periodic_tasks
(remove_tasks=True)[source]¶ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/iscan.html │ │ │ @@ -58,17 +58,17 @@ │ │ │Stop sending any messages that were started using bus.send_periodic
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: remove_tasks (bool) – Stop tracking the stopped tasks. │ │ │ + │ │ │ │ │ │Parameters: remove_tasks (bool) – Stop tracking the stopped tasks. │ │ │Bases:
│ │ │can.bus.BusABC
isCAN interface
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (int) – Device number │ │ │ -
- bitrate (int) – Bitrate in bits/s │ │ │ -
- poll_interval (float) – Poll interval in seconds when reading messages │ │ │ +
- channel (int) – Device number │ │ │ +
- bitrate (int) – Bitrate in bits/s │ │ │ +
- poll_interval (float) – Poll interval in seconds when reading messages │ │ │
-
│ │ │
-
│ │ │ @@ -77,15 +77,15 @@
│ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/kvaser.html │ │ │ @@ -59,50 +59,50 @@ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
│ │ │ │ │ │Bases:
│ │ │can.bus.BusABC
The CAN Bus implemented for the Kvaser interface.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (int) – The Channel id to create this bus with. │ │ │ -
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │ + - channel (int) – The Channel id to create this bus with. │ │ │ +
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │
Backend Configuration
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- bitrate (int) – Bitrate of channel in bit/s │ │ │ -
- accept_virtual (bool) – If virtual channels should be accepted. │ │ │ -
- tseg1 (int) – Time segment 1, that is, the number of quanta from (but not including) │ │ │ +
- bitrate (int) – Bitrate of channel in bit/s │ │ │ +
- accept_virtual (bool) – If virtual channels should be accepted. │ │ │ +
- tseg1 (int) – Time segment 1, that is, the number of quanta from (but not including) │ │ │ the Sync Segment to the sampling point. │ │ │ If this parameter is not given, the Kvaser driver will try to choose │ │ │ all bit timing parameters from a set of defaults. │ │ │ -
- tseg2 (int) – Time segment 2, that is, the number of quanta from the sampling │ │ │ +
- tseg2 (int) – Time segment 2, that is, the number of quanta from the sampling │ │ │ point to the end of the bit. │ │ │ -
- sjw (int) – The Synchronization Jump Width. Decides the maximum number of time quanta │ │ │ +
- sjw (int) – The Synchronization Jump Width. Decides the maximum number of time quanta │ │ │ that the controller can resynchronize every bit. │ │ │ -
- no_samp (int) – Either 1 or 3. Some CAN controllers can also sample each bit three times. │ │ │ +
- no_samp (int) – Either 1 or 3. Some CAN controllers can also sample each bit three times. │ │ │ In this case, the bit will be sampled three quanta in a row, │ │ │ with the last sample being taken in the edge between TSEG1 and TSEG2. │ │ │ Three samples should only be used for relatively slow baudrates. │ │ │ -
- driver_mode (bool) – Silent or normal. │ │ │ -
- single_handle (bool) – Use one Kvaser CANLIB bus handle for both reading and writing. │ │ │ +
- driver_mode (bool) – Silent or normal. │ │ │ +
- single_handle (bool) – Use one Kvaser CANLIB bus handle for both reading and writing. │ │ │ This can be set if reading and/or writing is done from one thread. │ │ │ -
- receive_own_messages (bool) – If messages transmitted should also be received back. │ │ │ +
- receive_own_messages (bool) – If messages transmitted should also be received back. │ │ │ Only works if single_handle is also False. │ │ │ If you want to receive messages from other applications on the same │ │ │ computer, set this to True or set single_handle to True. │ │ │ -
- fd (bool) – If CAN-FD frames should be supported. │ │ │ -
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ +
- fd (bool) – If CAN-FD frames should be supported. │ │ │ +
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ Defaults to arbitration bitrate. │ │ │
-
│ │ │ @@ -125,15 +125,15 @@
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
- channel (int or str or list(int) or list(str)) – The channel ids to create this bus with. │ │ │ +
- channel (int or str or list(int) or list(str)) – The channel ids to create this bus with. │ │ │ Can also be a single integer, netid name or a comma separated │ │ │ string. │ │ │ -
- can_filters (list) – See
can.BusABC.set_filters()
for details.
│ │ │ - - receive_own_messages (bool) – If transmitted messages should also be received by this bus. │ │ │ -
- use_system_timestamp (bool) – Use system timestamp for can messages instead of the hardware time │ │ │ +
- can_filters (list) – See
can.BusABC.set_filters()
for details.
│ │ │ + - receive_own_messages (bool) – If transmitted messages should also be received by this bus. │ │ │ +
- use_system_timestamp (bool) – Use system timestamp for can messages instead of the hardware time │ │ │ stamp │ │ │ -
- serial (str) – Serial to connect (optional, will use the first found if not │ │ │ +
- serial (str) – Serial to connect (optional, will use the first found if not │ │ │ supplied) │ │ │ -
- bitrate (int) – Channel bitrate in bit/s. (optional, will enable the auto bitrate │ │ │ +
- bitrate (int) – Channel bitrate in bit/s. (optional, will enable the auto bitrate │ │ │ feature if not supplied) │ │ │ -
- fd (bool) – If CAN-FD frames should be supported. │ │ │ -
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ +
- fd (bool) – If CAN-FD frames should be supported. │ │ │ +
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ Defaults to arbitration bitrate. │ │ │
- override_library_name – Absolute path or relative path to the library including filename. │ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/neovi.html │ │ │ @@ -96,27 +96,27 @@ │ │ │Parameters: │ │ │-
│ │ │
The CAN Bus implemented for the python_ics interface │ │ │ https://github.com/intrepidcs/python_ics
│ │ ││ │ │
│ │ │ @@ -128,15 +128,15 @@ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
│ │ │ │ │ │ │ │ │ │ │ │Parameters: device – ics device │ │ │ │ │ │ -Returns: ics device serial string │ │ │Return type: str │ │ │ + │ │ │ │ │ │Return type: str │ │ │-
│ │ │
-
│ │ │ @@ -145,15 +145,15 @@
│ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/nican.html │ │ │ @@ -74,18 +74,18 @@ │ │ │ does not work. │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
│ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (str) – Name of the object to open (e.g. ‘CAN0’) │ │ │ -
- bitrate (int) – Bitrate in bits/s │ │ │ -
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │ - - log_errors (bool) – If True, communication errors will appear as CAN messages with │ │ │ +
- channel (str) – Name of the object to open (e.g. ‘CAN0’) │ │ │ +
- bitrate (int) – Bitrate in bits/s │ │ │ +
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │ + - log_errors (bool) – If True, communication errors will appear as CAN messages with
│ │ │
is_error_frame
set to True andarbitration_id
will identify │ │ │ the error (default True)
│ │ │
Raises: │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/pcan.html │ │ │ @@ -92,64 +92,64 @@ │ │ │ the PCAN interface includes thecan.interfaces.nican.NicanError – If starting communication fails
│ │ │flash()
│ │ │ andstatus()
methods. │ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │ @@ -175,15 +175,15 @@ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (str) – The can interface name. An example would be ‘PCAN_USBBUS1’ │ │ │ +
- channel (str) – The can interface name. An example would be ‘PCAN_USBBUS1’ │ │ │ Default is ‘PCAN_USBBUS1’ │ │ │
- state (can.bus.BusState) – BusState of the channel. │ │ │ Default is ACTIVE │ │ │ -
- bitrate (int) – Bitrate of channel in bit/s. │ │ │ +
- bitrate (int) – Bitrate of channel in bit/s. │ │ │ Default is 500 kbit/s. │ │ │ Ignored if using CanFD. │ │ │ -
- fd (bool) – Should the Bus be initialized in CAN-FD mode. │ │ │ -
- f_clock (int) – Clock rate in Hz. │ │ │ +
- fd (bool) – Should the Bus be initialized in CAN-FD mode. │ │ │ +
- f_clock (int) – Clock rate in Hz. │ │ │ Any of the following: │ │ │ 20000000, 24000000, 30000000, 40000000, 60000000, 80000000. │ │ │ Ignored if not using CAN-FD. │ │ │ Pass either f_clock or f_clock_mhz. │ │ │ -
- f_clock_mhz (int) – Clock rate in MHz. │ │ │ +
- f_clock_mhz (int) – Clock rate in MHz. │ │ │ Any of the following: │ │ │ 20, 24, 30, 40, 60, 80. │ │ │ Ignored if not using CAN-FD. │ │ │ Pass either f_clock or f_clock_mhz. │ │ │ -
- nom_brp (int) – Clock prescaler for nominal time quantum. │ │ │ +
- nom_brp (int) – Clock prescaler for nominal time quantum. │ │ │ In the range (1..1024) │ │ │ Ignored if not using CAN-FD. │ │ │ -
- nom_tseg1 (int) – Time segment 1 for nominal bit rate, │ │ │ +
- nom_tseg1 (int) – Time segment 1 for nominal bit rate, │ │ │ that is, the number of quanta from (but not including) │ │ │ the Sync Segment to the sampling point. │ │ │ In the range (1..256). │ │ │ Ignored if not using CAN-FD. │ │ │ -
- nom_tseg2 (int) – Time segment 2 for nominal bit rate, │ │ │ +
- nom_tseg2 (int) – Time segment 2 for nominal bit rate, │ │ │ that is, the number of quanta from the sampling │ │ │ point to the end of the bit. │ │ │ In the range (1..128). │ │ │ Ignored if not using CAN-FD. │ │ │ -
- nom_sjw (int) – Synchronization Jump Width for nominal bit rate. │ │ │ +
- nom_sjw (int) – Synchronization Jump Width for nominal bit rate. │ │ │ Decides the maximum number of time quanta │ │ │ that the controller can resynchronize every bit. │ │ │ In the range (1..128). │ │ │ Ignored if not using CAN-FD. │ │ │ -
- data_brp (int) – Clock prescaler for fast data time quantum. │ │ │ +
- data_brp (int) – Clock prescaler for fast data time quantum. │ │ │ In the range (1..1024) │ │ │ Ignored if not using CAN-FD. │ │ │ -
- data_tseg1 (int) – Time segment 1 for fast data bit rate, │ │ │ +
- data_tseg1 (int) – Time segment 1 for fast data bit rate, │ │ │ that is, the number of quanta from (but not including) │ │ │ the Sync Segment to the sampling point. │ │ │ In the range (1..32). │ │ │ Ignored if not using CAN-FD. │ │ │ -
- data_tseg2 (int) – Time segment 2 for fast data bit rate, │ │ │ +
- data_tseg2 (int) – Time segment 2 for fast data bit rate, │ │ │ that is, the number of quanta from the sampling │ │ │ point to the end of the bit. │ │ │ In the range (1..16). │ │ │ Ignored if not using CAN-FD. │ │ │ -
- data_sjw (int) – Synchronization Jump Width for fast data bit rate. │ │ │ +
- data_sjw (int) – Synchronization Jump Width for fast data bit rate. │ │ │ Decides the maximum number of time quanta │ │ │ that the controller can resynchronize every bit. │ │ │ In the range (1..16). │ │ │ Ignored if not using CAN-FD. │ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │ @@ -219,15 +219,15 @@ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
- │ │ │
│ │ │status
()[source]¶ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/serial.html │ │ │ @@ -76,24 +76,24 @@ │ │ │ for some special semantics. │ │ │ │ │ │Query the PCAN bus status.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Return type: int │ │ │ + │ │ │Return type: int │ │ │ │ │ │ │ │ │Returns: The status code. See values in basic.PCAN_ERROR_ │ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (str) – The serial device to open. For example “/dev/ttyS1” or │ │ │ +
- channel (str) – The serial device to open. For example “/dev/ttyS1” or │ │ │ “/dev/ttyUSB0” on Linux or “COM1” on Windows systems. │ │ │ -
- baudrate (int) –
Baud rate of the serial device in bit/s (default 115200).
│ │ │ + - baudrate (int) –
Baud rate of the serial device in bit/s (default 115200).
│ │ ││ │ ││ │ │Warning
│ │ │Some serial port implementations don’t care about the baudrate.
│ │ │
│ │ │ - - timeout (float) – Timeout for the serial device in seconds (default 0.1). │ │ │ -
- rtscts (bool) – turn hardware handshake (RTS/CTS) on and off │ │ │ +
- timeout (float) – Timeout for the serial device in seconds (default 0.1). │ │ │ +
- rtscts (bool) – turn hardware handshake (RTS/CTS) on and off │ │ │
-
│ │ │
-
│ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/slcan.html
│ │ │ @@ -70,26 +70,26 @@
│ │ │ class
can.interfaces.slcan.
slcanBus
(channel, ttyBaudrate=115200, bitrate=None, btr=None, sleep_after_open=2, rtscts=False, **kwargs)[source]¶
│ │ │ Bases:
│ │ │can.bus.BusABC
slcan interface
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Raises: ValueError – if both bitrate and btr are set
│ │ │ + │ │ │Raises: │ │ │ValueError – if both bitrate and btr are set
│ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (str) – port of underlying serial or usb device (e.g. /dev/ttyUSB0, COM8, …) │ │ │ +
- channel (str) – port of underlying serial or usb device (e.g. /dev/ttyUSB0, COM8, …) │ │ │ Must not be empty. │ │ │ -
- ttyBaudrate (int) – baudrate of underlying serial or usb device │ │ │ -
- bitrate (int) – Bitrate in bit/s │ │ │ -
- btr (str) – BTR register value to set custom can speed │ │ │ -
- poll_interval (float) – Poll interval in seconds when reading messages │ │ │ -
- sleep_after_open (float) – Time to wait in seconds after opening serial connection │ │ │ -
- rtscts (bool) – turn hardware handshake (RTS/CTS) on and off │ │ │ +
- ttyBaudrate (int) – baudrate of underlying serial or usb device │ │ │ +
- bitrate (int) – Bitrate in bit/s │ │ │ +
- btr (str) – BTR register value to set custom can speed │ │ │ +
- poll_interval (float) – Poll interval in seconds when reading messages │ │ │ +
- sleep_after_open (float) – Time to wait in seconds after opening serial connection │ │ │ +
- rtscts (bool) – turn hardware handshake (RTS/CTS) on and off │ │ │
-
│ │ │
-
│ │ │ @@ -98,15 +98,15 @@
│ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/socketcan.html │ │ │ @@ -228,16 +228,16 @@ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
│ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- bcm_socket – An open bcm socket on the desired CAN channel. │ │ │
- message (can.Message) – The message to be sent periodically. │ │ │ -
- period (float) – The rate in seconds at which to send the message. │ │ │ -
- duration (float) – Approximate duration in seconds to send the message. │ │ │ +
- period (float) – The rate in seconds at which to send the message. │ │ │ +
- duration (float) – Approximate duration in seconds to send the message. │ │ │
-
│ │ │
- │ │ │ @@ -274,38 +274,38 @@ │ │ │
Bases:
│ │ │can.bus.BusABC
Implements
│ │ │can.BusABC._detect_available_configs()
.│ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (str) – The can interface name with which to create this bus. An example channel │ │ │ +
- channel (str) – The can interface name with which to create this bus. An example channel
│ │ │ would be ‘vcan0’ or ‘can0’.
│ │ │ An empty string ‘’ will receive messages from all channels.
│ │ │ In that case any sent messages must be explicitly addressed to a
│ │ │ channel using
can.Message.channel
.
│ │ │ - - receive_own_messages (bool) – If transmitted messages should also be received by this bus. │ │ │ -
- fd (bool) – If CAN-FD frames should be supported. │ │ │ -
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │ + - receive_own_messages (bool) – If transmitted messages should also be received by this bus. │ │ │ +
- fd (bool) – If CAN-FD frames should be supported. │ │ │ +
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │
-
│ │ │
-
│ │ │
recv
(timeout=None)¶
│ │ │ Block waiting for a message from the Bus.
│ │ ││ │ │
│ │ │ @@ -317,15 +317,15 @@ │ │ ││ │ │ │ │ │ │ │ │ - Parameters: timeout (float) – seconds to wait for a message or None to wait indefinitely │ │ │ + │ │ │ -Parameters: timeout (float) – seconds to wait for a message or None to wait indefinitely │ │ │Return type: can.Message or None │ │ │ + │ │ │Return type: can.Message or None │ │ │ │ │ │Returns: None on timeout or a │ │ │can.Message
object. │ │ │ │ │ │Raises: can.CanError – if an error occurred while reading │ │ │Transmit a message to the CAN bus.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float) – Wait up to this many seconds for the transmit queue to be ready. │ │ │ +
- timeout (float) – Wait up to this many seconds for the transmit queue to be ready. │ │ │ If not given, the call may fail immediately. │ │ │
│ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/systec.html │ │ │ @@ -80,46 +80,46 @@ │ │ │Raises: │ │ │can.CanError – if the message could not be written.
│ │ │Bases:
│ │ │can.bus.BusABC
The CAN Bus implemented for the SYSTEC interface.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (int) – The Channel id to create this bus with. │ │ │ -
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │ + - channel (int) – The Channel id to create this bus with. │ │ │ +
- can_filters (list) – See
can.BusABC.set_filters()
.
│ │ │
Backend Configuration
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- bitrate (int) – Channel bitrate in bit/s. │ │ │ +
- bitrate (int) – Channel bitrate in bit/s. │ │ │ Default is 500000. │ │ │ -
- device_number (int) – The device number of the USB-CAN. │ │ │ +
- device_number (int) – The device number of the USB-CAN. │ │ │ Valid values: 0 through 254. Special value 255 is reserved to detect the first connected device (should only │ │ │ be used, in case only one module is connected to the computer). │ │ │ Default is 255. │ │ │
- state (can.bus.BusState) – BusState of the channel. │ │ │ Default is ACTIVE. │ │ │ -
- receive_own_messages (bool) – If messages transmitted should also be received back. │ │ │ +
- receive_own_messages (bool) – If messages transmitted should also be received back. │ │ │ Default is False. │ │ │ -
- rx_buffer_entries (int) – The maximum number of entries in the receive buffer. │ │ │ +
- rx_buffer_entries (int) – The maximum number of entries in the receive buffer. │ │ │ Default is 4096. │ │ │ -
- tx_buffer_entries (int) – The maximum number of entries in the transmit buffer. │ │ │ +
- tx_buffer_entries (int) – The maximum number of entries in the transmit buffer. │ │ │ Default is 4096. │ │ │
│ │ │ │ │ │Raises: │ │ │-
│ │ │ -
- ValueError – If invalid input parameter were passed. │ │ │ +
- ValueError – If invalid input parameter were passed. │ │ │
- can.CanError – If hardware or CAN interface initialization failed. │ │ │
-
│ │ │ @@ -127,19 +127,19 @@
│ │ │ static
Calculates AMR and ACR using CAN-ID as parameter.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- extended (bool) – if True parameters from_id and to_id contains 29-bit CAN-ID │ │ │ -
- from_id (int) – first CAN-ID which should be received │ │ │ -
- to_id (int) – last CAN-ID which should be received │ │ │ -
- rtr_only (bool) – if True only RTR-Messages should be received, and rtr_too will be ignored │ │ │ -
- rtr_too (bool) – if True CAN data frames and RTR-Messages should be received │ │ │ +
- extended (bool) – if True parameters from_id and to_id contains 29-bit CAN-ID │ │ │ +
- from_id (int) – first CAN-ID which should be received │ │ │ +
- to_id (int) – last CAN-ID which should be received │ │ │ +
- rtr_only (bool) – if True only RTR-Messages should be received, and rtr_too will be ignored │ │ │ +
- rtr_too (bool) – if True CAN data frames and RTR-Messages should be received │ │ │
│ │ │ │ │ │ @@ -170,15 +170,15 @@ │ │ │ this channel will be deleted automatically for not blocking the other channel. │ │ │Returns: │ │ │Returns list with one filter containing a “can_id”, a “can_mask” and “extended” key.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – The CAN message. │ │ │ -
- timeout (float) – Transmit timeout in seconds (value 0 switches off the “auto delete”) │ │ │ +
- timeout (float) – Transmit timeout in seconds (value 0 switches off the “auto delete”) │ │ │
│ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/interfaces/vector.html │ │ │ @@ -74,28 +74,28 @@ │ │ │Raises: │ │ │can.CanError – If the message could not be sent.
│ │ │ │ │ │ │ │ │Bases:
│ │ │can.bus.BusABC
The CAN Bus implemented for the Vector interface.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- channel (list) – The channel indexes to create this bus with. │ │ │ +
- channel (list) – The channel indexes to create this bus with. │ │ │ Can also be a single integer or a comma separated string. │ │ │ -
- poll_interval (float) – Poll interval in seconds. │ │ │ -
- bitrate (int) – Bitrate in bits/s. │ │ │ -
- rx_queue_size (int) – Number of messages in receive queue (power of 2). │ │ │ +
- poll_interval (float) – Poll interval in seconds. │ │ │ +
- bitrate (int) – Bitrate in bits/s. │ │ │ +
- rx_queue_size (int) – Number of messages in receive queue (power of 2). │ │ │ CAN: range 16…32768 │ │ │ CAN-FD: range 8192…524288 │ │ │ -
- app_name (str) – Name of application in Hardware Config. │ │ │ +
- app_name (str) – Name of application in Hardware Config. │ │ │ If set to None, the channel should be a global channel index. │ │ │ -
- serial (int) – Serial number of the hardware to be used. │ │ │ +
- serial (int) – Serial number of the hardware to be used. │ │ │ If set, the channel parameter refers to the channels ONLY on the specified hardware. │ │ │ If set, the app_name is unused. │ │ │ -
- fd (bool) – If CAN-FD frames should be supported. │ │ │ -
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ +
- fd (bool) – If CAN-FD frames should be supported. │ │ │ +
- data_bitrate (int) – Which bitrate to use for data phase in CAN FD. │ │ │ Defaults to arbitration bitrate. │ │ │
-
│ │ │ @@ -111,15 +111,15 @@
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
-
│ │ │ class
can.
BusABC
(channel, can_filters=None, **kwargs)[source]
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
The CAN Bus Abstract Base Class that serves as the basis │ │ │ for all concrete interfaces.
│ │ │This class may be used as an iterator over the received messages.
│ │ │Construct and open a CAN bus instance of the specified type.
│ │ │Subclasses should call though this method with all given parameters │ │ │ as it handles generic tasks like applying filters.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- channel – The can interface identifier. Expected type is backend dependent. │ │ │ -
- can_filters (list) – See
set_filters()
for details.
│ │ │ - - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │ +
- can_filters (list) – See
set_filters()
for details.
│ │ │ + - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │
-
│ │ │
-
│ │ │ @@ -137,16 +137,16 @@
│ │ │ as it handles generic tasks like applying filters.
│ │ │
│ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- channel – The can interface identifier. Expected type is backend dependent. │ │ │ -
- can_filters (list) – See
set_filters()
for details.
│ │ │ - - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │ +
- can_filters (list) – See
set_filters()
for details.
│ │ │ + - kwargs (dict) – Any backend dependent configurations are passed in this dictionary │ │ │
Override this method to enable the transmit path.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ ├── ./usr/share/doc/python-can-doc/html/internal-api.html │ │ │ @@ -99,29 +99,29 @@ │ │ │Parameters: │ │ │-
│ │ │
Several methods are not documented in the main
│ │ │can.BusABC
│ │ │ as they are primarily useful for library developers as opposed to │ │ │ library users. This is the entire ABC bus class with all internal │ │ │ methods:-
│ │ │
-
│ │ │
-
│ │ │
__metaclass__
│ │ │ - alias of
│ │ │ +abc.ABCMeta
alias of
│ │ │abc.ABCMeta
-
│ │ │
-
│ │ │
__str__
()[source]
│ │ │ Return str(self).
│ │ │
_apply_filters
(filters)[source] │ │ │ │ │ │ │ │ │Hook for applying the filters to the underlying kernel or │ │ │ hardware if supported/implemented by the interface.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: filters (Iterator[dict]) – See │ │ │ +set_filters()
for details. │ │ │ │ │ │Parameters: filters (Iterator[dict]) – See │ │ │set_filters()
for details.-
│ │ │
-
│ │ │ @@ -208,15 +208,15 @@
│ │ │ currently connect with.
│ │ │
This might be quite time consuming.
│ │ │May not to be implemented by every interface on every platform.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Return type: Iterator[dict] │ │ │ + │ │ │Return type: Iterator[dict] │ │ │ │ │ │ │ │ │Returns: an iterable of dicts, each being a configuration suitable │ │ │ for usage in the interface’s bus constructor. │ │ │
This method should not be overridden.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ @@ -266,32 +266,32 @@ │ │ │ change over time for some interfaces, like for example in the │ │ │ Kvaser interface. Thus it cannot be simplified to a constant value. │ │ │ │ │ ││ │ │ │ │ │ │ │ │ │ │ │ -Parameters: msg (can.Message) – the message to check if matching │ │ │Return type: bool │ │ │ + │ │ │Return type: bool │ │ │ │ │ │ │ │ │Returns: whether the given message matches at least one filter │ │ ││ │ │
│ │ │ │ │ │ @@ -303,16 +303,16 @@ │ │ ││ │ │ │ │ │ │ │ │ - Parameters: timeout (float) – seconds to wait for a message, │ │ │ +
│ │ │ -Parameters: │ │ │timeout (float) – seconds to wait for a message, │ │ │ see
│ │ │send()
Return type: │ │ │ + │ │ │Return type: │ │ │ │ │ │ │ │ │Returns: │ │ │-
│ │ │
- a message that was read or None on timeout │ │ │
- a bool that is True if message filtering has already │ │ │ been done and else False │ │ │
│ │ │ │ │ │Raises: │ │ │-
│ │ │
- can.CanError – if an error occurred while reading │ │ │ -
- NotImplementedError – if the bus provides it’s own
recv()
│ │ │ + - NotImplementedError – if the bus provides it’s own
recv()
│ │ │ implementation (legacy implementation)
│ │ │
Override this method to enable a more efficient backend specific approach.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – Message to transmit │ │ │ -
- period (float) – Period in seconds between each message │ │ │ -
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ +
- period (float) – Period in seconds between each message │ │ │ +
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ no duration is provided, the task will continue indefinitely. │ │ │
Returns: │ │ │ @@ -347,17 +347,17 @@ │ │ │A started task instance. Note the task can be stopped (and depending on │ │ │ the backend modified) by calling the
│ │ │stop()
method.- │ │ │
│ │ │recv
(timeout=None)[source]Block waiting for a message from the Bus.
│ │ ││ │ │
│ │ │ @@ -370,15 +370,15 @@ │ │ ││ │ │ │ │ │ │ │ │ - Parameters: timeout (float or None) – seconds to wait for a message or None to wait indefinitely │ │ │ + │ │ │ -Parameters: timeout (float or None) – seconds to wait for a message or None to wait indefinitely │ │ │Return type: can.Message or None │ │ │ + │ │ │Return type: can.Message or None │ │ │ │ │ │Returns: None on timeout or a │ │ │can.Message
object. │ │ │ │ │ │Raises: can.CanError – if an error occurred while reading │ │ │Override this method to enable the transmit path.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ @@ -403,18 +403,18 @@ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – A message object. │ │ │ -
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ +
- timeout (float or None) – If > 0, wait up to this many seconds for message to be ACK’ed or │ │ │ for transmit queue to be ready depending on driver implementation. │ │ │ If timeout is exceeded, an exception will be raised. │ │ │ Might not be supported by all interfaces. │ │ │ None blocks indefinitely. │ │ │
│ │ │
│ │ │ │ │ │ │ │ ││ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- msg (can.Message) – Message to transmit │ │ │ -
- period (float) – Period in seconds between each message │ │ │ -
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ +
- period (float) – Period in seconds between each message │ │ │ +
- duration (float) – The duration to keep sending this message at given rate. If │ │ │ no duration is provided, the task will continue indefinitely. │ │ │ -
- store_task (bool) – If True (the default) the task will be attached to this Bus instance. │ │ │ +
- store_task (bool) – If True (the default) the task will be attached to this Bus instance. │ │ │ Disable to instead manage tasks manually. │ │ │
Returns: │ │ │ @@ -493,15 +493,15 @@ │ │ │A started task instance. Note the task can be stopped (and depending on │ │ │ the backend modified) by calling the
│ │ │stop()
method.- │ │ │
│ │ │stop_all_periodic_tasks
(remove_tasks=True)[source] │ │ │ │ │ │ │ │ │ │ │ │ @@ -539,31 +539,31 @@ │ │ │ │ │ │Stop sending any messages that were started using bus.send_periodic
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: remove_tasks (bool) – Stop tracking the stopped tasks. │ │ │ + │ │ │ │ │ │Parameters: remove_tasks (bool) – Stop tracking the stopped tasks. │ │ ││ │ │IO Utilities¶
│ │ │Contains a generic class for file IO.
│ │ │-
│ │ │
-
│ │ │ class
can.io.generic.
BaseIOHandler
(file, mode='rt')[source]¶
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
A generic file handler that can be used for reading and writing.
│ │ │Can be used as a context manager.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │Attr file-like file: │ │ │ │ │ │the file-like object that is kept internally, or None if none │ │ │ was opened
│ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- file – a path-like object to open a file, a file-like object │ │ │ to be used as a file or None to not use a file at all │ │ │ -
- mode (str) – the mode that should be used to open the file, see
│ │ │ -
open()
, ignored if file is None
│ │ │ + - mode (str) – the mode that should be used to open the file, see
│ │ │ +
open()
, ignored if file is None
│ │ │
│ │ │ │ │ │ │ │ │ │ │ │Parameters: channel – Channel string (e.g. can0, CAN1) or integer │ │ │ │ │ │ -Returns: Channel integer or None if unsuccessful │ │ │Return type: int │ │ │ + │ │ │ │ │ │Return type: int │ │ │-
│ │ │
-
│ │ │
can.util.
dlc2len
(dlc)[source]¶
│ │ │ Calculate the data length from DLC.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: dlc (int) – DLC (0-15) │ │ │ + │ │ │Parameters: dlc (int) – DLC (0-15) │ │ │ │ │ │ -Returns: Data length in number of bytes (0-64) │ │ │Return type: int │ │ │ + │ │ │ │ │ │Return type: int │ │ │
-
│ │ │
-
│ │ │
can.util.
len2dlc
(length)[source]¶
│ │ │ Calculate the DLC from data length.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: length (int) – Length in number of bytes (0-64) │ │ │ + │ │ │Parameters: length (int) – Length in number of bytes (0-64) │ │ │ │ │ │ -Returns: DLC (0-15) │ │ │Return type: int │ │ │ + │ │ │ │ │ │Return type: int │ │ │
-
│ │ │
-
│ │ ├── ./usr/share/doc/python-can-doc/html/listeners.html
│ │ │ @@ -54,20 +54,20 @@
│ │ │
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 │ │ │ +NotImplementedError
to be thrown when a message is received on │ │ │ the CAN bus. -
│ │ │ class
can.
Listener
[source]¶
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
The basic listener that can be called directly to handle some │ │ │ CAN message:
│ │ │listener = SomeListener() │ │ │ msg = my_bus.recv() │ │ │ │ │ │ # now either call │ │ │ listener(msg) │ │ │ @@ -82,15 +82,15 @@ │ │ │
- │ │ │
│ │ │on_error
(exc)[source]¶ │ │ │ │ │ │This method is called to handle any exception in the receive thread.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: exc (Exception) – The exception causing the thread to stop │ │ │ + │ │ │ │ │ │Parameters: exc (Exception) – The exception causing the thread to stop │ │ │-
│ │ │
-
│ │ │ @@ -156,15 +156,15 @@
│ │ │ available it blocks for given timeout or until a message is received, or else
│ │ │ returns None (whichever is shorter). This method does not block after
│ │ │
can.BufferedReader.stop()
has been called. │ │ ││ │ │
│ │ │ @@ -193,15 +193,15 @@ │ │ │ │ │ ││ │ │ │ │ │ │ │ │ - Parameters: timeout (float) – The number of seconds to wait for a new message. │ │ │ + │ │ │Parameters: timeout (float) – The number of seconds to wait for a new message. │ │ │ │ │ │Rytpe: can.Message or None │ │ │ │ │ │ │ │ │Returns: the message if there is one, or None if there is not. │ │ │
-
│ │ │
-
│ │ │ class
can.
AsyncBufferedReader
(loop=None)[source]¶
│ │ │ Bases:
│ │ │ -can.listener.Listener
A message buffer for use with
│ │ │ +asyncio
.A message buffer for use with
│ │ │asyncio
.See Asyncio support for how to use with
│ │ │can.Notifier
.Can also be used as an asynchronous iterator:
│ │ ││ │ ││ │ │async for msg in reader: │ │ │ print(msg) │ │ │
-
│ │ │ @@ -263,16 +263,16 @@
│ │ │
- file – a path-like object to open a file, a file-like object │ │ │ to be used as a file or None to not use a file at all │ │ │ -
- mode (str) – the mode that should be used to open the file, see
│ │ │ -
open()
, ignored if file is None
│ │ │ + - mode (str) – the mode that should be used to open the file, see
│ │ │ +
open()
, ignored if file is None
│ │ │
│ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ @@ -476,15 +476,15 @@ │ │ │Parameters: │ │ │-
│ │ │
- file – a path-like object or a file-like object to write to. │ │ │ If this is a file-like object, is has to open in text │ │ │ write mode, not binary write mode. │ │ │ -
- append (bool) – if set to True messages are appended to │ │ │ +
- append (bool) – if set to True messages are appended to │ │ │ the file and no header line is written, else │ │ │ the file is truncated and starts with a newly │ │ │ written header line │ │ │
│ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │ │ │ ││ │ │Warning
│ │ │ @@ -542,15 +542,15 @@ │ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │ │ │ ││ │ │Warning
│ │ │ @@ -667,16 +667,16 @@ │ │ │log_event
(message, timestamp=None)[source]¶ │ │ │ │ │ │ │ │ │ @@ -748,15 +748,15 @@ │ │ │ │ │ │Add a message to the log file.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- file – a path-like object or as file-like object to write to │ │ │ If this is a file-like object, is has to opened in text │ │ │ write mode, not binary write mode. │ │ │
- channel – a default channel to use when the message does not │ │ │ have a channel set │ │ │ -
- append (bool) – if set to True messages are appended to │ │ │ +
- append (bool) – if set to True messages are appended to │ │ │ the file, else the file is truncated │ │ │
-
│ │ │
-
│ │ │ @@ -840,16 +840,16 @@
│ │ │
Add an arbitrary message to the log file as a global marker.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │ -
- text (str) – The group name of the marker. │ │ │ -
- timestamp (float) – Absolute timestamp in Unix timestamp format. If not given, the │ │ │ +
- text (str) – The group name of the marker. │ │ │ +
- timestamp (float) – Absolute timestamp in Unix timestamp format. If not given, the │ │ │ marker will be placed along the last message. │ │ │
log_event
(text, timestamp=None)[source]¶ │ │ ││ │ │ │ │ ││ │ │Message¶
│ │ │-
│ │ │
-
│ │ │ class
can.
Message
(timestamp=0.0, arbitration_id=0, is_extended_id=None, is_remote_frame=False, is_error_frame=False, channel=None, dlc=None, data=None, is_fd=False, bitrate_switch=False, error_state_indicator=False, extended_id=None, check=False)[source]¶
│ │ │ - Bases:
│ │ │ +object
Bases:
│ │ │object
The
│ │ │Message
object is used to represent CAN messages for │ │ │ sending, receiving and other purposes like converting between different │ │ │ logging formats.Messages can use extended identifiers, be remote or error frames, contain │ │ │ data and may be associated to a channel.
│ │ │Messages are always compared by identity and never by value, because that │ │ │ may introduce unexpected behaviour. See also
│ │ │ -equals()
.
│ │ │ +copy()
/deepcopy()
is supported as well.
│ │ │copy()
/deepcopy()
is supported as well.Messages do not support “dynamic” attributes, meaning any others than the │ │ │ documented ones, since it uses
│ │ │__slots__
.To create a message object, simply provide any of the below attributes │ │ │ together with additional parameters as keyword arguments to the constructor.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Parameters: check (bool) – By default, the constructor of this class does not strictly check the input. │ │ │ + │ │ │ -Parameters: check (bool) – By default, the constructor of this class does not strictly check the input. │ │ │ Thus, the caller must prevent the creation of invalid messages or │ │ │ set this parameter to True, to raise an Error on invalid inputs. │ │ │ Possible problems include the dlc field not matching the length of data │ │ │ or creating a message with both is_remote_frame and is_error_frame set to True. │ │ │Raises: ValueError – iff check is set to True and one or more arguments were invalid │ │ │ + │ │ │ │ │ │Raises: ValueError – iff check is set to True and one or more arguments were invalid │ │ │One can instantiate a
│ │ │Message
defining data, and optional │ │ │ arguments for all attributes such as arbitration ID, flags, and timestamp.>>> from can import Message │ │ │ >>> test = Message(data=[1, 2, 3, 4, 5]) │ │ │ @@ -98,15 +98,15 @@ │ │ │
-
│ │ │
-
│ │ │
timestamp
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: float │ │ │ + │ │ │ │ │ │Type: float │ │ │The timestamp field in a CAN message is a floating point number representing when │ │ │ the message was received since the epoch in seconds. Where possible this will be │ │ │ timestamped in hardware.
│ │ │
-
│ │ │
-
│ │ │
arbitration_id
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: int │ │ │ + │ │ │ │ │ │Type: int │ │ │The frame identifier used for arbitration on the bus.
│ │ │The arbitration ID can take an int between 0 and the │ │ │ maximum value allowed depending on the
is_extended_id
flag │ │ │ (either 211 - 1 for 11-bit IDs, or │ │ │ @@ -136,15 +136,15 @@ │ │ │-
│ │ │
-
│ │ │
data
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bytearray │ │ │ + │ │ │ │ │ │Type: bytearray │ │ │The data parameter of a CAN message is exposed as a bytearray │ │ │ with length between 0 and 8.
│ │ │>>> example_data = bytearray([1, 2, 3]) │ │ │ >>> print(Message(data=example_data)) │ │ │ @@ -165,15 +165,15 @@ │ │ │
-
│ │ │
-
│ │ │
dlc
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: int │ │ │ + │ │ │ │ │ │Type: int │ │ │The DLC parameter of a CAN message is an integer │ │ │ between 0 and 8 representing the frame payload length.
│ │ │In the case of a CAN FD message, this indicates the data length in │ │ │ number of bytes.
│ │ │ @@ -195,29 +195,29 @@ │ │ │-
│ │ │
-
│ │ │
channel
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: str or int or None │ │ │ + │ │ │ │ │ │Type: str or int or None │ │ │This might store the channel from which the message came.
│ │ │
-
│ │ │
-
│ │ │
is_extended_id
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │This flag controls the size of the
│ │ │arbitration_id
field. │ │ │ Previously this was exposed as id_type.>>> print(Message(is_extended_id=False)) │ │ │ Timestamp: 0.000000 ID: 0000 S DLC: 0 │ │ │ @@ -235,15 +235,15 @@ │ │ │
-
│ │ │
-
│ │ │
is_error_frame
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │This boolean parameter indicates if the message is an error frame or not.
│ │ ││ │ │ @@ -253,15 +253,15 @@ │ │ │>>> print(Message(is_error_frame=True)) │ │ │ Timestamp: 0.000000 ID: 00000000 X E DLC: 0 │ │ │
-
│ │ │
-
│ │ │
is_remote_frame
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │This boolean attribute indicates if the message is a remote frame or a data frame, and │ │ │ modifies the bit in the CAN message’s flags field indicating this.
│ │ │>>> print(Message(is_remote_frame=True)) │ │ │ Timestamp: 0.000000 ID: 00000000 X R DLC: 0 │ │ │ @@ -272,44 +272,44 @@ │ │ │
-
│ │ │
-
│ │ │
is_fd
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │Indicates that this message is a CAN FD message.
│ │ │
-
│ │ │
-
│ │ │
bitrate_switch
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │If this is a CAN FD message, this indicates that a higher bitrate │ │ │ was used for the data transmission.
│ │ │
-
│ │ │
-
│ │ │
error_state_indicator
¶
│ │ │ │ │ │
│ │ ││ │ │ │ │ │ │ │ │ - Type: bool │ │ │ + │ │ │ │ │ │Type: bool │ │ │If this is a CAN FD message, this indicates an error active state.
│ │ │
-
│ │ │ @@ -352,20 +352,20 @@
│ │ │
Compares a given message with this one.
│ │ ││ │ │
│ │ │ │ │ │ │ │ │ │ │ │ -Parameters: │ │ │-
│ │ │
- other (can.Message) – the message to compare with │ │ │ -
- timestamp_delta (float or int or None) – the maximum difference at which two timestamps are │ │ │ +
- timestamp_delta (float or int or None) – the maximum difference at which two timestamps are │ │ │ still considered equal or None to not compare timestamps │ │ │
Return type: │ │ │ + │ │ │Return type: │ │ │ │ │ │ │ │ │ │ │ │Returns: │ │ │True iff the given message equals this one
│ │ │
-
│ │ │
-
│ │ │
-
│ │ │
-
│ │ │
-
│ │ │
-
│ │ │
create_filter
(extended, from_id, to_id, rtr_only, rtr_too)[source]¶ │ │ │
-
│ │ │