Adapters¶
Supported adapters¶
Adapter |
Platforms |
Connection |
|---|---|---|
Linux |
OS-configured CAN and virtual CAN interfaces |
|
Linux, macOS, Windows |
USB |
|
Linux, macOS, Windows |
USB |
|
Windows |
Vector XL driver |
|
Windows |
Vendor PassThru DLL; raw CAN and native ISO-TP |
Each adapter page documents its configuration and both async and sync classes.
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 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:
TimeoutError – A configured transmit deadline expired.
TransmissionCancelledError – A queue clear invalidated this send.
NotSupportedError – This backend cannot encode the frame.
AdapterError – The hardware operation failed.
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.
- 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:
TimeoutError – A configured transmit deadline expired.
TransmissionCancelledError – A queue clear invalidated this send.
NotSupportedError – The backend cannot encode this frame.
AdapterError – The hardware operation failed.
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.