Skip to content

QuantityManager

Thomas Starnes edited this page May 8, 2023 · 8 revisions

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

The QuantityManager class contains the basic functionality to update and retrieve quantity values within the instrument. The class communicates with instruments using the VISA interface .

Relavent Methods and Properties

Constructor

QuantityManager (quantity_info: dict, write_method: Callable, read_method: Callable, str_true: str , str_false: str, logger: Logging.logger=None)

  • quantity_info: dictionary containing all quantity information and settings as defined in the driver
  • write_method: Method used to write to the instrument. In the default InstrumentManager, this is InstrumentManager.write(msg)
  • read_method: Method used to read from the instrument. In the default InstrumentManager, this is InstrumentManager.read()
  • str_true: The string value that the instrument understands as True as defined in the driver
  • str_false: The string value that the instrument understands as False as defined in the driver
  • logger: Logging.logger

Public Properties

All fields in the quantity section of the driver except for label, combo_def_1,..., combo_def_n, cmd_def_1,..., cmd_def_n, or state_value_1,..., state_value_n. These fields are used but are under different names.

name: name of the quantity as defined by label in the driver.

combo_cmd: a dictionary mapping the combo_str_n to cmd_str_n from the driver.

state_values: list of state_value_1,..., state_value_n from the driver.

latest_value: last known quantity value in the database.

is_visible: boolean value determining visibility in experiment module and manual instrument control. This will only ever be false if state_quant is not currently a value in state_values.

str_true: string value that the instrument recognizes as True as defined in the VISA Settings in the driver.

str_false: string value that the instrument recognizes as True as defined in the VISA Settings in the driver.

linked_quantity_get: QuantityManager that this QuantityManager will call for any get_value if not None

linked_quantity_set: QuantityManager that this QuantityManager will call for any set_value if not None

Private Fields

_write_method: the write method of the InstrumentManager that was passed in at instantiation

_read_method: the read method of the InstrumentManager that was passed in at instantiation

Public Methods

set_value(value: obj)
     Sets the value of the quantity by directly writing to the instrument.

get_value() -> obj
     Returns the value of the quantity by directly querying the instrument. The return object is first converted from the instrument value to a value easily understood by the user. i.e. if the quantity is a boolean and the quantity value read from the instrument is 0, this method will return False.

set_latest_value(value: obj)
     Sets the latest_value of the quantity in the database and does not write to the instrument.

get_latest_value() -> obj
     Gets the latest_value of the quantity in the database and does not read from the instrument.

set_default_value()
     Sets the value of the quantity to its default value as defined in the driver by directly writing to the instrument.

Subclassing

In order to use a custom QuantityManager, you must also create a custom InstrumentManager and override its _initialize_quantities() method.

The following code shows the bare basics of how to use a user-defined MyQuantityManager for a quantity named My Quantity. The example code only updates latest_value rather than writing to the instrument.

# basic requirements for subclassing the InstrumentManager to use custom QuantityManagers
class MyInstrumentManager(InstrumentManager):
    def _initialize_quantities(self):
        str_true = self._driver['visa']['str_true']
        str_false = self._driver['visa']['str_false']

        for name, info in self._driver['quantities'].items():
            if name == 'My Quantity':
                self.quantities[name] = MyQuantityManager(info, self.write, self.read, str_true, str_false, self._logger)
            else:
                self.quantities[name] = QuantityManager(info, self.write, self.read, str_true, str_false, self._logger)


class MyQuantityManager(QuantityManager):
    def set_value(self, value):
        self.set_latest_value(value)

    def get_value(self):
        return self.get_latest_value()

In a similar fashion to subclassing InstrumentManager, users can specify the driver path of a custom module by utilizing the driver_path parameter in a .ini file. This allows the user to define the location of the driver associated with the custom module (e.g. Picoscope 6000). It is highly recommended to store the custom QuantityManager and custom InstrumentManager modules in the same Python file for optimal organization and ease of access.

[General settings]

# The name is shown in all the configuration windows
name: Picoscope 6000 Series


# The version string should be updated whenever changes are made to this config file
version: 1.0

# Name of folder containing the code defining a custom driver. Do not define this item
# or leave it blank for any standard driver based on the built-in VISA interface.
driver_path: Picoscope_6000/Picoscope_6000.py

Table of Contents

Clone this wiki locally