Blog · 2026-11-10
DTC checking while engine running
Stefan Bogdanescu
Founder & Senior Architect
The Volatility of Live OBD-II Scans
When working with embedded systems or automotive diagnostic tools, there is a persistent piece of folklore that advises against reading Diagnostic Trouble Codes (DTCs) while the engine is running. This rule often surfaces in forums when developers are debugging CAN bus data or writing scripts to interface with ECUs via OBD-II protocols. While modern vehicles run millions of lines of code per second without issue, this caution stems from fundamental differences between how active diagnostics operate versus static retrieval methods.
The core technical reason lies in the state management of the fault detection logic within the Engine Control Unit (ECU). Most diagnostic standards, such as ISO 15031-6 or SAE J1979, distinguish between retrieving "pending" codes and confirming "confirmed" codes. When a code is set, the ECU typically enters a freeze-frame mode or suspends certain active monitoring routines to prevent data corruption during the fault recording phase. If you initiate a scan request (like reading PID 0x43 for OBD status) while the engine is idling or under load, you risk interrupting the very process that sets the code or clears it based on drive cycles.
Consider a scenario where an emission monitor fails due to a loose gas cap. The ECU detects this discrepancy and prepares to log a DTC (e.g., P0455). However, the logic might be mid-execution when a diagnostic session is opened. In some legacy architectures, reading the status byte during this transition can cause the ECU to reset its internal flags, inadvertently clearing the code before it is fully confirmed in non-volatile memory. Conversely, if the system interprets the scan request as an attempt to clear faults without proper termination, you might see a false negative where a critical issue disappears from the report simply because of the timing of your query.
In software development terms, this behaves similarly to querying a database transaction that is currently in an inconsistent state. If you execute a SELECT statement while an UPDATE operation is holding locks or writing to the same table, you may receive stale data, partial records, or trigger application errors depending on the isolation level. Similarly, reading DTCs live creates a race condition between the monitoring thread and the reporting interface.
Implementation Considerations for Remote Diagnostics
When building a remote diagnostic tool using a library like python-can to communicate with an ECU, it is safer to adhere to the standard "Scan Mode" flow rather than attempting real-time polling. The protocol generally dictates that you must first open a session, request a list of pending codes, and only then proceed to read them.
A naive implementation might look like this:
# Risky approach: Continuous live reading
while True:
response = ec.read_dtc()
if response:
print(f"Code found: {response}")
time.sleep(0.1)
This loop sends constant requests over the bus, potentially flooding the ECU with interrupts during critical monitoring windows. A more robust implementation utilizes a structured session where you read codes only after specific conditions are met or when explicitly requested by the user interface. If using OBD-II PID 0x43 (Status Information), ensure that your software waits for the "Drive Cycle" to complete if the system indicates monitors are still running, rather than trying to force a status update mid-drive cycle.
The Role of Clear vs. Read Commands
Another pitfall involves the interaction between reading codes and clearing them. Many ECUs allow you to clear codes via PID 0x4C or specific UDS commands (U0102). If your application reads the code list, displays it to the user, and then attempts to clear it all while the engine is running without verifying if the fault condition has actually been resolved, you are effectively masking an ongoing issue. This creates a "ghost" scenario where the light turns off, but the ECU continues to log events in memory that aren't reflected until the next restart or full re-scan.
Furthermore, some manufacturers implement proprietary logic where accessing certain PIDs modifies the internal state machine of the ECU. While standard OBD-II modes are generally safe for reading, vendor-specific extensions (Mode $01–$09) may behave unpredictably under active engine load due to interrupt prioritization. Always consult the specific vehicle's datasheet before assuming a read-only operation is atomic.
Ultimately, avoiding live DTC checks isn't about preventing hardware damage; it's about ensuring data integrity and logical consistency in how faults are reported. By treating diagnostic sessions as discrete transactions rather than continuous streams, developers can avoid false negatives and ensure their tools reflect the true health of the powertrain system.