ODX Tools

11.0.6 · active · verified Tue Apr 14

odxtools is a Python library providing utilities to work with the ODX (Open Diagnostic Data eXchange) standard, primarily for automotive diagnostics. It enables parsing and internalizing ODX diagnostic database files, as well as encoding and decoding diagnostic messages for Electronic Control Units (ECUs). The library is actively maintained with frequent minor releases and occasional major version updates; the current version is 11.0.6.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load an ODX database from a .pdx file and iterate through the available ECUs and their services. It includes a placeholder for a PDX file, which you would replace with your actual diagnostic database.

import odxtools
import os

# This example requires an actual .pdx file. 
# For demonstration, we'll assume 'path/to/my_ecu.pdx' exists.
# Replace 'path/to/my_ecu.pdx' with your ODX database file.
# You can find example .pdx files in the odxtools GitHub repository.

# Create a dummy .pdx file for demonstration purposes if it doesn't exist
# In a real scenario, you would have your actual ODX/PDX file.
pdx_file_path = 'my_ecu.pdx'
if not os.path.exists(pdx_file_path):
    with open(pdx_file_path, 'w') as f:
        f.write("<ODXLINK><DATABASE><CONTAINER name='DummyECU'/></DATABASE></ODXLINK>")
    print(f"Created a dummy file: {pdx_file_path}")

try:
    # Load an ODX database from a .pdx file
    db = odxtools.load_pdx_file(pdx_file_path)

    # List available ECUs (Electronic Control Units)
    print(f"Loaded database contains {len(db.ecus)} ECUs:")
    for ecu in db.ecus:
        print(f"- {ecu.short_name} (ID: {ecu.oid if hasattr(ecu, 'oid') else 'N/A'})")

    # Example: Accessing services of the first ECU (if any)
    if db.ecus:
        first_ecu = db.ecus[0]
        print(f"\nServices offered by {first_ecu.short_name}:")
        if hasattr(first_ecu, 'services') and first_ecu.services:
            for service in first_ecu.services:
                print(f"- {service.short_name}")
        else:
            print("  No services found for this ECU in the dummy file.")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(pdx_file_path):
        os.remove(pdx_file_path)
        print(f"Cleaned up dummy file: {pdx_file_path}")

view raw JSON →