'Output the given byte string over the serial port.'

def write(self, data):

    if (not self.is_open):
        raise portNotOpenError
    d = to_bytes(data)
    tx_len = len(d)
    timeout = Timeout(self._write_timeout)
    while (tx_len > 0):
        try:
            n = os.write(self.fd, d)
            if timeout.is_non_blocking:
                return n
            elif (not timeout.is_infinite):
                if timeout.expired():
                    raise writeTimeoutError
                (abort, ready, _) = select.select([self.pipe_abort_write_r], [self.fd], [], timeout.time_left())
                if abort:
                    os.read(self.pipe_abort_write_r, 1000)
                    break
                if (not ready):
                    raise writeTimeoutError
            else:
                assert (timeout.time_left() is None)
                (abort, ready, _) = select.select([self.pipe_abort_write_r], [self.fd], [], None)
                if abort:
                    os.read(self.pipe_abort_write_r, 1)
                    break
                if (not ready):
                    raise SerialException('write    failed    (select)')
            d = d[n:]
            tx_len -= n
        except SerialException:
            raise
        except OSError as v:
            if (v.errno != errno.EAGAIN):
                raise SerialException('write    failed:    {}'.format(v))
            if timeout.expired():
                raise writeTimeoutError
    return len(data)
