import logging import obd logging.getLogger("obd").setLevel(logging.CRITICAL) def pause(): input("\nPress ENTER to return to menu...") def connect(): print("Checking for OBD adapter...") connection = obd.OBD(fast=False) if connection.is_connected(): print("Connected") else: print("No OBD device found") return connection def read_codes(connection): print("\nTrouble Codes") print("-------------") if connection is None or not connection.is_connected(): print("Not connected to vehicle") pause() return response = connection.query(obd.commands.GET_DTC) if response.is_null(): print("Unable to read trouble codes") elif response.value: for code in response.value: print(code) else: print("No trouble codes found") pause() def live_data(connection): print("\nLive Data") print("---------") if connection is None or not connection.is_connected(): print("Not connected to vehicle") pause() return commands = [ ("RPM", obd.commands.RPM), ("Speed", obd.commands.SPEED), ("Coolant Temp", obd.commands.COOLANT_TEMP), ] for name, command in commands: response = connection.query(command) if response.is_null(): print(name + ": Not supported") else: print(name + ":", response.value) pause() def vehicle_info(connection): print("\nVehicle Information") print("-------------------") if connection is None or not connection.is_connected(): print("Not connected to vehicle") pause() return vin = connection.query(obd.commands.VIN) if vin.is_null(): print("VIN: Not available") elif vin.value: print("VIN:", vin.value) else: print("VIN: Not available") pause() def main(): connection = None while True: print("\nOBD Tool") if connection is not None and connection.is_connected(): print("Status: Connected") else: print("Status: Not Connected") print("1. Connect") print("2. Read Codes") print("3. Live Data") print("4. Vehicle Info") print("Q. Quit") choice = input("> ") if choice == "1": connection = connect() elif choice == "2": read_codes(connection) elif choice == "3": live_data(connection) elif choice == "4": vehicle_info(connection) elif choice.lower() == "q": break else: print("Invalid choice") main()