Skip to content

InstrumentManager

Jahoon Koo edited this page May 8, 2023 · 28 revisions

This page contains the documentation on the InstrumentManager and how to subclass it for custom drivers.

The InstrumentManager class contains the basic functionality to communicate with instruments in an object oriented manner. The class communicates with instruments using the VISA interface (For non-VISA interfaced instruments see Subclassing).

Relavent Methods and Properties

Constructor

InstrumentManager(name: str, connection: str, driver: dict[dict], logger: Logging.logger)

  • name: Name that the InstrumentManager is referred to in the InstrumentServer
  • connection: VISA style connection string (for Non-VISA interfaced instruments, can be None)
  • driver: Driver dictionary containing all settings and quantity information
  • logger: Logging.logger

Properties

quantities -> dict[str, QuantitityManager]
     Returns a dictionary with quantity name as the key and corresponding QuantityManager as the value.

Name-> str
     Returns instrument name.

Model_name -> str
     Returns instrument_interface manufacturer.

Address -> str
     Returns instrument_interface address.

Delay -> float
     Returns instrument delay in seconds.

Timeout -> float
     Returns instrument timeout in seconds.

Property Setters

timeout setter(value: float)
     Sets instrument timeout to value in seconds.

delay setter(value: float)
     Sets instrument delay to value in seconds.

Public Methods

write(msg: str) -> None
     Sends a string message to the instrument.

read() -> str
     Returns instrument output.

ask(msg: str) -> None
     Sends a string message to the instrument and returns instrument output.

close() -> str
     Sends final command to instrument if defined in driver and closes instrument and related resources.

get_value(quantity: str) -> obj
     Queries and returns current value of Quantity manager with name quantity.

set_value(quantity: str, value: obj)
     Sets the value of the Quantity manager with name quantity to value.

read_values(format: obj) -> str
     Reads a list of floating point values from the instrument.

ask_for_values(msg: str, format: obj) -> str
     Sends a string message to the instrument and reads a list of floating point values from the instrument.

clear() -> None
     Clears the instrument.

trigger() -> None
     Sends a trigger signal to the instrument to initiate a measurement or an acquisition.

read_raw() -> None
     Reads raw binary data from the instrument.

get_visible_quantities() -> list[QuantityManager]
     Returns a list of all visible quantities.

get_latest_value(quantity: str) -> latest_value: obj
     Returns the latest value for given quantity.

set_default_value(quantity: str) -> None
     Sets default value for given quantity.

update_visibility(quantity_changed: obj, new_value: obj) -> None
     Updates visibility of all quantities to given value whose state_quant is the quantity_changed.

link_quantity(quantity: str, link_to: QuantityManager, link_set: bool, link_get: bool)
     Links the quantity to another QuantityManager for any set or get if the corresponding link_set or link_get is True

Private Methods

_initialize_instrument(connection: str) -> None
     Initializes PyVISA resource if a PyVISA resource string was given at construction.

_check_model(None) -> None
     Queries instrument for model ID and compares to models listed in driver.

_initialize_visa_settings(None) -> None
     Initializes instrument timeout, termination character, end of message, and query error using data in self._driver['VISA'].

_set_visa_settings_in_visa_resource(None) -> None
     Sets Instrument settings for VISA instruments.

_initialize_serial_settings(None) -> None
     Initializes Instrument baud rate, data bits, and stop bits using data in self._driver['VISA'].

_set_serial_settings_in_visa_resource(None) -> None
     Sets Instrument settings for serial instruments.

_initialize_quantities(None) -> None
     Initializes Instrument string true and false using data in self._driver['VISA'].

_startup(None) -> None
     Sends relevant start up commands to instrument.

_is_serial_instrument(None) -> bool
     Checks if the instrument uses serial to communicate.

Subclassing

The class, as-is, can communicate with (most) instruments that support the VISA interface. The InstrumentManager uses PyVisa to communicate with VISA instruments. It uses PyVisa's ResourceManager to instantiate a PyVisa Instrument to communicate with an instrument. For most instances, users will subclass the InstrumentManager because the the instrument does not support the VISA protocol. To subclass the InstrumentManager, define the path to the custom InstrumentManager in the driver_path field under [General settings] of the driver. NOTE: the module name must be the same as the class name.

The most basic subclassing for non-VISA instruments will override _initialize_instrument(connection). read(), and write(msg) will need to be overwritten if the instrument object does not use the same formatting as PyVisa's Instrument.write(msg) and Instrument.read().

# The file name is CustomInstrumentManager.py
class CustomInstrumentManager(InstrumentManager):
    # Constructor will call at run-time
    def _initialize_instrument(self, connection):
        self._instrument = self._create_connection(connection)

    # custom method implemented by user to create connection using any protocol
    def _create_connection(self, connection):
        ...
        return instrument_connection

    def write(self, msg):
        self._instrument.write_method(msg)

    def read(self):
        return self._instrument.read_method()

The read and write methods are used throughout the InstrumentManager and are used in methods such as ask(msg) and will be automatically sent to the QuantityManager without need to overwrite _initialize_quantities(). If functionality for setting/getting any quantity values needs to be changed, please see Subclassing for QuantityManagers. While it is possible to change the functionality with just the InstrumentMager, doing so would require complex functionality in the read and write methods; therefore, it is easier and better to create a custom QuantityManager.

Table of Contents

Clone this wiki locally