@@ -68,7 +68,7 @@ def current_engine_coolant_temperature(self):
68
68
"""
69
69
self .send (commands .CURRENT_ENGINE_COOLANT_TEMP_COMMAND )
70
70
response = self .receive ()
71
- response_data = response .split (' ' )[- 1 ]
71
+ response_data = response .strip (). split (' ' )[- 1 ]
72
72
#The data returned in the OBD response is in hexadecimal with a zero offset to account for negative temperatures
73
73
#To return the current temperature in degrees Celsius, we must first convert to decimal and then subtract 40
74
74
#to account for the zero offset.
@@ -81,7 +81,7 @@ def current_engine_oil_temperature(self):
81
81
"""
82
82
self .send (commands .CURRENT_ENGINE_OIL_TEMP_COMMAND )
83
83
response = self .receive ()
84
- response_data = response .split (' ' )[- 1 ]
84
+ response_data = response .strip (). split (' ' )[- 1 ]
85
85
#The data returned in the OBD response is in hexadecimal with a zero offset to account for negative temperatures
86
86
#To return the current temperature in degrees Celsius, we must first convert to decimal and then subtract 40
87
87
#to account for the zero offset.
@@ -94,9 +94,9 @@ def current_engine_rpm(self):
94
94
"""
95
95
self .send (commands .CURRENT_ENGINE_RPM )
96
96
response = self .receive ()
97
- response_data = response .split (' ' )
98
- if len (response_data ) == 4 :
99
- rpm = (int (response . split ( ' ' ) [- 2 ], 16 ) * 256 + int (response . split ( ' ' ) [- 1 ], 16 )) / 4
97
+ response_data = response .strip (). split (' ' )
98
+ if len (response_data ) >= 2 :
99
+ rpm = (int (response_data [- 2 ], 16 ) * 256 + int (response_data [- 1 ], 16 )) / 4
100
100
return rpm
101
101
else :
102
102
return None
@@ -116,7 +116,7 @@ def fuel_type(self):
116
116
"""
117
117
self .send (commands .FUEL_TYPE_COMMAND )
118
118
response = self .receive ()
119
- response_data = response .split (' ' )[- 1 ]
119
+ response_data = response .strip (). split (' ' )[- 1 ]
120
120
return FUEL_TYPE_DESCRIPTION .get (int (response_data , 16 ))
121
121
122
122
def echo_off (self ):
@@ -143,6 +143,7 @@ def initialize(self):
143
143
:return:
144
144
"""
145
145
self .reset ()
146
+ self .echo_off ()
146
147
self .send (elm327 .SELECT_PROTOCOL_COMMAND )
147
148
self .receive ()
148
149
@@ -152,6 +153,8 @@ def receive(self):
152
153
:return: the data returned by the OBD-II Scanner
153
154
"""
154
155
if self .connected :
156
+ #Wait a second for data to become available
157
+ time .sleep (1 )
155
158
retry_number = 0
156
159
value = ""
157
160
while True :
@@ -183,7 +186,6 @@ def reset(self):
183
186
"""
184
187
if self .connected :
185
188
self .send (elm327 .RESET_COMMAND )
186
- time .sleep (1 )
187
189
self .elm_version = self .receive ()
188
190
189
191
def send (self , data ):
0 commit comments