-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehicle_diagnostic _tool.py
55 lines (50 loc) · 1.95 KB
/
Vehicle_diagnostic _tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import obd
import time
def connect_to_vehicle():
# Attempt to connect to the OBD-II adapter
connection = obd.OBD() # Auto-connects to the first available port
if connection.is_connected():
print("Connected to vehicle!")
return connection
else:
print("Failed to connect to vehicle. Ensure the adapter is plugged in.")
return None
def get_vehicle_info(connection):
# Retrieve vehicle information
print("\nFetching vehicle information...")
commands = [obd.commands.VIN, obd.commands.ELM_VERSION, obd.commands.OBD_VERSION]
for cmd in commands:
response = connection.query(cmd)
print(f"{cmd.name}: {response.value if response.is_successful() else 'N/A'}")
def read_diagnostic_codes(connection):
# Retrieve diagnostic trouble codes (DTCs)
print("\nReading diagnostic trouble codes...")
response = connection.query(obd.commands.GET_DTC)
if response.is_successful():
dtcs = response.value
if dtcs:
for code, description in dtcs:
print(f"Code: {code}, Description: {description}")
else:
print("No trouble codes found.")
else:
print("Failed to retrieve trouble codes.")
def monitor_live_data(connection):
# Monitor real-time engine data
print("\nMonitoring live data (Press Ctrl+C to stop)...")
try:
while True:
rpm = connection.query(obd.commands.RPM)
speed = connection.query(obd.commands.SPEED)
print(f"RPM: {rpm.value if rpm.is_successful() else 'N/A'}, "
f"Speed: {speed.value if speed.is_successful() else 'N/A'}")
time.sleep(1)
except KeyboardInterrupt:
print("\nStopped live data monitoring.")
if __name__ == "__main__":
connection = connect_to_vehicle()
if connection:
get_vehicle_info(connection)
read_diagnostic_codes(connection)
monitor_live_data(connection)
connection.close()