Skip to main content

buildstatus coverage

About

CAN BUS tools.

  • DBC file mangling.

  • candump output decoder.

Documentation: http://cantools.readthedocs.org/en/latest

Installation

pip install cantools

Example usage

Scripting

An example parsing and using a small DBC-file:

>>> import cantools
>>> from pprint import pprint
>>> db = cantools.db.load_file('tests/files/motohawk.dbc')
>>> db
version('1.0')

node('PCM1', None)
node('FOO', None)

message('ExampleMessage', 0x1f0, 8, 'Example message used as template in MotoHawk models.')
  signal('Temperature', 7, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', False, None, None, None)
  signal('AverageRadius', 1, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, '')
  signal('Enable', 0, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, None, None)

>>> db.messages
[message('ExampleMessage', 0x1f0, 8, 'Example message used as template in MotoHawk models.')]
>>> example_message = db.messages[0]
>>> example_message.comment
'Example message used as template in MotoHawk models.'
>>> pprint(example_message.signals)
[signal('Temperature', 7, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', False, None, None, None),
 signal('AverageRadius', 1, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, ''),
 signal('Enable', 0, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, None, None)]
>>> db.nodes
[node('PCM1', None), node('FOO', None)]
>>> db.version
'1.0'
>>>

The example continues encoding a message and sending it on a CAN bus using the python-can package.

>>> import can
>>> can.rc['interface'] = 'socketcan_ctypes'
>>> can.rc['channel'] = 'vcan0'
>>> can_bus = can.interface.Bus()
>>> data = example_message.encode({'Temperature': 250.1, 'AverageRadius': 3.2, 'Enable': 1})
>>> message = can.Message(arbitration_id=example_message.frame_id, data=data)
>>> can_bus.send(message)
>>>

See the test suite for additional examples: https://github.com/eerimoq/cantools/blob/master/tests/test_cantools.py

Command line tool

Decode CAN frames captured with the Linux program candump.

$ candump vcan0 | cantools decode motohawk.dbc
  vcan0  000001F0   [7]  01 FA 0F 00 00 00 00 :: ExampleMessage(Temperature: 249.88 degK, AverageRadius: 0.0 m, Enable: 1.0 -)
  vcan0  000001F0   [7]  01 FA 0F 00 00 00 00 :: ExampleMessage(Temperature: 249.88 degK, AverageRadius: 0.0 m, Enable: 1.0 -)
  vcan0  000001F0   [7]  01 FA 0F 00 00 00 00 :: ExampleMessage(Temperature: 249.88 degK, AverageRadius: 0.0 m, Enable: 1.0 -)

Contributing

  1. Fork the repository.

  2. Implement the new feature or bug fix.

  3. Implement test case(s) to ensure that future changes do not break legacy.

  4. Run the test suite for Python 2 and Python 3. Make sure all tests pass.

    python setup.py test
    python3 setup.py test
  5. Create a pull request.

Metadata

Release files for cantools 5.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cantools 5.2.0
File Size Uploaded Provenance Actions
cantools-5.2.0.tar.gz 24.3 kB Without provenance Details for cantools-5.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cantools 5.2.0
File Interpreter ABI Platform Actions
cantools-5.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for cantools-5.2.0-py2.py3-none-any.whl

Total release size: 39.1 kB

Release files / cantools-5.2.0.tar.gz

Download URL cantools-5.2.0.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9347f1f00aafdb6a90293954db262b95c4daf121c449013ca8a5e068729828dd
BLAKE2b-256 checksum
How to use checksums
38fd41163a0aa3a9ca26533188002c94e46e583183af9cbe8b4238abca165f94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cantools-5.2.0-py2.py3-none-any.whl

Download URL cantools-5.2.0-py2.py3-none-any.whl
Size 14.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
800d7b9675cdc36e2669d21496bce3239c1d91418a7158515a2aeef647b95b94
BLAKE2b-256 checksum
How to use checksums
25c5443330ba25534b6f598051a257474cf65861c28d76eb4de3b57a8b3ec62c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cantools 5.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

5.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page