Adapters
CAN Bus

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

ParameterTypeDefaultDescription
interfacestr"socketcan"CAN interface type (see table below)
channelstr"can0"CAN channel name
bitrateint500000CAN bitrate in bits per second
dbc_pathstr | NoneNonePath to DBC file for signal decoding
emit_rawboolTrueEmit raw CAN frame metrics
emit_decodedboolTrueEmit decoded signal metrics (requires dbc_path)
raw_prefixstr"can.raw"Metric name prefix for raw frames
filterslist | NoneNoneCAN ID filters (list of {"can_id": int, "can_mask": int})
receive_own_messagesboolFalseReceive own transmitted messages
source_idstr | NoneNoneOverride source ID for metrics from this adapter

Supported Interfaces

InterfacePlatformDescription
socketcanLinuxLinux SocketCAN (most common)
pcanWindows/LinuxPeak CAN USB adapters
vectorWindowsVector CANalyzer/CANoe
kvaserWindows/LinuxKvaser CAN interfaces
slcanAllSerial 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 vcan0

Then use interface="socketcan" with channel="vcan0":

adapter = CANAdapter(interface="socketcan", channel="vcan0")

Send test frames from another terminal:

cansend vcan0 123#DEADBEEF

See examples/can_basic.py for more.

Next Steps