Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

CAN BUS tools.

Project Description

About

CAN BUS tools.

  • DBC and KCD file mangling.
  • candump output decoder.

Project homepage: https://github.com/eerimoq/cantools

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, False, 8, 'Example message used as template in MotoHawk models.')
  signal('Enable', 0, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, {0: 'Disabled', 1: 'Enabled'}, None)
  signal('AverageRadius', 1, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, '')
  signal('Temperature', 7, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', 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('Enable', 0, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, {0: 'Disabled', 1: 'Enabled'}, None),
 signal('AverageRadius', 1, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, ''),
 signal('Temperature', 7, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', 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  1F0   [7]  80 4A 0F 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)
  vcan0  1F0   [7]  80 4A 0F 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)
  vcan0  1F0   [7]  80 4A 0F 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)

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.

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

Release History

Release History

This version
History Node

9.0.0

History Node

8.0.0

History Node

7.0.0

History Node

6.1.0

History Node

6.0.0

History Node

5.2.0

History Node

5.1.0

History Node

5.0.0

History Node

4.1.1

History Node

4.1.0

History Node

4.0.1

History Node

4.0.0

History Node

3.1.1

History Node

3.1.0

History Node

3.0.0

History Node

2.4.0

History Node

2.3.0

History Node

2.2.0

History Node

2.1.0

History Node

2.0.0

History Node

1.0.0

History Node

0.2.2

History Node

0.2.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cantools-9.0.0-py2.py3-none-any.whl (19.3 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Aug 16, 2017
cantools-9.0.0.tar.gz (28.7 kB) Copy SHA256 Checksum SHA256 Source Aug 16, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting