'Reader loop'

def run(self):

    if (not hasattr(self.serial, 'cancel_read')):
        self.serial.timeout = 1
    self.protocol = self.protocol_factory()
    try:
        self.protocol.connection_made(self)
    except Exception as e:
        self.alive = False
        self.protocol.connection_lost(e)
        self._connection_made.set()
        return
    error = None
    self._connection_made.set()
    while (self.alive and self.serial.is_open):
        try:
            data = self.serial.read((self.serial.in_waiting or 1))
        except serial.SerialException as e:
            error = e
            break
        else:
            if data:
                try:
                    self.protocol.data_received(data)
                except Exception as e:
                    error = e
                    break
    self.alive = False
    self.protocol.connection_lost(error)
    self.protocol = None
