def query(request)
      tried = 0
      response = ""
      begin
        ::Timeout.timeout(@read_retry_timeout, ModBusTimeout) do
          send_pdu(request)
          response = read_pdu
        end
      rescue ModBusTimeout => err
        log "Timeout of read operation: (#{@read_retries - tried})"
        tried += 1
        retry unless tried >= @read_retries
        raise ModBusTimeout.new, "Timed out during read attempt"
      end

      return nil if response.size == 0

      read_func = response.getbyte(0)
      if read_func >= 0x80
        exc_id = response.getbyte(1)
        raise Exceptions[exc_id] unless Exceptions[exc_id].nil?

        raise ModBusException.new, "Unknown error"
      end

      check_response_mismatch(request, response) if raise_exception_on_mismatch
      response[2..-1]
    end
def query(request)
      tried = 0
      response = ""
      begin
        ::Timeout.timeout(@read_retry_timeout, ModBusTimeout) do
          send_pdu(request)
          response = read_pdu
        end
      rescue ModBusTimeout => err
        log "Timeout of read operation: (#{@read_retries - tried})"
        tried += 1
        retry unless tried >= @read_retries
        raise ModBusTimeout.new, "Timed out during read attempt"
      end

      return nil if response.size == 0

      read_func = response.getbyte(0)
      if read_func >= 0x80
        exc_id = response.getbyte(1)
        raise Exceptions[exc_id] unless Exceptions[exc_id].nil?

        raise ModBusException.new, "Unknown error"
      end

      check_response_mismatch(request, response) if raise_exception_on_mismatch
      response[2..-1]
    end
Request pdu to slave device

 @param [String] pdu request to slave
 @return [String] received data

 @raise [ResponseMismatch] the received echo response differs from the request
 @raise [ModBusTimeout] timed out during read attempt
 @raise [ModBusException] unknown error
 @raise [IllegalFunction] function code received in the query is not an allowable action for the server
 @raise [IllegalDataAddress] data address received in the query is not an allowable address for the server
 @raise [IllegalDataValue] value contained in the query data field is not an allowable value for server
 @raise [SlaveDeviceFailure] unrecoverable error occurred while the server was attempting to perform the requested action
 @raise [Acknowledge] server has accepted the request and is processing it, but a long duration of time will be required to do so
 @raise [SlaveDeviceBus] server is engaged in processing a long duration program command
 @raise [MemoryParityError] extended file area failed to pass a consistency check