Example #1
0
     def get_result(self):
         """Internal use only: not a public interface"""

         repeat_count = 0
         if self.port is not None:
             buffer = ""
             while True:
                 c = self.port.read(1)
                 if len(c) == 0:
                    if(repeat_count == 5):
                        break
                    print "Got nothing\n"
                    repeat_count = repeat_count + 1
                    continue
                    
                 if c == '\r':
                    continue
                    
                 if c == ">":
                    break;

                 #if something is in the buffer, add it
                 if buffer != "" or c != ">":
                    buffer = buffer + c
                    
             if(buffer == ""):
                return None
             return buffer
         else:
            debug_display(self.notify_window, 3, "NO self.port!")
         return None
Example #2
0
    def get_result(self):
        """Internal use only: not a public interface"""

        repeat_count = 0
        if self.port is not None:
            buffer = ""
            while True:
                c = self.port.read(1)
                if len(c) == 0:
                    if (repeat_count == 5):
                        break
                    print "Got nothing\n"
                    repeat_count = repeat_count + 1
                    continue

                if c == '\r':
                    continue

                if c == ">":
                    break

                #if something is in the buffer, add it
                if buffer != "" or c != ">":
                    buffer = buffer + c

            if (buffer == ""):
                return None
            return buffer
        else:
            debug_display(self.notify_window, 3, "NO self.port!")
        return None
Example #3
0
     def __init__(self, portnum, notify_window, SERTIMEOUT):
         """Initializes port by resetting the device and gettings supported PIDs. """

         baud = 38400
         databits = 8
         parity = serial.PARITY_NONE
         stop_bits = 1
         to = SERTIMEOUT
         self.elm_version = "Unknown"

         #state SERIAL is 1 connected, 0 disconnected (connection failed)
         self.state = 1
         self.port = None
         
         self.notify_window = notify_window
         debug_display(self.notify_window, 1, "Opening interface (serial port)")

         try:
             self.port = serial.Serial(portnum, baud, parity=parity, stopbits=stop_bits, bytesize=databits, timeout=to)
             
         except serial.SerialException as e:
             print e
             self.state = 0
             return None
             
         debug_display(self.notify_window, 1, "Interface " + self.port.portstr + "successfully opened")
         debug_display(self.notify_window, 1, "Connecting to ECU...")
         
         try:
            self.send_command("atz")   # initialize
            time.sleep(1)
         except serial.SerialException:
            self.state = 0
            return None
            
         self.elm_version = self.get_result()
         if(self.elm_version is None):
            self.state = 0
            return None
         
         debug_display(self.notify_window, 2, "atz response:" + self.elm_version)
         self.send_command("ate0")  # echo off
         debug_display(self.notify_window, 2, "ate0 response:" + self.get_result())
         self.send_command("0100")
         ready = self.get_result()
         
         if(ready is None):
            self.state = 0
            return None
            
         debug_display(self.notify_window, 2, "0100 response:" + ready)
         return None
Example #4
0
    def __init__(self, portnum, notify_window, SERTIMEOUT):
        """Initializes port by resetting the device and gettings supported PIDs. """

        baud = 38400
        databits = 8
        parity = serial.PARITY_NONE
        stop_bits = 1
        to = SERTIMEOUT
        self.elm_version = "Unknown"

        #state SERIAL is 1 connected, 0 disconnected (connection failed)
        self.state = 1
        self.port = None

        self.notify_window = notify_window
        debug_display(self.notify_window, 1, "Opening interface (serial port)")

        try:
            self.port = serial.Serial(portnum,
                                      baud,
                                      parity=parity,
                                      stopbits=stop_bits,
                                      bytesize=databits,
                                      timeout=to)

        except serial.SerialException as e:
            print e
            self.state = 0
            return None

        debug_display(self.notify_window, 1,
                      "Interface " + self.port.portstr + "successfully opened")
        debug_display(self.notify_window, 1, "Connecting to ECU...")

        try:
            self.send_command("atz")  # initialize
            time.sleep(1)
        except serial.SerialException:
            self.state = 0
            return None

        self.elm_version = self.get_result()
        if (self.elm_version is None):
            self.state = 0
            return None

        debug_display(self.notify_window, 2,
                      "atz response:" + self.elm_version)
        self.send_command("ate0")  # echo off
        debug_display(self.notify_window, 2,
                      "ate0 response:" + self.get_result())
        self.send_command("0100")
        ready = self.get_result()

        if (ready is None):
            self.state = 0
            return None

        debug_display(self.notify_window, 2, "0100 response:" + ready)
        return None