class ReadingThread(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.Serial = Serializer(port) if self.Serial.port.isOpen() == False: try: self.Serial.open() except RuntimeError: self.PortExceptionHandler() def PortReader(self): try: reading = self.Serial.recv() except RuntimeError: self.PortExceptionHandler() return reading def PortExceptionHandler(self, tries = 0): self.Serial.Close() tries =+ 1 portRetry = [ChecaPuertos.serial_ports()] portRetry = portRetry[0] self.Serial = Serializer(portRetry) print'portexception' if self.Serial.port.isOpen() == False: try: self.Serial.open() except RuntimeError: if tries > 3: return else: self.PortExceptionHandler(tries)
def __init__(self, port): threading.Thread.__init__(self) self.Serial = Serializer(port) if self.Serial.port.isOpen() == False: try: self.Serial.open() except RuntimeError: self.PortExceptionHandler()
def PortExceptionHandler(self, tries = 0): self.Serial.Close() tries =+ 1 portRetry = [ChecaPuertos.serial_ports()] portRetry = portRetry[0] self.Serial = Serializer(portRetry) print'portexception' if self.Serial.port.isOpen() == False: try: self.Serial.open() except RuntimeError: if tries > 3: return else: self.PortExceptionHandler(tries)