qmi.core.scpi_protocol

Implementation of SCPI protocol primitives.

Classes

ScpiProtocol(transport[, ...])

Implement SCPI protocol primitives.

class qmi.core.scpi_protocol.ScpiProtocol(transport: QMI_Transport, command_terminator: str = '\n', response_terminator: str = '\n', default_timeout: float | None = None)

Implement SCPI protocol primitives.

An ScpiProtocol instance may be instantiated by QMI_Instrument classes that talk SCPI over some transport. After instantiation, the ScpiProtocol primitives should be used to talk to the instrument.

Note that the ScpiProtocol does not take ownership of the transport. The transport’s owner is responsible for closing the transport even when the ScpiProtocol is used.

Example:

self._transport = transport_descriptor.create()
self._scpi = ScpiProtocol(self._transport)

idn = self._scpi.ask("*IDN?")
write(cmd: str) None

Send an SCPI command.

write_raw(cmd: bytes) None

Send an SCPI command already encoded as bytes

ask(cmd: str, timeout: float | None = None, discard: bool = False, decoder: str = 'ascii') str

Send an SCPI command, then read and return the response.

Parameters:
  • cmd – SCPI command string.

  • timeout – Optional response timeout in seconds.

  • discard – Discard contents in read buffer before asking. Default is False.

  • decoder – Optional parameter to set another decoder to use for the query. Some instruments have optional data format settings which can then return data in other than ‘ascii’ coded format.

Returns:

Decoded response message with message terminator removed.

Return type:

decoded_response

read_binary_data(read_terminator_flag: bool = True, timeout: float | None = None) bytes

Read a binary data block formatted as in SCPI definite length arbitrary block response data.

Parameters:
  • read_terminator_flag – True to expect a message terminator after the binary data. This should be True (the default) if the binary data block is the last or only data element in the response message.

  • timeout – Optional timeout in seconds.