The Elm327Device provides low-level serial communication with an ELM327-compatible automotive diagnostic device. It sends raw ELM327 commands and returns Elm327Response objects.
OBD-II request modeling and PID decoding belong in protocols.obd2. An adapter that translates between those protocol models and this device belongs in controllers.automotive.
The default connection is /dev/rfcomm0 at 38400 baud. Both values can be configured when creating the device:
On connection, the device sends ATZ, ATE0, ATL0, ATS0, ATH1, and ATSP0 to reset and configure the ELM327.
Initialization commands use a settling delay. Normal commands do not use a fixed delay; the device starts reading immediately and completes the command when it receives the ELM327 > prompt.
The device requires pyserial:
A Bluetooth Classic ELM327 uses the Serial Port Profile (SPP). BlueZ exposes that connection as an RFCOMM serial device such as /dev/rfcomm0, which Elm327Device opens through pyserial.
Use the setup helper with the address reported by the Bluetooth scanner:
The helper:
bluetoothctl./dev/rfcomm0 now and on future boots, restarting the RFCOMM connection if it drops.dialout.Specify the channel only when SDP discovery fails:
The host installer can install the feature and configure RFCOMM together:
Pairing and RFCOMM configuration are host responsibilities. Elm327Device intentionally begins at the serial-device boundary and does not invoke bluetoothctl, sdptool, or rfcomm itself.
The component test opens a real serial connection, initializes the ELM327, and lets you send raw adapter or OBD-II commands. It does not emulate an adapter and does not decode OBD-II PID values.
Use this raw test first to separate serial, RFCOMM, and ELM327 problems from OBD-II parsing problems. Once commands such as ATI and 0100 work, use the decoded automotive component test to exercise Elm327ObdAdapter and the PID decoders.
Before running the test:
/dev/rfcomm0.Serial devices are commonly assigned to the dialout group. If necessary, add your user to that group, then log out and back in:
Activate the project virtual environment so that pyserial and the project packages are available:
From the project root, run:
The test connects to /dev/rfcomm0 at 38400 baud by default. After the ELM327 initialization commands succeed, enter commands at the prompt:
Useful initial commands include:
ATI — report the adapter identification string.ATDP — report the selected vehicle protocol.0100 — request the vehicle's supported Mode 01 PIDs.Enter quit or exit, press Ctrl+D, or press Ctrl+C to disconnect and stop the test.
Use --command to connect, send one command, print its response, and exit:
Use --port and --baud for an adapter with different serial settings:
Display all command-line options with:
Unable to connect usually means the serial path is wrong, RFCOMM is not connected, the user lacks device permission, or another process owns the port.NO DATA is an ELM327 response, not a connection failure. It can mean the vehicle is off, no ECU answered, or the requested PID is unsupported.ATI identifies what the adapter claims rather than verifying its firmware.