examples/CAN Bus Example/README.md
This example shows how to use CAN bus with Serial Studio. It includes a car simulator that sends realistic vehicle data.
VirtualCANcan0cd "examples/CAN Bus Example"
python3 ecu_simulator.py --virtual
You will see CAN messages in Serial Studio's Console (View → Console).
Switch Console to Hexadecimal mode to see the raw data.
To create a dashboard with gauges, plots, and organized data:
Make sure Serial Studio is connected (VirtualCAN or hardware).
examples/CAN Bus Example/example_vehicle.dbcA window appears showing:
Look at the summary, then click Create Project.
vehicle_can.ssprojReopen the project editor to:
The ECU simulator sends realistic automotive data:
Engine ECU (100 Hz)
0x100: RPM (0-8000), Speed (0-300 km/h)0x101: Coolant Temp, Intake Temp, Engine Load0x102: Throttle Position, Fuel PressureTransmission ECU (50 Hz)
0x200: Current Gear, Trans Temp, Torque Converter SlipBattery Management (10 Hz)
0x400: Pack Voltage, Pack Current0x401: State of Charge, Pack Temperature0x402: Individual Cell VoltagesChassis/ABS (100 Hz)
0x600: Individual Wheel Speeds0x601: Brake Pressure0x700: Steering AngleBody Control (10 Hz)
0x300: Lights (headlights, turn signals)0x301: Doors (open/closed status)Instrument Cluster (5 Hz)
0x500: Odometer, Trip Distance0x501: Fuel Level, Fuel Consumptionecu_simulator.py: All-in-one simulator (VirtualCAN, PCAN, SocketCAN, Vector)example_vehicle.dbc: DBC database fileREADME.md: This fileWorks on macOS/Windows/Linux without hardware!
# Simple - just run it
python3 ecu_simulator.py --virtual
# Custom update rate
python3 ecu_simulator.py --virtual -r 100
# Custom channel
python3 ecu_simulator.py --virtual -c can1
In Serial Studio:
VirtualCANcan0 (or your specified channel)Serial Studio supports all Qt CAN backends:
| Backend | Platforms | Typical Use |
|---|---|---|
| VirtualCAN | All | Testing without hardware (TCP-based) |
| SocketCAN | Linux | Most USB-CAN adapters on Linux |
| PEAK CAN | All | PEAK PCAN-USB adapters |
| Vector CAN | Windows/Linux | Vector VN-series interfaces |
| PassThru CAN | Windows | SAE J2534 Pass-Thru devices |
| SysTec CAN | Windows | SYS TEC USB-CANmodul |
| Tiny CAN | Windows | MHS Tiny-CAN adapters |
python3 ecu_simulator.py -i pcan -c PCAN_USBBUS1
In Serial Studio:
PEAK CANPCAN_USBBUS1500000# Setup virtual CAN interface
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
# Run simulator
python3 ecu_simulator.py -i socketcan -c vcan0
In Serial Studio:
SocketCANvcan0500000python ecu_simulator.py -i pcan -c PCAN_USBBUS1
In Serial Studio:
PEAK CANPCAN_USBBUS1500000Option 1: Virtual CAN (No Hardware)
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
Option 2: Physical CAN Hardware
# For SocketCAN-compatible devices (most USB-CAN adapters)
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
Install CAN Hardware Drivers:
Connect Hardware and verify in Device Manager
Launch Serial Studio and check driver dropdown
VirtualCAN: Should always be available. If not, Qt installation may be incomplete.
Physical Hardware:
sudo modprobe vcan or sudo modprobe canVirtualCAN Mode:
Error: Failed to connect to Qt VirtualCAN
Solution: Start Serial Studio FIRST, connect to VirtualCAN, THEN run the simulator.
The first client to connect creates the TCP server.
Hardware Mode:
# Check if python-can is installed
pip install python-can
# Verify hardware is detected
python3 -c "import can; print(can.detect_available_configs())"
The raw CAN frames are binary data. To see meaningful information:
Edit ecu_simulator.py:
# Change driving pattern (line ~425)
if cycle_time < 15:
self.target_speed = min(200, cycle_time * 10) # Faster acceleration
# Adjust message rates (line ~667)
rates = {
'engine': 200, # Increase to 200 Hz
'transmission': 100,
# ...
}
Use DBC editors to create your own CAN databases:
Then import into Serial Studio as described above.
Linux Command Line:
candump vcan0 # View all frames
candump -t a vcan0 # With timestamps
cansend vcan0 100#1122334455 # Send test frame
Serial Studio Console:
[ID_H ID_L DLC DATA...]