File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,33 +11,41 @@ class Async():
1111
1212 def __init__ (self , portstr = None ):
1313 self .connection = obd .OBD (portstr )
14- self .running = True
1514 self .commands = {} # key = OBDCommand, value = Response
16-
15+ self .thread = None
16+ self .start ()
17+
18+ def start (self ):
19+ self .running = True
1720 if self .connection .is_connected ():
1821 self .thread = threading .Thread (target = self .run , args = (self .connection ,))
1922 self .thread .start ()
2023
21- def close (self ):
24+ def stop (self ):
2225 self .running = False
23- self .thread .join ()
24- self .connection .close
26+ if self .thread is not None :
27+ self .thread .join ()
28+ self .thread = None
2529
26- def get (self , c ):
27- if self .commands .has_key (c ):
28- return self .commands [c ]
29- else :
30- return Response ()
30+ def close (self ):
31+ self .stop ()
32+ self .connection .close ()
3133
32- def add (self , * commands ):
34+ def watch (self , * commands ):
3335 for c in commands :
3436 if isinstance (c , OBDCommand ) and self .connection .has_command (c ):
3537 if not self .commands .has_key (c ):
3638 self .commands [c ] = Response () # give it an initial value
3739
38- def remove (self , c ):
40+ def unwatch (self , c ):
3941 self .commands .pop (c , None )
4042
43+ def get (self , c ):
44+ if self .commands .has_key (c ):
45+ return self .commands [c ]
46+ else :
47+ return Response ()
48+
4149 def run (self , connection ):
4250 # loop until the stop signal is recieved
4351 while self .running :
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ def send(self, cmd):
140140 def get (self ):
141141 """Internal use only: not a public interface"""
142142
143- attempts = 2
143+ attempts = 1
144144 result = ""
145145
146146 if self .port is not None :
You can’t perform that action at this time.
0 commit comments