Query the number of bytes waiting to be written to the serial port.

        Returns:
            int: number of bytes waiting to be written.

        Raises:
            SerialError: if an I/O or OS error occurs.
437688
def output_waiting(self):
        
        # Get input waiting
        buf = array.array('I', [0])
        try:
            fcntl.ioctl(self._fd, termios.TIOCOUTQ, buf, True)
        except OSError as e:
            raise SerialError(e.errno, "Querying output waiting: " + e.strerror)

        return buf[0]
940275
def get_data_length(self):
        # type: () -> int
        '''
        
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
        if self.inode is not None:
            return self.inode.get_data_length()
        return self.data_length
785090
def display(self):
        
        total = 0
        count = 0
        for i, result in enumerate(self._results):
            if total == 0:
                self.pre_write()
            self.write(result)
            count += 1
            total += 1
            if (
                count >= self.pagesize
                and self.pagesize > 0
                and i < len(self._results) - 1
            ):
                self.wait()
                count = 0
        if total == 0:
            self._ostream.write("No results\n")
        else:
            self.post_write()
655238
def _write_to_device_and_return(cmd, ack, device_connection):
    ''''''
    log.debug('Write -> {}'.format(cmd.encode()))
    device_connection.write(cmd.encode())
    response = device_connection.read_until(ack.encode())
    log.debug('Read <- {}'.format(response))
    if ack.encode() not in response:
        raise SerialNoResponse(
            'No response from serial port after {} second(s)'.format(
                device_connection.timeout))
    clean_response = _parse_serial_response(response, ack.encode())
    if clean_response:
        return clean_response.decode()
    return ''
347283
def determineLength(length):
        
        integer = ord(length)

        if integer < 128:
            return 0
        elif integer < 192:
            return 1
        elif integer < 224:
            return 2
        elif integer < 240:
            return 3
        else:
            raise ConnectionError('Unknown controll byte {}'.format(length))
688909
def respond(self, response_adu):
        
        log.debug('--> {0}'.format(hexlify(response_adu)))
        self.serial_port.write(response_adu)
501455
def read_bytes(self, count):
        
        result = self.input.read(count)
        found = len(result)
        self.lineno += result.count(b'\n')
        if found != count:
            self.abort(errors.MissingBytes, count, found)
        return result
401735
def get_status(self):
        

        # "The first command sent must be a 'T' command" from T95 manual
        self.device.serial_command_mode = True

        Tarray = [0x80] * 10

        # Status byte (SB1)
        Tarray[0] = {
            'stopped': 0x01,
            'heat': 0x10,
            'cool': 0x20,
            'hold': 0x30,
        }.get(self.device._csm.state, 0x01)

        if Tarray[0] == 0x30 and self.device.hold_commanded:
            Tarray[0] = 0x50

        # Error status byte (EB1)
        if self.device.pump_overspeed:
            Tarray[1] |= 0x01
        # TODO: Add support for other error conditions?

        # Pump status byte (PB1)
        Tarray[2] = 0x80 + self.device.pump_speed

        # Temperature
        Tarray[6:10] = [ord(x) for x in "%04x" % (int(self.device.temperature * 10) & 0xFFFF)]

        return ''.join(chr(c) for c in Tarray)
972476
def r12_serial_port(port):
    '''  '''
    return serial.Serial(port, baudrate=BAUD_RATE, parity=PARITY,
                         stopbits=STOP_BITS, bytesize=BYTE_SIZE)
532029
def length(self):
        

        if not self.__length:
            self.__length = self.__get_length()

        return self.__length
946480
def wait_for_read_result(self):
        
        while not self.callback_data:
            self.board.sleep(.001)
        rval = self.callback_data
        self.callback_data = []
        return rval
1210189
def data(self):
        
        if self._data_type == int:
            if self._pb.HasField("int64_data"):
                return self._pb.int64_data
            if self._pb.HasField("int32_data"):
                return self._pb.int32_data
            if self._pb.HasField("uint64_data"):
                return self._pb.uint64_data
            if self._pb.HasField("uint32_data"):
                return self._pb.uint32_data
        elif self._data_type == float:
            if self._pb.HasField("float32_data"):
                return self._pb.float32_data
            if self._pb.HasField("float64_data"):
                return self._pb.float64_data
        elif self._data_type == str:
            return self._pb.string_data
        elif self._data_type == bool:
            return self._pb.bool_data
        elif self._data_type == bytes:
            return self._pb.bytes_data
        return None
1095831
def get_serial():
    
    port, serial_number = find_microbit()
    if port is None:
        raise IOError('Could not find micro:bit.')
    return Serial(port, SERIAL_BAUD_RATE, timeout=1, parity='N')
366724
def read(self):
        
        while len(self.rcv_data) == 0:
            sleep(0)

        if self.rcv_data[0] is None:
            raise DAPAccessIntf.DeviceError("Device %s read thread exited" %
                                            self.serial_number)
        return self.rcv_data.pop(0)
785467
def write(self, pkt):
		
		self.setRTS(self.DD_WRITE)
		self.flushInput()
		# prep data array for transmition
		pkt = bytearray(pkt)
		pkt = bytes(pkt)

		num = self.serial.write(pkt)
		# self.serial.flush()
		# print('wrote {} of len(pkt) = {}'.format(num, len(pkt)))
		return num
1014867
def write(self, data):
        
        _complain_ifclosed(self.closed)
        if self.__encoding:
            self.f.write(data.encode(self.__encoding, self.__errors))
            return len(data)
        else:
            return self.f.write(data)
782634
def pending_batch_info(self):
        
        c_length = ctypes.c_int(0)
        c_limit = ctypes.c_int(0)
        self._call(
            'pending_batch_info',
            ctypes.byref(c_length),
            ctypes.byref(c_limit))

        return (c_length.value, c_limit.value)