Skip to main content

A command line interface to send and receive CAN bus messages.

Project description

cancli

A command line interface to send and receive CAN bus messages.

This program is based on:

  • prompt_toolkit for the user interface
  • confattr for parsing user input, providing auto completion and config files
  • cantools for decoding and encoding CAN bus messages
  • python-can for receiving and transmitting CAN bus messages

Usage

Connect to a CAN bus with bus can0 500k. Incoming messages are printed. If there are too many messages you can hide some or all of them with hide. You can undo hide with show or display a hidden message once with next or prev.

When you load a database file with db path/to/db.dbc messages are decoded and the signals are displayed in human readable form. If the data base file does not repeat the messages for every possible node you can specify that part of the arbitration id is a node id with node-id FF << 8.

You can send messages with send msg_name sig1=option1 sig2=3.14.

You can give different incoming messages different colors with set color.message=%color.message%,importantmessage:ansired. The syntax to add values to a dict setting is explained here. The available colors are displayed in the auto completion.

Available commands:

  • bitrate: Set the default bitrate and change the bitrate of all active buses.
  • bus: Activate a bus.
  • read: Read CAN bus messages from a log file.
  • db: Load a database file (dbc/sym/...).
  • node-id: Specify that part of an arbitration id is a node id.
  • mask: Specify a mask to modify an arbitration ID in case it is not found in the dbc file.
  • send/s: Send a message on the last activated CAN bus.
  • hide/-: Do not print received messages of the specified type.
  • show/+: Undo the effect of a previous hide command.
  • next//: Print the next received message of the specified type regardless of whether it has been disabled with the hide command.
  • prev/?: Print the last received message of the specified type.
  • grep: Search for signal.
  • set: Change the value of a setting.
  • include: Load another config file.
  • save: Save the settings.
  • echo: Display a message.
  • help: Display help.
  • quit/q: Quit the program.

Installation

pipx install cancli

sudo

In order to set bit rates and create virtual CAN buses root privileges are required. You can configure sudo to not ask for a password in these circumstances.

Create a group called can:

# groupadd can

Add the desired user to the group (this requires a reboot to take effect):

# gpasswd -a <username> can
# EDITOR=vim visudo
%can    ALL=(root) NOPASSWD: /bin/ip link set can? up type can bitrate *
%can    ALL=(root) NOPASSWD: /bin/ip link set can? down
%can    ALL=(root) NOPASSWD: /bin/ip link set can? up

%can    ALL=(root) NOPASSWD: /usr/bin/modprobe vcan
%can    ALL=(root) NOPASSWD: /bin/ip link add dev vcan? type vcan
%can    ALL=(root) NOPASSWD: /bin/ip link set up vcan?

Note that the last matching rule wins, not the most specific one. So in order to make sure that these rules are not overridden by other rules add them at the end of the file.

Links

Running the tests

I am using mypy for static type checking. tox creates a virtual environment and installs all dependencies for you. You can install tox with pipx (pipx install tox).

$ tox

In order to make tox work without an internet connection install devpi:

$ pipx install devpi-server
$ devpi-init
$ devpi-gen-config
$ su
# cp gen-config/devpi.service /etc/systemd/system/
# systemctl start devpi.service
# systemctl enable devpi.service

and add the following line to your bashrc:

export PIP_INDEX_URL=http://localhost:3141/root/pypi/+simple/

License

This work is free. You can use, copy, modify, and/or distribute it under the terms of the BSD Zero Clause License.

Project details


Download files

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

Source Distribution

cancli-1.3.2.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

cancli-1.3.2-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file cancli-1.3.2.tar.gz.

File metadata

  • Download URL: cancli-1.3.2.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for cancli-1.3.2.tar.gz
Algorithm Hash digest
SHA256 4bda00874cb4d11adc563d22e2e5bfaceba0231b1beacd04d6c6bc0b80dba6c3
MD5 7923403bb9f51ec8561acc91207d2cdf
BLAKE2b-256 95bc65f01c01443304b96cc49fd06d5a2cb21f81f6e4e49cb9c60c06d0dbf39f

See more details on using hashes here.

File details

Details for the file cancli-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: cancli-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for cancli-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c54d3a3f78d45c5ad919d0dd115c327b1d20f5d6e0bbdd7d810e178cb07b43
MD5 965159d6e56aaaeb4bf35d627e35f369
BLAKE2b-256 c378a0a23ce7d5b6d9c7cdb5359605441f34a4cdc7c278659efda56c91332a2a

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