@@ -105,21 +105,25 @@ class ELM327:
105105 def __init__ (self , portname , baudrate , protocol ):
106106 """Initializes port by resetting device and gettings supported PIDs. """
107107
108+ logger .info ("Initializing ELM327: PORT=%s BAUD=%s PROTOCOL=%s" %
109+ (
110+ portname ,
111+ "auto" if baudrate is None else baudrate ,
112+ "auto" if protocol is None else protocol ,
113+ ))
114+
108115 self .__status = OBDStatus .NOT_CONNECTED
109116 self .__port = None
110117 self .__protocol = UnknownProtocol ([])
111118
112119
113120 # ------------- open port -------------
114121 try :
115- logger .info ("Opening serial port '%s'" % portname )
116122 self .__port = serial .Serial (portname , \
117123 parity = serial .PARITY_NONE , \
118124 stopbits = 1 , \
119125 bytesize = 8 ,
120126 timeout = 10 ) # seconds
121- logger .info ("Port opened" )
122-
123127 except serial .SerialException as e :
124128 self .__error (e )
125129 return
@@ -164,7 +168,12 @@ def __init__(self, portname, baudrate, protocol):
164168 # try to communicate with the car, and load the correct protocol parser
165169 if self .set_protocol (protocol ):
166170 self .__status = OBDStatus .CAR_CONNECTED
167- logger .info ("Connection successful" )
171+ logger .info ("Connected Successfully: PORT=%s BAUD=%s PROTOCOL=%s" %
172+ (
173+ portname ,
174+ self .__protocol .ELM_ID ,
175+ self .__port .baudrate ,
176+ ))
168177 else :
169178 logger .error ("Connected to the adapter, but failed to connect to the vehicle" )
170179
@@ -182,9 +191,6 @@ def set_protocol(self, protocol):
182191
183192
184193 def manual_protocol (self , protocol ):
185-
186- logger .debug ("Setting fixed protocol: %s" % protocol )
187-
188194 r = self .__send (b"ATTP" + protocol .encode ())
189195 r0100 = self .__send (b"0100" )
190196
@@ -206,8 +212,6 @@ def auto_protocol(self):
206212 and this function returns True
207213 """
208214
209- logger .debug ("Choosing protocol automatically" )
210-
211215 # -------------- try the ELM's auto protocol mode --------------
212216 r = self .__send (b"ATSP0" )
213217
@@ -234,7 +238,7 @@ def auto_protocol(self):
234238 # an unknown protocol
235239 # this is likely because not all adapter/car combinations work
236240 # in "auto" mode. Some respond to ATDPN responded with "0"
237- logger .info ("ELM responded with unknown protocol. Trying them one-by-one" )
241+ logger .debug ("ELM responded with unknown protocol. Trying them one-by-one" )
238242
239243 for p in self ._TRY_PROTOCOL_ORDER :
240244 r = self .__send (b"ATTP" + p .encode ())
@@ -258,7 +262,6 @@ def set_baudrate(self, baud):
258262 else :
259263 return self .auto_baudrate ()
260264 else :
261- logger .debug ("Setting fixed baudrate: %d" % baud )
262265 self .__port .baudrate = baud
263266 return True
264267
@@ -269,8 +272,6 @@ def auto_baudrate(self):
269272 Returns boolean for success.
270273 """
271274
272- logger .debug ("Choosing baudrate automatically" )
273-
274275 # before we change the timout, save the "normal" value
275276 timeout = self .__port .timeout
276277 self .__port .timeout = 0.1 # we're only talking with the ELM, so things should go quickly
@@ -399,7 +400,7 @@ def __send(self, cmd, delay=None):
399400 self .__write (cmd )
400401
401402 if delay is not None :
402- logger .info ("wait: %d seconds" % delay )
403+ logger .debug ("wait: %d seconds" % delay )
403404 time .sleep (delay )
404405
405406 return self .__read ()
0 commit comments