CAN BUS tools.
Project description
About
CAN BUS tools.
DBC file mangling.
Installation
pip install cantools
Example usage
Scripting
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)
>>>
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.
python setup.py test python3 setup.py test
Create 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
cantools-3.1.0.tar.gz
(19.8 kB
view hashes)
Built Distribution
Close
Hashes for cantools-3.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8140b9c4aa101280b01b4216530f219ec7a85dc73d994f66ea2989284d4a299 |
|
MD5 | 9d7a38384e1e4e64b67a87a04b306812 |
|
BLAKE2b-256 | 1e86b437b652bb8d6e7ccd2400c19b51f44265ebaa686f33204c647562c71b82 |