Protocols

class obdii.protocols.ProtocolCAN[source]

Bases: ProtocolBase

Supported Protocols: - [0x06] ISO 15765-4 CAN (11 bit ID, 500 Kbaud) - [0x07] ISO 15765-4 CAN (29 bit ID, 500 Kbaud) - [0x08] ISO 15765-4 CAN (11 bit ID, 250 Kbaud) - [0x09] ISO 15765-4 CAN (29 bit ID, 250 Kbaud) - [0x0A] SAE J1939 CAN (29 bit ID, 250 Kbaud) - [0x0B] USER1 CAN (11 bit ID, 125 Kbaud) - [0x0C] USER2 CAN (11 bit ID, 50 Kbaud)

Required configuration: - HEADER_ON

static to_frames(lines: List[bytes], header_len: int) List[CANFrame][source]

Parse a list of raw ELM327 lines into CANFrame objects.

Frame anatomy and examples

Single Frame (SF) - complete message in one line

7E8 04 41 0C 41 C2
|   |  |
|   |  +-- payload: mode (41) + PID (0C) + data (41 C2)
|   +-- PCI: high nibble 0x0 = SF, low nibble 0x4 = DLC (4 bytes)
+-- ECU address (11-bit)

First Frame (FF) - first frame of a multi-frame message

7E8 10 14 49 02 01 57 50 30
|   |  |  |
|   |  |  +-- payload start: mode (49) + PID (02) + data (57 50 30)
|   |  +-- DLC low byte: 0x14 = 20 -> DLC(20 bytes)
|   +-- PCI: high nibble 0x1 = FF, low nibble 0x0 = DLC high bits
+-- ECU address (11-bit)

Consecutive Frame (CF) - continuation of a multi-frame message

7E8 21 5A 5A 5A 39 39 5A 54
|   |  |
|   |  +-- payload continuation (no mode, no PID, only data)
|   +-- PCI: high nibble 0x2 = CF, low nibble 0x1 = SN
+-- ECU address (11-bit)
static to_message(frames: List[CANFrame], command: Command) List[int] | None[source]
parse_response(response_base: ResponseBase) Response[source]
class obdii.protocols.ProtocolJ1850[source]

Bases: ProtocolBase

Supported Protocols: - [0x01] SAE J1850 PWM (41.6 Kbaud) - [0x02] SAE J1850 VPW (10.4 Kbaud)

parse_response(response_base: ResponseBase) Response[source]
class obdii.protocols.ProtocolKWP[source]

Bases: ProtocolBase

Supported Protocols: - [0x03] ISO 9141-2 (5 baud init, 10.4 Kbaud) - [0x04] ISO 14230-4 KWP (5 baud init, 10.4 Kbaud) - [0x05] ISO 14230-4 KWP (fast init, 10.4 Kbaud)

Required configuration: - HEADER_ON

static to_frames(lines: List[bytes], protocol: Protocol) List[KWPFrame][source]

Parse a list of raw ELM327 lines into KWPFrame objects.

Frame anatomy and examples

ISO 9141-2 Frame - fixed 3 byte header

48 6B 11 41 0C 1F 40 70
|  |  |  |           |
|  |  |  |           +-- checksum: sum of all previous bytes % 256
|  |  |  +-- payload: mode (41) + PID (0C) + data (1F 40)
|  |  +-- source address (sender ECU)
|  +-- target address (receiver)
+-- priority

ISO 14230-4 Frame (Standard Header) - length inline within FMT byte

84 F1 11 41 0C 1F 44 36
|  |  |  |           |
|  |  |  |           +-- checksum: sum of all previous bytes % 256
|  |  |  +-- payload: mode (41) + PID (0C) + data (1F 44)
|  |  +-- source address (sender ECU)
|  +-- target address (receiver)
+-- FMT: addressing mode (bits 7:6) + payload length (bits 5:0 = 4 bytes)

ISO 14230-4 Frame (Extended Header) - length in a separate LEN byte

80 F1 11 04 41 0C 1F 44 32
|  |  |  |  |           |
|  |  |  |  |           +-- checksum: sum of all previous bytes % 256
|  |  |  |  +-- payload: mode (41) + PID (0C) + data (1F 44)
|  |  |  +-- LEN: payload length byte (present because bits 5:0 of FMT = 0)
|  |  +-- source address (sender ECU)
|  +-- target address (receiver)
+-- FMT: addressing mode (bits 7:6) + length flag (bits 5:0 = 0)
static to_message(frames: List[KWPFrame], command: Command) List[int] | None[source]
parse_response(response_base: ResponseBase) Response[source]