Python CAN Bus USB Streaming API [+Grafana-MQTT Dashboards]
Need to stream CAN bus data via USB in Python?
With our Python API you can easily connect CLX000 or CANmod devices via USB to your PC - and integrate the CAN data with the popular python-can library.
In this intro we outline key features and use cases - including e.g. streaming your data in real-time Grafana dashboards!
Pip install, then stream data in <5 lines of code
Send/receive raw CAN frames via CLX000/CANmod(s)
Easily DBC decode data to physical values
Deploy on Windows and Linux (incl. Raspberry)
Leverage the extensive python-can extension tools
Benefit from excellent docs and script examples
The CLX000 (CL1000/CL2000) and CANmod.router let you send/receive CAN bus data via USB in real-time. This is often relevant in automotive/industrial OEM development, reverse engineering and CAN bus diagnostics. Further, our other CANmod devices can also be used via USB to stream GPS/temperature/analog sensor data in real-time.
If you need to stream CAN bus data via USB you can use both the CLX000 and CANmod.router.
For pure streaming use cases, we recommend the CANmod.router as it offers multiple advantages:
- It can be powered via USB while streaming - the CLX000 has to be powered via the DB9 (7-32V)
- It offers 4 x CAN interfaces vs. 1 x CAN for the CLX000
- It supports CAN FD on all 4 interfaces
- It can handle 8,000+ frames/second vs. 1,000+ frames/second for the CLX000
- It provides flanges for easier mounting in the field
- It offers advanced configuration of e.g. bit-rates, filters
View data via CLI
View your raw CAN bus data via the command line (with zero code required) using the can-viewer tool (part of the cantools library)
Log data via CLI
View/log your raw CAN data via the command line using the can-logger tool - with extensive output support (MF4, CSV, LOG, TRC, ASC, …)
Replay data via CLI
Easily load e.g. CANedge/CLX000 log files and replay them via USB onto your CAN bus using the simple can-player tool
Receive/transmit raw CAN frames in scripts
Receive/transmit raw CAN frames in a few lines of code - enabling tons of powerful use cases, incl. e.g. dynamic/conditional communication flows
DBC decode data in real-time
Load your own DBC file(s) to decode data in real-time, enabling e.g. visualization, alerting, conditional logic and more
Visualize your data in real-time via Grafana-MQTT
As an example demo use case, you can forward decoded CLX000/CANmod CAN-bus messages to an MQTT-broker - and visualise it in customizable Grafana dashboards
Try the Python API now!
Setup CAN based monitoring & alerting systems
Need to continuously monitor CAN based systems and automate alerts?
In many production/testing/development use cases, you may need to deploy automation scripts that records CAN data, DBC decodes it - and reacts according to e.g. certain patterns. For example, you may have a temperature-sensitive process where you could deploy one or more CANmod.temp units to measure temperatures, stream this data to a PC - and send an alert if certain thresholds are crossed. Or, you could use a CANmod.router to record CAN bus data during e.g. an automotive lab test and script it to transmit certain CAN based commands when event X, Y or Z happens.
Visualize data in 100% free & customizable dashboards
Need to deploy customized dashboards for visualizing your data?
Most CAN-USB software tools offer very limited visualization options. However, with the Python API you can easily integrate your CLX000/CANmod data streams with Grafana dashboards using the MQTT protocol. This lets you visualize your DBC decoded data in beautiful and customizable dashboardsa. This can be used locally on the host PC as a development/diagnostic tool - or it can be port forwarded for remote access, e.g. for systematic process monitoring.
Perform advanced CAN bus diagnostics/simulation
Need to perform tailored diagnostics of your CAN bus?
With the Python API, you gain far more granular control in your CAN bus diagnostics efforts, making it an excellent supplement to using e.g. the SavvyCAN GUI tool. For example, you can selectively extract specific CAN frames (or DBC decoded signals) of interest and perform targeted statistical analyses. Or, you can replay entire/partial log files by e.g. loading data recorded from the CANedge/CLX000 and outputting it onto your CAN bus. Replaying can be done quickly via the can-player tool - or with more granular control using Python scripts.
Create protocol-specific communication flows
Need to set up advanced and protocol-specific communication?
The python-can library offers a wide array of extensions, incl. for protocols like J1939, UDS, XCP, ISO-TP, CANopen and more. This lets you abstract away a lot of the code complexity required to work with a specific protocol - and lets you focus on quickly writing the communication required for your use case. With this, there are practically no limits to what you can achieve - as long as you know your way around Python. Further, with the CANmod.router you can deploy advanced cross-channel logic, e.g. transmitting custom CAN frames on CAN 4 in response to certain CAN patterns on CAN 1.
FAQ
Yes, you can connect any number of CANmod and/or CLX000 devices in parallel. Each device is registered with a unique COM port, which can be referenced via the various command line tools and in your Python scripts. This is useful if you e.g. need to monitor multiple CAN buses in parallel, or if you e.g. need to hook up several CANmod devices for monitoring.
We offer technical support on the basics, i.e. ensuring that you can get started with receiving/transmitting data as per our 'basic' script examples in the Python API documentation.
However, we do not offer technical support on custom scripts or general Python coding. Further, some of the demos we showcase (such as the Grafana-MQTT integration) come without support, though the documentation should make it fairly simple to set up.
Our CANedge/CLX000/CANmod devices all integrate with Python. We refer in general to this integration as a Python API. To be more specific, the 'Python API' refers to the below Python packages:
- python-can-csscan-mf4: This Python package adds support in python-can for the CANedge MDF log file format
- python-can-csscan-txt: This Python package adds support in python-can for the CLX000 TXT log file format
- python-can-csscan-serial: This Python package adds support in python-can for the serial interface used by the CLX000/CANmod
This article focuses on the python-can-csscan-serial package, while you can read about the log file Python API in our separate Python API article. Note also that the three packages above provide identical interfaces, meaning you can to a large extent abstract away the source of the data, whether it is a log file or a USB data stream.
As a supplement to the above Python packages, we also sometimes refer to processing Parquet data lakes in Python, see e.g. our intro to our MF4 decoders. This reflects the fact that we provide simple-to-use executables for DBC decoding CANedge/CLX000 log files to Parquet files. Python can be used to both run the executables (via sub processes) as well as analyze the Parquet files, hence this offers a very useful alternative route for analysing data - ideally suited for large-scale data processing.
Ready to analyze your CAN-USB data in Python?
Get your CANmod/CLX000 today!