@@ -59,16 +59,16 @@ class ELM327:
5959 def __init__ (self , portname ):
6060 """Initializes port by resetting device and gettings supported PIDs. """
6161
62- self .connected = False
63- self .port = None
64- self .protocol = None
62+ self .__connected = False
63+ self .__port = None
64+ self .__protocol = None
6565
6666 # ------------- open port -------------
6767
6868 debug ("Opening serial port '%s'" % portname )
6969
7070 try :
71- self .port = serial .Serial (portname , \
71+ self .__port = serial .Serial (portname , \
7272 baudrate = 38400 , \
7373 parity = serial .PARITY_NONE , \
7474 stopbits = 1 , \
@@ -132,12 +132,12 @@ def __init__(self, portname):
132132 self .__error ("ELM responded with unknown protocol" )
133133 return
134134
135- self .protocol = _SUPPORTED_PROTOCOLS [r ]()
135+ self .__protocol = _SUPPORTED_PROTOCOLS [r ]()
136136
137137
138138 # ------------------------------- done -------------------------------
139139 debug ("Connection successful" )
140- self .connected = True
140+ self .__connected = True
141141
142142
143143 def __error (self , msg = None ):
@@ -148,42 +148,42 @@ def __error(self, msg=None):
148148 if msg is not None :
149149 debug (' ' + str (msg ), True )
150150
151- if self .port is not None :
152- self .port .close ()
151+ if self .__port is not None :
152+ self .__port .close ()
153153
154- self .connected = False
154+ self .__connected = False
155155
156156
157157 def get_port_name (self ):
158- return self .port .portstr if (self .port is not None ) else "No Port"
158+ return self .__port .portstr if (self .__port is not None ) else "No Port"
159159
160160
161161 def is_connected (self ):
162- return self .connected
162+ return self .__connected
163163
164164
165165 def close (self ):
166166 """ Resets device and closes all associated filehandles"""
167167
168- if (self .port != None ) and self .connected :
168+ if (self .__port != None ) and self .__connected :
169169 self .__write ("ATZ" )
170- self .port .close ()
170+ self .__port .close ()
171171
172- self .connected = False
173- self .port = None
174- self .protocol = None
172+ self .__connected = False
173+ self .__port = None
174+ self .__protocol = None
175175
176176
177177 def send_and_parse (self , cmd , delay = None ):
178178
179179 r = self .send (cmd , delay )
180180
181- messages = self .protocol (r ) # parses string into list of messages
181+ messages = self .__protocol (r ) # parses string into list of messages
182182
183183 # if more than one ECUs have responded, pick the primary
184184 # TODO: add support for more ECU types
185185 if len (messages ) > 1 :
186- messages = filter (lambda m : m .tx_id == self .protocol .PRIMARY_ECU , messages )
186+ messages = filter (lambda m : m .tx_id == self .__protocol .PRIMARY_ECU , messages )
187187
188188 return messages [0 ]
189189
@@ -202,11 +202,12 @@ def send(self, cmd, delay=None):
202202
203203 # sends the hex string to the port
204204 def __write (self , cmd ):
205- if self .port :
205+
206+ if self .__port :
206207 cmd += "\r \n " # terminate
207- self .port .flushOutput ()
208- self .port .flushInput ()
209- self .port .write (cmd )
208+ self .__port .flushOutput ()
209+ self .__port .flushInput ()
210+ self .__port .write (cmd )
210211 debug ("write: " + repr (cmd ))
211212 else :
212213 debug ("cannot perform write() when unconnected" , True )
@@ -219,9 +220,9 @@ def __read(self):
219220 attempts = 2
220221 result = ""
221222
222- if self .port :
223+ if self .__port :
223224 while True :
224- c = self .port .read (1 )
225+ c = self .__port .read (1 )
225226
226227 # if nothing was recieved
227228 if not c :
0 commit comments