CAN Bus Adapter
The CAN bus adapter reads CAN frames and optionally decodes them into named signals using a DBC file.
Install
pip install plexus-agent[can]Basic Usage
from plexus import Plexus
from plexus.adapters import CANAdapter
px = Plexus(api_key="plx_xxx", source_id="vehicle-001")
adapter = CANAdapter(
interface="socketcan",
channel="can0",
dbc_path="vehicle.dbc", # optional: decode signals
)
with adapter:
while True:
for metric in adapter.poll():
px.send(metric.name, metric.value, tags=metric.tags)When a DBC file is loaded, each decoded signal becomes a separate metric.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
interface | str | "socketcan" | CAN interface type (see table below) |
channel | str | "can0" | CAN channel name |
bitrate | int | 500000 | CAN bitrate in bits per second |
dbc_path | str | None | None | Path to DBC file for signal decoding |
emit_raw | bool | True | Emit raw CAN frame metrics |
emit_decoded | bool | True | Emit decoded signal metrics (requires dbc_path) |
raw_prefix | str | "can.raw" | Metric name prefix for raw frames |
filters | list | None | None | CAN ID filters (list of {"can_id": int, "can_mask": int}) |
receive_own_messages | bool | False | Receive own transmitted messages |
source_id | str | None | None | Override source ID for metrics from this adapter |
Supported Interfaces
| Interface | Platform | Description |
|---|---|---|
socketcan | Linux | Linux SocketCAN (most common) |
pcan | Windows/Linux | Peak CAN USB adapters |
vector | Windows | Vector CANalyzer/CANoe |
kvaser | Windows/Linux | Kvaser CAN interfaces |
slcan | All | Serial CAN adapters (e.g., CANable) |
Virtual CAN for Testing
Set up a virtual CAN interface on Linux for development without hardware:
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0Then use interface="socketcan" with channel="vcan0":
adapter = CANAdapter(interface="socketcan", channel="vcan0")Send test frames from another terminal:
cansend vcan0 123#DEADBEEFSee examples/can_basic.py for more.
Next Steps
- MQTT Bridge -- Bridge MQTT brokers to Plexus
- MAVLink -- Connect drones and autonomous vehicles
- CLI Reference -- Run adapters from the command line