CAN Bus ECU Simulator
Demonstrates CAN bus usage with a physics-based ECU simulator that sends realistic vehicle data and DBC file import for automatic dashboard generation. Needs the widget-extension example installed for its custom level-bar widget.
What you'll learn: a CAN Bus source with DBC file import for automatic dashboard generation, a Lua frame parser, a Data Grid, and a custom level-bar widget extension.
Prerequisites: Serial Studio Pro, Python 3 for the ECU simulator, and the widget-extension example installed first.
This example shows how to use CAN bus with Serial Studio. It includes a car simulator that sends realistic vehicle data.
CAN Bus support needs a Serial Studio Pro license. See serial-studio.com for details.
The bundled project (ecu_simulator.ssproj) uses the com.example.level-bar custom widget, so
install the widget-extension example first or that gauge falls back to a
missing-widget placeholder.
Quick Start (No Hardware Required!)
1. Start Serial Studio
- In the Setup panel, select CAN Bus from the Connection dropdown
- Select CAN Driver:
Virtual CAN - Select Interface:
can0 - Click Connect
2. Run the Simulator
cd "examples/CAN Bus Example"
python3 ecu_simulator.py --virtual
3. See Live CAN Data
You will see CAN messages in Serial Studio's Console view (shown automatically until a frame is parsed, or toggle it from the Tools menu).
Switch Console to Hexadecimal mode to see the raw data.
Importing the DBC File
To create a dashboard with gauges, plots, and organized data:
Step 1: Connect to CAN Bus
Make sure Serial Studio is connected (Virtual CAN or hardware).
Step 2: Import DBC Database
- In the Setup → CAN Bus panel, click Import DBC File…
- Navigate to
examples/CAN Bus Example/ - Select
ecu_simulator.dbc - Click Open
Step 3: Review the Preview
A window appears showing:
- All CAN messages from the DBC file
- Message IDs (0x100, 0x101, etc.)
- How many signals each message has
- Total number of signals
Look at the summary, then click Create Project.
Step 4: Save the Project
- Serial Studio generates:
- Lua frame parser (decodes CAN frames automatically)
- Groups for each CAN message
- Datasets for each signal
- Auto-assigned widgets (Gauges, Meters, Bars)
- The Project Editor opens automatically
- Click the Save toolbar button (or Ctrl+S)
- Save as
vehicle_can.ssproj
Step 5: View the Dashboard
- Close the Project Editor
- The Dashboard automatically loads your project
- You'll see:
- Engine RPM meter
- Vehicle Speed meter
- Coolant Temperature bar
- Battery State of Charge bar
- And many more widgets for all signals
Step 6: Customize (Optional)
Reopen the project editor to:
- Rearrange widget layout
- Change widget types
- Adjust min/max ranges
- Modify titles and units
What's in This Example
Simulated CAN Messages
The ECU simulator sends realistic automotive data:
Engine ECU (100 Hz)
0x100: RPM (0-7000), Speed (0-200 km/h)0x101: Coolant Temp, Intake Temp, Engine Load0x102: Throttle Position, Fuel Pressure
Transmission ECU (50 Hz)
0x200: Current Gear, Trans Temp, Torque Converter Slip
Battery Management (10 Hz)
0x400: Pack Voltage, Pack Current0x401: State of Charge, Pack Temperature0x402: Individual Cell Voltages
Chassis/ABS (100 Hz)
0x600: Individual Wheel Speeds0x601: Brake Pressure0x700: Steering Angle
Body Control (10 Hz)
0x300: Lights (headlights, turn signals)0x301: Doors (open/closed status)
Instrument Cluster (5 Hz)
0x500: Odometer, Trip Distance0x501: Fuel Level, Fuel Consumption
Files
ecu_simulator.py: All-in-one simulator (Virtual CAN, PCAN, SocketCAN, Vector)ecu_simulator.dbc: DBC database fileecu_simulator.ssproj: Ready-made project built from the DBC file, then tidied into data grids so every signal is visible at a glance (load it to skip the import steps)README.md: This file
Usage Options
Virtual CAN (Recommended for Testing)
Works 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:
- Driver:
Virtual CAN - Interface:
can0(or your specified channel)
Physical Hardware
Serial Studio supports all Qt CAN backends:
| Backend | Platforms | Typical Use |
|---|---|---|
| Virtual CAN | 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 |
macOS with PEAK PCAN-USB
python3 ecu_simulator.py -i pcan -c PCAN_USBBUS1
In Serial Studio:
- Driver:
PEAK CAN - Interface:
PCAN_USBBUS1 - Bitrate:
500000
Linux with SocketCAN
# 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:
- Driver:
SocketCAN - Interface:
vcan0 - Bitrate:
500000
Windows with PEAK PCAN
python ecu_simulator.py -i pcan -c PCAN_USBBUS1
In Serial Studio:
- Driver:
PEAK CAN - Interface:
PCAN_USBBUS1 - Bitrate:
500000
Hardware Setup (If Using Physical CAN)
macOS
- Buy CAN Hardware: PEAK PCAN-USB adapter (~$150-200)
- Install Drivers: PEAK macOS Drivers
- Restart your Mac
- Verify: Check that Serial Studio detects the interface
Linux
Option 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
Windows
-
Install CAN Hardware Drivers:
-
Connect Hardware and verify in Device Manager
-
Launch Serial Studio and check driver dropdown
Troubleshooting
"No CAN Drivers Found"
Virtual CAN: Should always be available. If not, Qt installation may be incomplete.
Physical Hardware:
- macOS/Windows: Install CAN hardware drivers first
- Linux: Load kernel modules:
sudo modprobe vcanorsudo modprobe can
Python Simulator Won't Connect
Virtual CAN Mode:
Error: Failed to connect to Qt VirtualCAN
Solution: Start Serial Studio FIRST, connect to Virtual CAN, 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())"
No Data in Serial Studio
- Check Console: open the Console view (shown automatically, or toggle it from the Tools menu), switch to Hexadecimal mode
- Verify Connection: Status bar should show "Connected"
- Check Bitrate: Must match on both sides (500000)
- Verify Interface: Both must use same interface name
Data Shows as Dots/Garbage
The raw CAN frames are binary data. To see meaningful information:
- Import the DBC file (see "Importing the DBC File" section above)
- Or switch Console to Hexadecimal mode to see raw hex values
Advanced Customization
Modify Simulation Behavior
Edit ecu_simulator.py:
# Change driving pattern (line ~675)
if cycle_time < 15:
self.target_speed = min(200, cycle_time * 10) # Faster acceleration
# Adjust message rates (line ~1015)
rates = {
"engine": 200, # Increase to 200 Hz
"transmission": 100,
# ...
}
Create Custom DBC Files
Use DBC editors to create your own CAN databases:
- Vector CANdb++ Editor
- PEAK PCAN-Explorer
- SavvyCAN (Free, open-source)
Then import into Serial Studio as described above.
Monitor CAN Traffic
Linux Command Line:
candump vcan0 # View all frames
candump -t a vcan0 # With timestamps
cansend vcan0 100#1122334455 # Send test frame
Serial Studio Console:
- Open the Console view (shown automatically, or toggle it from the Tools menu)
- Set Display Mode to Hexadecimal
- All CAN frames shown in format:
[ID_H ID_L DLC DATA...]
See Also
- Serial Studio Documentation
- Qt VirtualCAN Documentation
- python-can Documentation
- DBC File Format Specification
- PEAK PCAN Products
- Vector CAN Products
License
This example is dual-licensed under GPL-3.0 and the Serial Studio Commercial License.