Adapters

Supported adapters

Adapter

Platforms

Connection

SocketCAN

Linux

OS-configured CAN and virtual CAN interfaces

panda

Linux, macOS, Windows

USB

PEAK PCAN-USB FD

Linux, macOS, Windows

USB

Vector XL

Windows

Vector XL driver

J2534

Windows

Vendor PassThru DLL; raw CAN and native ISO-TP

Each adapter page documents its configuration and both async and sync classes.

Discovery and shared interface

Use CanAdapter() for discovery, or choose a backend from the table above. available_adapters() reports the backends compiled for the current platform; it does not probe connected hardware. Constructors open hardware immediately and block until ready in both APIs. The named adapter classes inherit the send, receive, and lifecycle methods documented below.

Hardware is released when its last owner is dropped. For deterministic cleanup, use aclose() or async with in the async API, or close() or with in the sync API.

adapter.recv_for(duration) subscribes immediately and returns an independent receiver including transmit echoes. Its timer and waiting start on the first anext() or async for iteration, so create it before sending. The sync API uses the same pattern with next() or for. The receiver closes when its duration ends and leaves existing recv() subscriptions unaffected:

responses = adapter.recv_for(0.1)
await adapter.send(request)
received = [frame async for frame in responses]

The synchronous equivalent is:

responses = adapter.recv_for(0.1)
adapter.send(request)
received = list(responses)

Asynchronous API

automotive.adapters.AdapterConfig: TypeAlias = automotive.adapters.SocketCanConfig | automotive.adapters.PandaConfig | automotive.adapters.PeakConfig | automotive.adapters.VectorConfig | automotive.adapters.J2534Config

Represent a union type

E.g. for int | str

automotive.adapters.available_adapters() → tuple[str, ...][source]

Return compiled backend names; this does not probe connected hardware.

class automotive.adapters.CanAdapter(config: SocketCanConfig | PandaConfig | PeakConfig | VectorConfig | J2534Config | None = None)[source]

Open a CAN adapter immediately, using discovery when no config is supplied.

Parameters:

config – Reusable backend configuration; None discovers an adapter with Rust defaults. Named classes such as PeakAdapter select a backend.

Construction blocks until hardware is ready, including inside an async function. Sends and receives are awaitable. Hardware is released when its last owner is dropped; transports, clients, and receivers retain ownership. Use await aclose() or async with for deterministic cleanup. Explicit closure invalidates dependent operations. A closed adapter cannot be reopened.

Raises:
  • ValueError – Explicit configuration is invalid.

  • NotSupportedError – The backend is unavailable on this platform.

  • AdapterError – Opening failed or discovery found no usable adapter.

property config: SocketCanConfig | PandaConfig | PeakConfig | VectorConfig | J2534Config | None

Backend configuration, or None for automatic discovery.

async open() → Self[source]

Return this already-open adapter; raise RuntimeError after closure.

async aclose() → None[source]

Close this adapter and wake dependent operations; repeated calls are safe.

property closed: bool

Whether this adapter has been explicitly closed.

async send(frame: Frame) → None[source]

Send a frame and await the backend’s transmit confirmation.

Parameters:

frame – Validated Classic, FD, or remote frame supported by the adapter.

Raises:

Confirmation strength depends on the backend; some emulate ACKs at submission. Cancelling this await cannot undo an already-sent frame.

recv() → Receiver[Frame][source]

Subscribe immediately to all frames, including transmit echoes.

Returns:

An async iterator of Frame objects. Create it before sending. Dropping it releases the subscription; aclose() releases it early. Slow consumers retain Rust’s drop/lag behavior.

recv_for(duration: float) → Receiver[Frame][source]

Subscribe now and receive CAN frames for duration seconds when consumed.

Returns an async iterator including transmit echoes. The independent subscription is created immediately, but its duration starts on the first anext() or async-for iteration. It finishes early if the adapter closes and does not affect existing recv() subscriptions. duration must be finite and nonnegative.

Synchronous API

Named adapters in automotive.sync.adapters inherit the blocking lifecycle, send, and receive methods from CanAdapter and accept the same configuration as the async API.

class automotive.sync.adapters.CanAdapter(config: SocketCanConfig | PandaConfig | PeakConfig | VectorConfig | J2534Config | None = None)[source]

Open a CAN adapter immediately, using discovery when no config is supplied.

Parameters:

config – Shared backend configuration; None discovers an adapter with Rust defaults. Named classes such as PeakAdapter select a backend.

Hardware is released when its last owner is dropped. Transports, clients, and receivers retain ownership. close() and with support deterministic cleanup. Explicit closure invalidates dependent operations, and a closed adapter cannot be reopened. Opening errors are raised by construction.

property config: SocketCanConfig | PandaConfig | PeakConfig | VectorConfig | J2534Config | None

Backend configuration, or None for automatic discovery.

open() → Self[source]

Return this already-open adapter; raise RuntimeError after closure.

send(frame: Frame) → None[source]

Send a frame and block for the backend’s transmit confirmation.

Parameters:

frame – A Classic, FD, or remote frame supported by the adapter.

Raises:

Confirmation strength depends on the backend. Interrupting this call cannot undo a frame that has already been sent.

recv() → Receiver[Frame][source]

Subscribe immediately to CAN frames, including transmit echoes.

Returns:

A blocking iterator of Frame objects supporting with and close(). Subscribe before sending. Dropping the receiver releases its subscription; close() releases it early.

recv_for(duration: float) → Receiver[Frame][source]

Subscribe now and receive CAN frames for duration seconds when consumed.

Returns a blocking iterator including transmit echoes. The independent subscription is created immediately, but its duration starts on the first next() or for iteration. It finishes early if the adapter closes and does not affect existing recv() subscriptions. duration must be finite and nonnegative.

close() → None

Release the resource and wake pending operations; idempotent.

property closed: bool

Whether this resource or its owning parent has been closed.