CAN BUS tools.
Project description
About
CAN BUS tools.
CAN message encoding and decoding.
Simple and extended signal multiplexing.
candump output decoder.
Project homepage: https://github.com/eerimoq/cantools
Documentation: http://cantools.readthedocs.org/en/latest
Installation
pip install cantools
Example usage
Scripting
The example starts by parsing a small DBC-file and printing its messages and signals.
>>> import cantools
>>> from pprint import pprint
>>> db = cantools.db.load_file('tests/files/motohawk.dbc')
>>> db.messages
[message('ExampleMessage', 0x1f0, False, 8, 'Example message used as template in MotoHawk models.')]
>>> example_message = db.get_message_by_name('ExampleMessage')
>>> pprint(example_message.signals)
[signal('Enable', 7, 1, 'big_endian', False, 1.0, 0, 0.0, 0.0, '-', False, None, {0: 'Disabled', 1: 'Enabled'}, None),
signal('AverageRadius', 6, 6, 'big_endian', False, 0.1, 0, 0.0, 5.0, 'm', False, None, None, ''),
signal('Temperature', 0, 12, 'big_endian', True, 0.01, 250, 229.53, 270.47, 'degK', False, None, None, None)]
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)
Alternatively, a message can be encoded using the encode_message() method on the database object.
The last part of the example receives and decodes a CAN message.
>>> message = can_bus.recv()
>>> db.decode_message(message.arbitration_id, message.data)
{'AverageRadius': 3.2, 'Enable': 'Enabled', 'Temperature': 250.09}
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 tests/files/motohawk.dbc
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 ::
ExampleMessage(
Enable: 'Enabled' -,
AverageRadius: 0.0 m,
Temperature: 255.92 degK
)
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 ::
ExampleMessage(
Enable: 'Enabled' -,
AverageRadius: 0.0 m,
Temperature: 255.92 degK
)
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 ::
ExampleMessage(
Enable: 'Enabled' -,
AverageRadius: 0.0 m,
Temperature: 255.92 degK
)
Alternatively, the decoded message is printed on a single line:
$ candump vcan0 | cantools decode --single-line tests/files/motohawk.dbc
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)
vcan0 1F0 [8] 80 4A 0F 00 00 00 00 00 :: ExampleMessage(Enable: 'Enabled' -, AverageRadius: 0.0 m, Temperature: 255.92 degK)
Contributing
Fork the repository.
Install prerequisites.
pip install -r requirements.txtImplement the new feature or bug fix.
Implement test case(s) to ensure that future changes do not break legacy.
Run the tests.
make 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-18.0.0.tar.gz.
File metadata
- Download URL: cantools-18.0.0.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71c24f5735789093850b15bbf970cf0f4a0e7b00fc3dcc1b349658e57acf664b
|
|
| MD5 |
81fe6a8fa46819045f2a2c28e5cb52b7
|
|
| BLAKE2b-256 |
9f4228da6f1af0db1ba1b9d545467725eae5664bb0c4ba5bbe73c9757bf23cc5
|
File details
Details for the file cantools-18.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: cantools-18.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae0ba5477a8ce716e54ea21c782716b3e29f7686209f29d39c54f73786c0838
|
|
| MD5 |
cce41ac57ffc823a611093afc1f545ea
|
|
| BLAKE2b-256 |
876c9e131c839cf767bc6499fc2353f6355317fd6494731b7b854e1cb281c4f9
|