def read(self, numberOfBytes):
    'Read from a port on dummy_serial.\n\n        The response is dependent on what was written last to the port on dummy_serial,\n        and what is defined in the :data:`RESPONSES` dictionary.\n\n        Args:\n            numberOfBytes (int): For compability with the real function.\n\n        Returns a **string** for Python2 and **bytes** for Python3.\n\n        If the response is shorter than numberOfBytes, it will sleep for timeout.\n        If the response is longer than numberOfBytes, it will return only numberOfBytes bytes.\n\n        '
    if VERBOSE:
        _print_out('\nDummy_serial: Reading from port (max length {!r} bytes)'.format(numberOfBytes))
    if (numberOfBytes < 0):
        raise IOError('Dummy_serial: The numberOfBytes to read must not be negative. Given: {!r}'.format(numberOfBytes))
    if (not self._isOpen):
        raise IOError('Dummy_serial: Trying to read, but the port is not open.')
    if (self._waiting_data == DEFAULT_RESPONSE):
        returnstring = self._waiting_data
    elif (numberOfBytes == len(self._waiting_data)):
        returnstring = self._waiting_data
        self._waiting_data = NO_DATA_PRESENT
    elif (numberOfBytes < len(self._waiting_data)):
        if VERBOSE:
            _print_out(('Dummy_serial: The numberOfBytes to read is smaller than the available data. ' + 'Some bytes will be kept for later. Available data: {!r} (length = {}), numberOfBytes: {}'.format(self._waiting_data, len(self._waiting_data), numberOfBytes)))
        returnstring = self._waiting_data[:numberOfBytes]
        self._waiting_data = self._waiting_data[numberOfBytes:]
    else:
        if VERBOSE:
            _print_out(('Dummy_serial: The numberOfBytes to read is larger than the available data. ' + 'Will sleep until timeout. Available  data: {!r} (length = {}), numberOfBytes: {}'.format(self._waiting_data, len(self._waiting_data), numberOfBytes)))
        time.sleep(self.timeout)
        returnstring = self._waiting_data
        self._waiting_data = NO_DATA_PRESENT
    if VERBOSE:
        _print_out('Dummy_serial read return data: {!r} (has length {})\n'.format(returnstring, len(returnstring)))
    if (sys.version_info[0] > 2):
        return bytes(returnstring, encoding='latin1')
    else:
        return returnstring
Read from a port on dummy_serial.

The response is dependent on what was written last to the port on dummy_serial,
and what is defined in the :data:`RESPONSES` dictionary.

Args:
    numberOfBytes (int): For compability with the real function.

Returns a **string** for Python2 and **bytes** for Python3.

If the response is shorter than numberOfBytes, it will sleep for timeout.
If the response is longer than numberOfBytes, it will return only numberOfBytes bytes.
def read(self, numberOfBytes):
    'Read from a port on dummy_serial.\n\n        The response is dependent on what was written last to the port on dummy_serial,\n        and what is defined in the :data:`RESPONSES` dictionary.\n\n        Args:\n            numberOfBytes (int): For compability with the real function.\n\n        Returns a **string** for Python2 and **bytes** for Python3.\n\n        If the response is shorter than numberOfBytes, it will sleep for timeout.\n        If the response is longer than numberOfBytes, it will return only numberOfBytes bytes.\n\n        '
    if VERBOSE:
        _print_out('\nDummy_serial: Reading from port (max length {!r} bytes)'.format(numberOfBytes))
    if (numberOfBytes < 0):
        raise IOError('Dummy_serial: The numberOfBytes to read must not be negative. Given: {!r}'.format(numberOfBytes))
    if (not self._isOpen):
        raise IOError('Dummy_serial: Trying to read, but the port is not open.')
    if (self._waiting_data == DEFAULT_RESPONSE):
        returnstring = self._waiting_data
    elif (numberOfBytes == len(self._waiting_data)):
        returnstring = self._waiting_data
        self._waiting_data = NO_DATA_PRESENT
    elif (numberOfBytes < len(self._waiting_data)):
        if VERBOSE:
            _print_out(('Dummy_serial: The numberOfBytes to read is smaller than the available data. ' + 'Some bytes will be kept for later. Available data: {!r} (length = {}), numberOfBytes: {}'.format(self._waiting_data, len(self._waiting_data), numberOfBytes)))
        returnstring = self._waiting_data[:numberOfBytes]
        self._waiting_data = self._waiting_data[numberOfBytes:]
    else:
        if VERBOSE:
            _print_out(('Dummy_serial: The numberOfBytes to read is larger than the available data. ' + 'Will sleep until timeout. Available  data: {!r} (length = {}), numberOfBytes: {}'.format(self._waiting_data, len(self._waiting_data), numberOfBytes)))
        time.sleep(self.timeout)
        returnstring = self._waiting_data
        self._waiting_data = NO_DATA_PRESENT
    if VERBOSE:
        _print_out('Dummy_serial read return data: {!r} (has length {})\n'.format(returnstring, len(returnstring)))
    if (sys.version_info[0] > 2):
        return bytes(returnstring, encoding='latin1')
    else:
        return returnstring