Drivers#

class pyscan.drivers.instrument_driver.InstrumentDriver(instrument, debug=False)#

Base driver class which creates class attributes based on a settings dictionary

Parameters:
instrumentstring or pyvisa Resource

visa string or an instantiated instrument

Methods

query(string)

write(string)

read()

find_first_key(dictionary, machine_value)

add_device_property(settings)

get_instrument_property()

set_values_property()

set_range_property()

set_index_values_property()

set_dict_values_property()

get_pyscan_properties()

get_property_docstring(prop_name)

add_device_property(settings)#

Adds a property to the class based on a settings dictionary

Parameters:
settingsdict
dict containing settings for property. Must have:
  • the key “values”, “range”, or “indexed_values”, or “dict_values”

  • “write_string” and/or “query_string” to communication with instrument

  • “return_type” is a function that converts the return string to a python type

Returns:
None
get_instrument_property(obj, settings, debug=False)#

Generator function for a query function of the instrument that sends the query string and formats the return based on settings[‘return_type’]

Parameters obj :

parent object

settingsdict

settings dictionary

debugbool

returns query string instead of querying instrument

Returns:
value formatted to setting’s [‘return_type’]
get_property_docstring(prop_name)#

Gets the doc string for a property from an instance of this class

Parameters:
prop_namestr

The name of the property to get the doc string of

Returns:
str

The two doc string lines for the property

get_pyscan_properties()#

Finds the pyscan style properties of this driver, i.e. those that end with “_settings”

Returns:
list

list of property names for the current driver

query(string)#

Wrapper to pass string to the instrument object

Parameters:
string: str

The message to send to the device

Returns:
str

Answer from the device.

read()#

Wrapper to read string from the instrument object

Returns:
str

Message read from the instrument

set_dict_values_property(obj, input_key, settings)#

Generator function for settings dictionary with ‘dict_values’ item. Check that new_value is a value in settings[‘dict_values’]. If so, sends the associated key to the settings[‘write_string’]; if not, rejects command.

Parameters:
obj

parent class object

input_key

input_key whose associated dictionary value will be set on the instrument

settingsdict

dictionary with [‘dict_values’] item

Returns:
None
set_indexed_values_property(obj, new_value, settings)#

Generator function for settings dictionary with ‘indexed_values’ item Check that new_value is in settings[‘indexed_values’], if not, rejects command

Parameters:
obj

parent class object

new_value

new_value to be set on instrument

settingsdict

dictionary with [‘indexed_values’] item

Returns:
None
set_range_property(obj, new_value, settings)#

Generator function for settings dictionary with ‘range’ item Check that new_value is in settings[‘range’], if not, rejects command

Parameters:
obj

parent class object

new_value

new_value to be set on instrument

settingsdict

dictionary with [‘range’] item

Returns:
None
set_values_property(obj, new_value, settings)#

Generator function for settings dictionary with ‘values’ item Check that new_value is in settings[‘values’], if not, rejects command

Parameters:
obj

parent class object

new_value

new_value to be set on instrument

settingsdict

dictionary with [‘values’] item

Returns:
None
write(string)#

Wrapper to write string to the instrument object

Parameters:
string: str

The message to be sent

Returns:
None
pyscan.drivers.new_instrument.new_instrument(visa_string=None, gpib_address=None)#

Function creates a new visa instrument based on input type. If neither a visa_string or gpib_address is entered, prints a list of possible instruments and returns None. If both visa_string and gpib_address are entered, only gpib_address is used.

Parameters:
visa_stringstr

full visa string address, defaults to None.

gpib_address: int or str

int to format visa string ‘GPIB0::{}::INSTR’, defaults to None.

Returns:
pyvisa pyvisa.Resource

Subclass of Resource from pyvisa library matching the instrument

class pyscan.drivers.testing.test_voltage.TestVoltage(debug=False, instrument=None, *arg, **kwarg)#

Class that mimics the operation of a simple voltage source.

This is used in the demo jupyter notebooks.

Parameters:
instrumentmock

Optional parameter.

Attributes:
(Properties)
voltagefloat

Get/set a mock voltage, with default range [-10, 10]

powerint

Get/set a mock power setting, with available values [1, 10]

output_stateint or str

Get/set a mock output state, with dict values ‘on’, 1, ‘off’, or 0

Methods

query(string)

Wrapper to pass string to the instrument object

write(string)

Wrapper to write string to the instrument object

initialize_properties

query(string)#

Wrapper to pass string to the instrument object

Parameters:
string: str

The message to send to the device

Returns:
str

Answer from the device.

write(string)#

Wrapper to write string to the instrument object

Parameters:
string: str

The message to be sent

Returns:
None

Instruments#