CAN¶
automotive.can provides frames and identifiers, with bus timing in
automotive.can.bitrate. The same types are available through
automotive.sync.can and automotive.sync.can.bitrate.
Frames and identifiers¶
In both APIs, identifiers compare directly with numbers using their raw value:
frame.id == rx_addr works when rx_addr is an integer. Ordering comparisons
also support range checks such as 0x600 <= frame.id < 0x800. Error frames have
no identifier; check frame.id is not None before ordering those frames.
Equality between two Identifier objects also requires the same standard or
extended format.
Validated CAN identifiers and Classic, FD, remote, and error frames.
- class automotive.can.ErrorFlag(*values)[source]¶
CAN wire error flags; these are not OS-specific error reports.
- ACTIVE = 0x00¶
- PASSIVE = 0x01¶
- class automotive.can.Frame(id: int | Identifier | None = None, data: bytes | bytearray | memoryview = b'', bus: int = 0, fd: bool | None = None, brs: bool = False, esi: bool = False, loopback: bool = False, kind: str = 'data', dlc: int | None = None, error_flag: ErrorFlag | None = None)[source]¶
A CAN frame validated by Rust, with immutable payload bytes.
- Parameters:
id – Integer or explicit Identifier; None only for error frames.
data – Bytes, bytearray, or a contiguous byte-oriented memoryview.
bus – Bus index, default zero.
fd – Select CAN FD. None chooses FD for payloads longer than eight bytes.
brs – Enable FD bitrate switching; requires FD and adapter support.
esi – Set the FD error-state indicator.
loopback – Whether this is a transmit-confirmation echo.
kind – “data”, “remote”, or “error”; prefer the named constructors.
dlc – Remote-request DLC (0–15); computed for data frames.
error_flag – Active/passive flag for error frames only.
- Raises:
ValueError – Rust rejects the frame length, identifier, or flag combination.
Classic payloads contain 0–8 bytes. FD payload lengths are 0–8, 12, 16, 20, 24, 32, 48, or 64, without automatic padding. Error frames can be represented but cannot currently be transmitted by adapters.
- id: Identifier | None¶
- data: bytes¶
- bus: int¶
- fd: bool¶
- brs: bool¶
- esi: bool¶
- loopback: bool¶
- kind: str¶
- dlc: int | None¶
- classmethod remote(id: int | Identifier, dlc: int = 8, *, bus: int = 0) Self[source]¶
Construct a Classic remote request without a payload.
- Parameters:
id – Arbitration ID, inferring format for integer inputs.
dlc – Four-bit requested DLC. Codes 8–15 request eight bytes.
bus – Bus index, default zero.
- class automotive.can.Identifier(value: int, is_extended: bool = False)[source]¶
A validated CAN arbitration ID, preserving its wire format.
Comparisons with numbers use the raw value, so
frame.id == 0x123and0x600 <= frame.id < 0x800work directly. Equality between identifiers also compares the wire format.- Parameters:
value – Unsigned arbitration ID. Standard IDs fit in 11 bits; extended IDs fit in 29 bits.
is_extended – Select extended format, including for values below 0x800.
- Raises:
ValueError – The value does not fit the selected wire format.
- value: int¶
- is_extended: bool¶