BaseInstrument module

Created on Tue Feb 27 2025

@author: Refactoring Bot

class Instruments_Libraries.BaseInstrument.BaseInstrument(resource_str, visa_library='@py', **kwargs)[source]

Bases: object

Base class for all instrument drivers. Handles VISA connection, communication, logging, and error handling.

Parameters:
  • resource_str (str)

  • visa_library (str)

Close()

Close the connection to the instrument.

Return type:

None

IDN()

Get the instrument identification string (*IDN?).

Return type:

str

OPC()

Wait until operation complete (*OPC?).

Returns:

1 when operation is complete.

Return type:

int

clear()[source]

Clear the instrument status (*CLS).

Return type:

None

close()[source]

Close the connection to the instrument.

Return type:

None

static com_to_asrl(com_port)[source]

Convert a Windows COM port string to a PyVISA ASRL resource string.

Parameters:

com_port (str) – Windows COM port (e.g., “COM3”).

Returns:

VISA ASRL string (e.g., “ASRL3::INSTR”).

Return type:

str

get_idn()[source]

Get the instrument identification string (*IDN?).

Return type:

str

get_opc()[source]

Wait until operation complete (*OPC?).

Returns:

1 when operation is complete.

Return type:

int

idn()

Get the instrument identification string (*IDN?).

Return type:

str

opc()

Wait until operation complete (*OPC?).

Returns:

1 when operation is complete.

Return type:

int

query(command)[source]

Send a query and return the response string. The instrument’s response is stripped of whitespace.

Parameters:

command (str) – SCPI query string.

Return type:

str

query_ascii_values(command, **kwargs)[source]

Query for a list of ASCII values (e.g., trace data).

Parameters:
  • command (str) – SCPI query command.

  • **kwargs (dict) – Additional arguments passed to query_ascii_values.

Return type:

list[Any]

query_float(command)[source]

Convenience method to query and parse a single float value.

Parameters:

command (str) – SCPI query string.

Return type:

float

query_int(command)[source]

Convenience method to query and parse a single integer value.

Parameters:

command (str) – SCPI query string.

Return type:

int

query_str_list(command)[source]

Query the instrument and return a list of strings. Automatically removes SCPI quotes (’ or “) and strips whitespace.

Parameters:

command (str)

Return type:

list[str]

read()[source]

Read raw response string from the instrument.

Return type:

str

reset()[source]

Reset the instrument (*RST).

Return type:

None

wait()[source]

Wait for operation to complete (*WAI).

Return type:

None

write(command)[source]

Send a command to the instrument.

Parameters:

command (str) – SCPI command string.

Return type:

None