def query(self, cmd, size=-1): """ Executes the given query. :param str cmd: String containing the query to execute. :param int size: Number of bytes to be read. Default is read until termination character is found. :return: The result of the query as returned by the connected instrument. :rtype: `str` """ ack_expected_list = self._ack_expected(cmd) if not isinstance(ack_expected_list, (list, tuple)): ack_expected_list = [ack_expected_list] if ack_expected_list[0] is None: # Case no ACK value = self._file.query(cmd, size) else: # Case with ACKs _ = self._file.query(cmd, size=0) # Send the cmd, don't read for ack_expected in ack_expected_list: # Read and verify ACKs ack = self.read() if ack != ack_expected: raise AcknowledgementError( "Incorrect ACK message received: got {} " "expected {}".format(ack, ack_expected)) value = self.read(size) # Now read in our return data if self.prompt is not None: prompt = self.read(len(self.prompt)) if prompt != self.prompt: raise PromptError("Incorrect prompt message received: got {} " "expected {}".format(prompt, self.prompt)) return value
def sendcmd(self, cmd): """ Sends a command without waiting for a response. :param str cmd: String containing the command to be sent. """ self._file.sendcmd(str(cmd)) ack_expected_list = self._ack_expected(cmd) # pylint: disable=assignment-from-none if not isinstance(ack_expected_list, (list, tuple)): ack_expected_list = [ack_expected_list] for ack_expected in ack_expected_list: if ack_expected is None: break ack = self.read() if ack != ack_expected: raise AcknowledgementError( "Incorrect ACK message received: got {} " "expected {}".format(ack, ack_expected) ) if self.prompt is not None: prompt = self.read(len(self.prompt)) if prompt != self.prompt: raise PromptError( "Incorrect prompt message received: got {} " "expected {}".format(prompt, self.prompt) )