Controller Area Network utilities (CAN utils)
A Rust library and CLI utility for creating and managing Linux CAN interfaces.
The tool supports setting up:
- Native CAN interfaces (
can0,can1, etc.) - SLCAN serial CAN adapters (
slcan0viaslcand) - Virtual CAN interfaces (
vcan0for testing)
It provides an interactive wizard that helps users configure CAN interfaces
without remembering the exact ip or slcand commands.
The library can also be used programmatically to generate and execute CAN setup commands.
Supported CAN Interface Types
Native CAN
Configures a hardware CAN controller using:
sudo ip link set can0 up type can bitrate 500000
Typically used with:
- SocketCAN PCI/USB adapters
- Raspberry Pi CAN HATs
- Embedded CAN controllers
SLCAN (Serial CAN)
For USB-serial CAN adapters using the slcand daemon.
Example command generated by the tool:
sudo slcand -c -o -f -s6 -t hw -S 3000000 /dev/ttyUSB0 slcan0
sudo ip link set up slcan0
Virtual CAN
Creates a virtual CAN bus for development or simulation.
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
This is extremely useful for testing CAN software without hardware.
Install
The library can be installed to create or manage interfaces.
cargo install --path .
Usage
Running the binary starts an interactive configuration wizard.
$ can-utils-rs
? Select CAN connection type
❯ Native CAN bus
Non-native CAN bus (slcand)
Virtual CAN bus (vcan)
The tool then asks for:
- interface name
- CAN bitrate
- serial device (for SLCAN)
Before applying changes it prints the commands that will be executed.
Interface Safety
The tool checks if an interface already exists and offers options:
Interface 'can0' already exists.
❯ Replace existing interface
Enter another interface name
Keep existing and skip setup
Cancel
When replacing an interface it will:
- bring the interface down
- remove it if needed (
vcanorslcan) - recreate it using the selected configuration
All system interaction uses standard Linux tools:
ipslcand
Linux Requirements
The following tools must be installed:
iproute2
can-utils
For virtual CAN interfaces:
sudo modprobe vcan
Design
The library separates concerns into several layers:
Prompt layer
↓
Config model
↓
Command plan
↓
Command execution
This allows the setup logic to be reused without the interactive UI.
License
MIT