CAN BUS tools.
Project description
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
Fork the repository.
Implement the new feature or bug fix.
Implement test case(s) to ensure that future changes do not break legacy.
Run the test suite for Python 2 and Python 3. Make sure all tests pass.
python2 setup.py test python3 setup.py testCreate a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cantools-6.0.0.tar.gz.
File metadata
- Download URL: cantools-6.0.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4dcb58beef970a59c8fbae1577748e263bef15e28a73fd2b751887d2b7da649
|
|
| MD5 |
05963992fb71c7da904c4f294a0d5326
|
|
| BLAKE2b-256 |
a16005f1fc40636cabced64c650c891f749cfa01381105dc284b45a46038d870
|
File details
Details for the file cantools-6.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: cantools-6.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
762ed739b21a2bec4b57591ece49529be3e6ded9d4931e139c07b12493471066
|
|
| MD5 |
c18a2d783fa7387a443983b9f4e09928
|
|
| BLAKE2b-256 |
a2a911dcc799460d82a01671e939d9adde11d4fa52a11b7dd0df8c34371db0ea
|