Commits

Chris Moffitt committed de7f8ce

Fix to make work with USB in ubuntu and change baud rate to 38400

Comments (0)

Files changed (2)

      def __init__(self,portnum,_notify_window,SERTIMEOUT,RECONNATTEMPTS):
          """Initializes port by resetting device and gettings supported PIDs. """
          # These should really be set by the user.
-         baud     = 9600
+         baud     = 38400
          databits = 8
          par      = serial.PARITY_NONE  # parity
          sb       = 1                   # stop bits
                       buffer = buffer + c
              wx.PostEvent(self._notify_window, DebugEvent([3,"Get result:" + buffer]))
              return buffer
+         else:
+            wx.PostEvent(self._notify_window, DebugEvent([3,"NO self.port!" + buffer]))
          return None
 
      # get sensor value from command
 import os #os.environ
 
 import threading
-
+import sys
 import serial
+import platform
 import time
 import ConfigParser #safe application configuration
 import webbrowser #open browser from python
         for i in range(256):
           try:
             s = serial.Serial("/dev/ttyUSB"+str(i))
-            available.append( (i, s.portstr))
+            #available.append( (i, s.portstr))
+            available.append(s.portstr)
             s.close()   # explicit close 'cause of delayed GC in java
           except serial.SerialException:
             pass
             s.close()   # explicit close 'cause of delayed GC in java
           except serial.SerialException:
             pass
+            
+        # ELM-USB shows up as /dev/tty.usbmodemXXXX, where XXXX is a changing hex string
+        # on connection; so we have to search through all 64K options
+        if len(platform.mac_ver()[0])!=0:  #search only on MAC
+          for i in range (65535):
+            extension = hex(i).replace("0x","", 1)
+            try:
+              s = serial.Serial("/dev/tty.usbmodem"+extension)
+              available.append(s.portstr)
+              s.close()
+            except serial.SerialException:
+              pass 
+        
         return available
 
     def Configure(self,e = None):