'Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read.'

def read(self, size=1):

    if (not self.is_open):
        raise portNotOpenError
    read = bytearray()
    timeout = Timeout(self._timeout)
    while (len(read) < size):
        try:
            (ready, _, _) = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
            if (self.pipe_abort_read_r in ready):
                os.read(self.pipe_abort_read_r, 1000)
                break
            if (not ready):
                break
            buf = os.read(self.fd, (size - len(read)))
            if (not buf):
                raise SerialException('device    reports    readiness    to    read    but    returned    no    data    (device    disconnected    or    multiple    access    on    port?)')
            read.extend(buf)
        except OSError as e:
            if ((e.errno != errno.EAGAIN) and (e.errno != errno.EINTR)):
                raise SerialException('read    failed:    {}'.format(e))
        except select.error as e:
            if (e[0] != errno.EAGAIN):
                raise SerialException('read    failed:    {}'.format(e))
        if timeout.expired():
            break
    return bytes(read)
