Skip to main content

CAN BUS tools.

Project description

buildstatus coverage

About

CAN BUS tools.

  • DBC file mangling.

Installation

pip install cantools

Example usage

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

An example parsing and using a small DBC-file:

>>> import cantools
>>> from pprint import pprint
>>> db = cantools.db.File()
>>> db.add_dbc_file('tests/files/motohawk.dbc')
>>> pprint(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", "signed", 0.01, 250, 229.53, 270.47, "degK", None, None),
 signal("AverageRadius", 1, 6, "big_endian", "unsigned", 0.1, 0, 0.0, 5.0, "m", None, ""),
 signal("Enable", 0, 1, "big_endian", "unsigned", 1.0, 0, 0.0, 0.0, "-", None, None)]
>>> pprint(db.ecus)
[ecu("PCM1", 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_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)
>>>

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.

Project details


Release history Release notifications | RSS feed

This version

2.3.0

Download files

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

Source Distribution

cantools-2.3.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cantools-2.3.0-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cantools-2.3.0.tar.gz.

File metadata

  • Download URL: cantools-2.3.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cantools-2.3.0.tar.gz
Algorithm Hash digest
SHA256 1d6d270244b35e67eed39b65290163cb530718872e05617798bf9ccf912e2421
MD5 6a17e1fd3cd4f217082864810cb9482f
BLAKE2b-256 a272a89689043b2b20770a260719086f2b9e59599049c3a5ef8106b290732f61

See more details on using hashes here.

File details

Details for the file cantools-2.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cantools-2.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf8bd1a3cd440dc04b33d9a7922d02d244c58ccec8a8310afc021931aa9cb63f
MD5 918d0ff15ab73a6ca1bdd36467b8d69a
BLAKE2b-256 989a8abd732c4728059fe1504914f6f05e6b4e0f0d3dc6b67ab0bc97563cf447

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page