Labtronyx¶
The Labtronyx project is a instrument control and automation framework. It features a robust core for simplifying communication with laboratory instruments and provides users with a powerful interface for controlling and automating tests and experiments. Labtronyx is developed in Python to take advantage of the powerful and vast collection of libraries, as well as to provide an easy to learn environment in which to develop.
The goals of the Labtronyx project are:
- Provide a framework for instrumentation that is easier to use (and cheaper) than MATLAB or LabVIEW.
- Compatibility with any instrument from any vendor using any protocol.
- Compatibility with Windows, Mac and Linux.
- Powerful, object-oriented architecture that is flexible and easy to develop
Labtronyx is all you need to develop robust scripts and applications for automation. With this framework, you will no longer have to worry about interfaces and protocols.
User Guide¶
Instructions for installing Labtronyx and the associated dependenciesFirst steps to connecting to and controlling instrumentsSee which instruments are currently supportedA collection of example scriptsDeveloping scripts using the Labtronyx Python Library and APIDevelop new drivers or interfaces for new instruments
Indices and tables¶
Lists all sections and subsections.All functions, classes, terms.Search this documentation.
Installation¶
Installing Python¶
Download the latest version of Python 2.7 from the official Python website . Follow the directions on the Python website and the downloaded installer.
Additional instructions and help can be found at http://python.org
Installing Labtronyx¶
From PIP¶
Labtronyx is released as a package to the Python Package Index, and can be installed using pip:
pip install labtronyx
This will also install all of the necessary dependencies automatically. If you are running an earlier version of python, you will need to install Pip before you will be able to install Labtronyx.
From Source¶
- Clone the Labtronyx repository or unzip the source archive file.
- Open a terminal window and browse to the location of the extracted files.
- Execute the following command:
python setup.py install
The proper dependent packages will also be installed.
Numpy on Windows¶
Numpy is a mathematics library for Python that provides optimized math functions used by many of the drivers in Labtronyx. When installing Labtronyx on Windows, it may be necessary to download additional programs to install Numpy correctly. This is only necessary when the installation above fails. There are two options:
Download the pre-compiled Numpy windows superpack distribution for your version of Python from the Numpy SourceForge page here.
e.g. numpy-1.9.2-win32-superpack-python2.7.exe
Download the Microsoft Visual C++ Compiler for Python 2.7. Install the package from pip: pip install numpy
Interface Dependencies¶
Below are instructions to install dependent programs to enable to use of certain Interfaces.
VISA¶
Using the VISA Interface requires a VISA server to be installed before Labtronyx can use any VISA resource. Any VISA compatible server should work fine, but NI-VISA was found to be the most stable during development. The latest version of NI-VISA can be downloaded from nivisa .
Install NI-VISA using the instructions and ReadMe file included with the installer. NI-VISA is compatible with Windows, Mac and Linux.
Getting Started¶
Introduction¶
The primary use case for Labtronyx is as a Python library. This way, it can be imported into an existing script, framework or application to enable automation with ease. Once Labtronyx is installed, it can be imported and used as a module:
import labtronyx
instr = labtronyx.InstrumentManager()
The Instrument Manager is the core of the Labtronyx framework. It connects to all of the compatible interfaces and
discovers connected instruments. The command findInstruments()
can be used to return a list of connected
instruments.:
dev_list = instr.findInstruments()
Note
labtronyx.InstrumentManager.findInstruments()
will always return a list of instrument objects, even if only one
was found.
To find a specific instrument connected to a specific port, you can specify the resourceID parameter to pinpoint which instrument you would like. This requires some knowledge of how the instrument is connected to the system:
device = instr.findInstruments(resourceID='COM16') # Serial
device = instr.findInstruments(resourceID='ASRL::16') # VISA
Additional labtronyx.InstrumentManager
methods can be found here: InstrumentManager API.
Using Instruments¶
Instruments are objects that allow you to control a physical device connected to the system. Instruments interact with the physical device through a Resource object which is managed by an interface connector (such as VISA, Serial, USB, etc). Before you can do anything with an instrument, it must be opened. Opening an instrument allows Labtronyx to communicate with the physical device and also acquires a lock to prevent other software on your computer from controlling this device as well.:
device.open()
By default, instruments contain only a small set of methods to interact with a device (see Resource API). These methods allow you to read and write to the device, but it has no knowledge of the capabilities of the device or the commands required to interact with that particular device.:
device.write('*IDN?')
identity = device.read()
In order to access the full capabilities of a device, you must load a Driver. When a driver is loaded for an instrument, additional methods are made available that may allow you to interact with the device without having to know all of the commands a device supports. Some interfaces, such as VISA, support automatically loading a Driver by using a discovery process supported by a majority of commercially available devices. For devices that do not support discovery, you will need to load a driver manually.:
device_list = instr.findInstruments(resourceID='ASRL::9')
if len(device_list) > 0:
instrument = device_list[0]
instrument.loadDriver('drivers.BK_Precision.Load.m_85XX')
Similarly, to unload a driver:
instrument.unloadDriver()
Once a driver is loaded, you can interact with the device using methods specific to that device. For documentation on the supported instruments and available commands for those instruments, see Supported Instruments.
Finding Instruments¶
If a driver is loaded for a particular instrument, you may be able to find instruments based on device metadata:
- Manufacturer
- Device Type
- Serial Number
- Model Number
To find devices by Manufacturer:
dev = instr.findInstruments(deviceVendor='Tektronix')
To connect to instruments by type:
scope = instr.findInstruments(deviceType='Oscilloscope')
To connect to instruments by Model number:
smu = instr.findInstruments(deviceModel='B2902A')
To connect to instruments by Serial number:
dev = instr.findInstruments(deviceSerial='12345')
Multiple search criteria can also be used to pinpoint a specific instrument if there are many instruments present on the system:
dev = instr.findInstruments(deviceType='Oscilloscope', deviceSerial='12345')
Other parameters you can use to identify devices:
- resourceID
- interface
- driver
- deviceVendor
- deviceModel
- deviceSerial
- deviceFirmware
Resources or drivers may specify additional properties that can be used to identify instruments. See the resource or driver documentation for your instrument to find out what else may be available. See Supported Instruments.
Instrument Metadata (Properties)¶
Instrument objects provide additional metadata about the physical device it is connected to. It could include information such as:
- Manufacturer
- Model number(s)
- Firmware Revision
- Serial Numbers
- Capabilities
- Channels/Probes
- etc.
This metadata is retrieved by calling getProperties()
and returned as a dictionary. All instruments provide the
following keys, with additional keys optionally added by the driver:
Key | Description |
---|---|
uuid | Resource UUID |
fqn | Fully Qualified Name of resource class |
interfaceName | The name of the associated interface |
resourceID | Resource ID specific for that interface |
driver | Driver name |
deviceType | Device type |
deviceVendor | Device vendor or manufacturer |
deviceModel | Device model number |
deviceSerial | Device serial number |
deviceFirmware | Device firmware revision number |
Supported Instruments¶
Agilent¶
33509B Function Generator
33510B Function Generator
33511B Function Generator
33512B Function Generator
33519B Function Generator
33520B Function Generator
33521A Function Generator
33521B Function Generator
33522A Function Generator
33522B Function Generator
34410A Multimeter
34411A Multimeter
B2901A Source Measurement Unit
B2902A Source Measurement Unit
L4411A Multimeter
BK Precision¶
2831E Multimeter
5491B Multimeter
5492B Multimeter
5492BGPIB Multimeter
8500 DC Electronic Load
8502 DC Electronic Load
8510 DC Electronic Load
8512 DC Electronic Load
8514 DC Electronic Load
8518 DC Electronic Load
8520 DC Electronic Load
8522 DC Electronic Load
8524 DC Electronic Load
8526 DC Electronic Load
9115 DC Power Supply
9116 DC Power Supply
XLN10014 DC Power Supply
XLN15010 DC Power Supply
XLN30052 DC Power Supply
XLN3640 DC Power Supply
XLN60026 DC Power Supply
XLN6024 DC Power Supply
XLN8018 DC Power Supply
Chroma¶
62006P-100-25 DC Power Supply
62006P-30-80 DC Power Supply
62006P-300-8 DC Power Supply
62012P-100-50 DC Power Supply
62012P-40-120 DC Power Supply
62012P-600-8 DC Power Supply
62012P-80-60 DC Power Supply
62024P-100-50 DC Power Supply
62024P-40-120 DC Power Supply
62024P-600-8 DC Power Supply
62024P-80-60 DC Power Supply
62052P-100-100 DC Power Supply
Regatron¶
Sorensen¶
TDI¶
XBL-100-120-800 DC Electronic Load
XBL-100-300-2000 DC Electronic Load
XBL-100-600-4000 DC Electronic Load
XBL-100-600-6000 DC Electronic Load
XBL-400-120-800 DC Electronic Load
XBL-400-300-2000 DC Electronic Load
XBL-400-600-4000 DC Electronic Load
XBL-400-600-6000 DC Electronic Load
XBL-50-1000-4000 DC Electronic Load
XBL-50-150-800 DC Electronic Load
XBL-50-400-2000 DC Electronic Load
XBL-600-100-2000 DC Electronic Load
XBL-600-200-4000 DC Electronic Load
XBL-600-200-6000 DC Electronic Load
XBL-600-40-800 DC Electronic Load
Tektronix¶
DPO2002B Oscilloscope
DPO2004B Oscilloscope
DPO2012 Oscilloscope
DPO2012B Oscilloscope
DPO2014 Oscilloscope
DPO2014B Oscilloscope
DPO2022B Oscilloscope
DPO2024 Oscilloscope
DPO2024B Oscilloscope
DPO5034 Oscilloscope
DPO5034B Oscilloscope
DPO5054 Oscilloscope
DPO5054B Oscilloscope
DPO5104 Oscilloscope
DPO5104B Oscilloscope
DPO5204 Oscilloscope
DPO5204B Oscilloscope
DPO70404C Oscilloscope
DPO7054C Oscilloscope
DPO70604C Oscilloscope
DPO70804C Oscilloscope
DPO7104C Oscilloscope
DPO71254C Oscilloscope
DPO71604C Oscilloscope
DPO72004C Oscilloscope
DPO72304DX Oscilloscope
DPO72504DX Oscilloscope
DPO7254C Oscilloscope
DPO73304DX Oscilloscope
DPO7354C Oscilloscope
MSO2002B Oscilloscope
MSO2004B Oscilloscope
MSO2012 Oscilloscope
MSO2012B Oscilloscope
MSO2014 Oscilloscope
MSO2014B Oscilloscope
MSO2022B Oscilloscope
MSO2024 Oscilloscope
MSO2024B Oscilloscope
MSO5034 Oscilloscope
MSO5034B Oscilloscope
MSO5054 Oscilloscope
MSO5054B Oscilloscope
MSO5104 Oscilloscope
MSO5104B Oscilloscope
MSO5204 Oscilloscope
MSO5204B Oscilloscope
MSO70404C Oscilloscope
MSO70604C Oscilloscope
MSO70804C Oscilloscope
MSO71254C Oscilloscope
MSO71604C Oscilloscope
MSO72004C Oscilloscope
MSO72304DX Oscilloscope
MSO72504DX Oscilloscope
MSO73304DX Oscilloscope
Examples¶
Agilent 34410A Multimeter¶
import labtronyx
# Enable debug logging
labtronyx.logConsole()
# Instantiate an InstrumentManager
im = labtronyx.InstrumentManager()
# Find the instrument by model number
dev_list = im.findInstruments(deviceVendor="Agilent", deviceModel="34410A")
dev = dev_list[0]
# Open the instrument
with dev:
# Disable the front panel
dev.disableFrontPanel()
# Set the text on the front panel
dev.frontPanelText("PRIMARY VOLT", "measuring...")
# Set the mode to DC Voltage
dev.setMode('DC Voltage')
# Set the sample count to 10
dev.setSampleCount(10)
# Measure the input
data = dev.getMeasurement()
# Check for errors
dev.checkForError()
API¶
Labtronyx Python Library API
API Documentation for the InstrumentManager and RemoteManager classesAPI Documentation for general resourcesErrors and ExceptionsAPI documentation for all driversAPI documentation for all interfaces and associated resource types
InstrumentManager¶
The InstrumentManager object is the primary interface to communicating with instruments. It simplifies script development by abstracting instruments as Python objects.
-
class
labtronyx.
InstrumentManager
(**kwargs)[source]¶ Labtronyx InstrumentManager
Facilitates communication with instruments using all available interfaces.
Parameters: - server (bool) – Enable RPC endpoint
- server_port (int) – RPC endpoint port
- plugin_dirs (list) – List of directories containing plugins
- logger (logging.Logger) – Logger
-
addPluginSearchDirectory
(path)[source]¶ Add a search path for plugins. Directory will be searched immediately and all discovered plugins will be cataloged. If a search path has already been searched, it will not be searched again. Interfaces will not be started automatically. Use
enableInterface()
to start the interface once it has been discovered.Parameters: path (str) – Search directory
-
closeScript
(script_uuid)[source]¶ Destroy a script instance that is not currently running.
Parameters: script_uuid (str) – Script Instance UUID Return type: bool
-
disableInterface
(interface)[source]¶ Disable an interface that is running.
Parameters: interface (str) – Interface Name (interfaceName attribute of plugin) or Interface UUID Return type: bool
-
enableInterface
(interfaceName, **kwargs)[source]¶ Enable or restart an interface. Use this method to pass parameters to an interface. If an interface with the same name is already running, it will be stopped first. Each interface may only have one instance at a time (Singleton pattern).
Parameters: interfaceName (str) – Interface Name (interfaceName attribute of plugin) or plugin FQN Return type: bool Raises: KeyError
-
findResources
(**kwargs)[source]¶ Get a list of resources/instruments that match the parameters specified. Parameters can be any key found in the resource property dictionary, such as these:
Parameters: - uuid – Unique Resource Identifier (UUID)
- interface – Interface
- resourceID – Interface Resource Identifier (Port, Address, etc.)
- resourceType – Resource Type (Serial, VISA, etc.)
- deviceVendor – Instrument Vendor
- deviceModel – Instrument Model Number
- deviceSerial – Instrument Serial Number
Return type: list[labtronyx.bases.resource.ResourceBase]
-
getAttributes
()[source]¶ Get the class attributes for all loaded plugins. Dictionary keys are the Fully Qualified Names (FQN) of the plugins
Return type: dict[str:dict]
-
getPluginSearchDirectories
()[source]¶ Get a list of all the searched paths for plugins.
Return type: list
-
getProperties
()[source]¶ Returns the property dictionaries for all resources
Return type: dict[str:dict]
-
getResource
(interfaceName, resID, driverName=None)[source]¶ Get a resource by name from the specified interface. Not supported by all interfaces, see interface documentation for more details.
Parameters: Returns: Resource object
Return type: Raises: InterfaceUnavailable
Raises: ResourceUnavailable
Raises: InterfaceError
-
listInterfaces
()[source]¶ Get a list of interface names that are enabled
Returns: Interface names Return type: list[str]
-
listResources
()[source]¶ Get a list of UUIDs for all resources
Deprecated: Deprecated by getProperties()
Return type: list[str]
-
openScript
(script_fqn, **kwargs)[source]¶ Create an instance of a script. The script must have already been loaded by the plugin manager. Any required script parameters can be provided using keyword arguments.
Parameters: script_fqn (str) – Fully Qualified Name of the script plugin Returns: Script Instance UUID Return type: str Raises: KeyError Raises: RuntimeError
-
refresh
()[source]¶ Refresh all interfaces and resources. Attempts enumeration on all interfaces, then calls the refresh method for all resources.
-
runScript
(script_uuid)[source]¶ Run a script that has been previously opened using
openScript()
. The script is run in a separate threadParameters: script_uuid (str) – Script Instance UUID Raises: KeyError Raises: ThreadError
-
server_start
(new_thread=True)[source]¶ Start the API/RPC Server and Event publisher. If new_thread is True, the server will be started in a new thread in a non-blocking fashion.
If a server is already running, it will be stopped and then restarted.
Returns: True if successful, False otherwise Return type: bool
-
stopScript
(script_uuid)[source]¶ Stop a script that is currently running. Does not currently do anything.
Parameters: script_uuid (str) – Script Instance UUID Raises: KeyError
-
interfaces
¶ Returns: Dictionary of interface plugin instances {UUID -> Interface Object} Return type: dict[str:labtronyx.bases.interface.InterfaceBase]
-
scripts
¶ Returns: Dictionary of script plugin instances {UUID -> Script object} Return type: dict[str:labtronyx.bases.script.ScriptBase]
Resources¶
Resources are created and managed by an Interface object. All resources will implement the API specified below. Methods and properties beyond this API are specified in the Interface docs.
API¶
Getting started¶
All resources are subclasses of the labtronyx.ResourceBase
class. Creating a resource is simple:
import labtronyx
class RESOURCE_CLASS_NAME(labtronyx.ResourceBase):
pass
Attributes¶
Resources have some attributes that should be defined:
- interfaceName - str that names the interface that owns the resource. Should match the interfaceName attribute of the corresponding interface.
Errors¶
Labtronyx has a number of build-in exception types that can be raised from resources. For more information about these exceptions and the proper times to raise them, see Exceptions
Usage Model¶
When resources are created, they should default to the closed state. This is to prevent any locking issues if multiple instances of Labtronyx are open. Resources should typically only be open if they are actively in use.
When a driver is loaded, the resource object acts as a proxy to access the driver methods. All driver functions are accessed directly from the resource object as if they were a single object. Some things to note:
- If there is a naming conflict between a method in the resource and a method in the driver, the resource method will take priority
- Driver functions are inaccessible and cannot be called if the resource is closed
Note
In order to support proper operation using Remote Resources and Instruments, some limitations should be imposed to ensure maximum compatibility. All methods within a resource or driver must return serializable data. Serializable data types include:
- str
- unicode
- int
- long
- float
- bool
- list
- tuple
- dict
- None
If a method returns an object that is not serializable, an exception will be passed back to the remote host. If the method returns a non-serializable data type, the method should be prefixed with an underscore (‘_’) to mark it as a protected function that cannot be accessed remotely.
Resources may implement more functions than just those which are defined in the API below, see the interface and resource class documentation to learn more.
-
class
labtronyx.bases.resource.
ResourceBase
(manager, resID, **kwargs)[source]¶ Resource Base Class. Acts as a proxy for driver if one is loaded.
Parameters: - manager (labtronyx.InstrumentManager) – InstrumentManager instance
- interface (labtronyx.bases.interface.InterfaceBase) – Reference to the interface instance
- resID (str) – Resource Identifier
- logger (logging.Logger) – Logger instance
-
getProperties
()[source]¶ Get the property dictionary for the resource. If a driver is loaded, the driver properties will be merged and returned as well
Return type: dict[str:object]
-
loadDriver
(driverName, force=False)[source]¶ Load a Driver for a resource. A driver name can be specified, even if it may not be compatible with this resource. Existing driver is no unloaded unless the force parameter is set to True.
Parameters: - driverName (str) – Module name of the desired Model
- force – Force load driver by unloading existing driver
Returns: True if successful, False otherwise
Raises: KeyError if driver class not found
-
open
()[source]¶ Open the resource. If a driver is loaded, the driver open method will also be called
Returns: True if open was successful, False otherwise Raises: ResourceUnavailable
-
unloadDriver
()[source]¶ If a driver is currently loaded for the resource, unload it. This will close the resource as well.
Returns: True if successful, False otherwise
-
driver
¶ Return type: labtronyx.bases.driver.DriverBase
Exceptions¶
The interface could not be opened because it is unavailable. Possible causes:
- A library is missing or not installed
- An error occurred while accessing the interface
-
exception
labtronyx.common.errors.
InterfaceError
[source]¶ Generic error for an exception that occurred during a low-level interface operation.
-
exception
labtronyx.common.errors.
InterfaceTimeout
[source]¶ A timeout condition occurred during data transmission, data was not received within the timeout window.
The Resource could not be opened because it is unavailable. Possible causes:
- Resource is in use by another program
- Resource is locked by the system
- Resource does not actually exist or is no longer connected to the system
Drivers¶
Agilent.FunctionGenerator¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Agilent.Multimeter¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
-
class
labtronyx.drivers.Agilent.Multimeter.
d_3441XA
(resource, **kwargs)[source]¶ Driver for Agilent 34410A and 34411A Digital Multimeter
-
checkForError
()[source]¶ Query the device for errors. Raises an exception if an error was registered on the device
-
disableFrontPanel
()[source]¶ Disables the front panel display. Display can be re-enabled by calling enableFrontPanel or pressing the LOCAL button on the instrument.
-
frontPanelText
(text_top, text_bottom)[source]¶ Set the text on the front panel of the instrument. The top line is limited to 12 characters, the bottom line to 18 characters. You can use letters (A-Z), numbers (0-9), and special characters like “@”, “%”, “*”, etc. Use “#” character to display a degree symbol.
Parameters:
-
getError
()[source]¶ Get the last recorded error from the instrument
Returns: error code, error message
-
getIntegrationRate
()[source]¶ Get the integration period (measurement speed). Expressed as a factor of the power line frequency.
Returns: float
-
getMeasurement
()[source]¶ Get the last available reading from the instrument. This command does not trigger a measurement if trigger source is not set to IMMEDIATE.
Returns: float
-
getSampleCount
()[source]¶ Get the number of readings (samples) the multimeter will take per trigger.
Returns: Number of samples (int)
-
self_test
()[source]¶ Run the self-test suite
+========+================================+ | Test # | Test Name | +========+================================+ | 600 | Front Panel Communications | | 601 | Front Panel All On Test | | 602 | A/D Feedback Test | | 603 | Fine A/D Test | | 604 | Fine A/D Linearity | | 605 | A/D & FE Measure Zero | | 606 | Input Amplifier x100 Zero Test | | 607 | Input Amplifier x10 Zero Test | | 608 | Input Amplifier x1 Zero Test | | 609 | Input Leakage Test | | 610 | Input Amplifier x10 Gain Test | | 611 | Input Amplifier x1 Gain Test | | 612 | Ohms 500nA Current Source | | 613 | DC High Voltage Divider Test | | 614 | Ohms 5uA Current Source Test | | 615 | Ohms 10uA Current Source | | 616 | Ohms 100uA to 200 Ohm Shunt | | 617 | Ohms 1mA to 2 Ohm Shunt | | 618 | High Current Shunt Test | | 619 | AC 0.1VAC Zero Test | | 620 | Precharge Amplifier Gain Test | | 621 | Precharge Offset Range Test | | 622 | FPGA Ping Test | +——–+——————————–+ :return:
-
setIntegrationRate
(value)[source]¶ Set the integration period (measurement speed) for the basic measurement functions (except frequency and period). Expressed as a factor of the power line frequency (PLC = Power Line Cycles).
Valid values: 0.006, 0.02, 0.06, 0.2, 1, 2, 10, 100
Value of ‘DEF’ sets the integration rate to 1 PLC
Parameters: value – Integration rate
-
setMode
(func)[source]¶ Set the configuration mode
Valid modes:
- ‘AC Voltage’
- ‘DC Voltage’
- ‘Resistance’
- ‘4-wire Resistance’
- ‘AC Current’
- ‘DC Current’
- ‘Frequency’
- ‘Period’
- ‘Diode’
- ‘Continuity’
- ‘Capacitance
- ‘Temperature’
Parameters: func (str) – Configuration mode
-
setRange
(new_range)[source]¶ Set the range for the measurement. The range is selected by specifying the expected reading as an absolute value. The instrument will then go to the most ideal range that will accommodate the expected reading
Possible value ranges:
- ‘AUTO’
- DC Voltage: 0 to 1000 Volts
- AC Voltage: 0 to 750 Volts
- Current: 0 to 20 Amps
- Resistance: 0 to 20e6 ohms
- Frequency or Period: 0 to 1010 Volts
Parameters: new_range (str) – Measurement Range
-
setSampleCount
(samples)[source]¶ Set the number of readings (samples) the multimeter will take per trigger.
When the sample source is Immediate, the trigger delay value is used to determine how far apart the samples are to be taken. In Timer mode, the sample timer value is used.
Parameters: samples (int) – Number of samples
-
setTriggerCount
(count)[source]¶ This command selects the number of triggers that will be accepted by the meter before returning to the “idle” trigger state.
A value of ‘0’ will set the multimeter into continuous trigger mode.
Parameters: count (int) – Number of triggers
-
setTriggerDelay
(delay=None)[source]¶ This command sets the delay between the trigger signal and the first measurement. This may be useful in applications where you want to allow the input to settle before taking a reading or for pacing a burst of readings. The programmed trigger delay overrides the default trigger delay that the instrument automatically adds.
If delay is not provided, the automatic trigger delay is enabled
Note:
The Continuity and Diode test functions ignore the trigger delay setting
Parameters: delay (float) – Trigger delay (in seconds)
-
setTriggerSource
(source)[source]¶ Set the trigger source for a measurement.
Valid values:
- IMMEDIATE: Internal continuous trigger
- BUS: Triggered via USB/RS-232 Interface
- EXTERNAL: Triggered via the ‘Ext Trig Input’ BNC connector
For the EXTernal source, the instrument will accept a hardware trigger applied to the rear-panel Ext Trig Input BNC connector. The instrument takes one reading, or the specified number of readings (sample count), each time a TTL pulse (low-true for slope = negative) is received. If the instrument receives an external trigger before it is ready to accept one, it will buffer one trigger.
Parameters: source (str) – Trigger source
-
trigger
()[source]¶ Used in conjunction with the Trigger Source to trigger the instrument from the remote interface. After setting the trigger source, you must place the multimeter in the “wait-for-trigger” state by calling
waitForTrigger()
.
-
Agilent.SMU¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
-
class
labtronyx.drivers.Agilent.SMU.
d_B29XX
(resource, **kwargs)[source]¶ Driver for Agilent B2901A and B2902A Source Measurement Units
-
clearTraceBuffer
(channel)[source]¶ Clears the trace buffer of the specified channel.
Parameters: channel (int) – SMU Channel
-
disableAutoAperture
(channel)[source]¶ Disables the auto aperture function.
Parameters: channel (int) – SMU Channel
-
disableFrontPanel
()[source]¶ Disables the front panel display. Display can be re-enabled by calling enableFrontPanel or pressing the LOCAL button on the instrument.
-
disableHighCapacitanceOutput
(channel)[source]¶ Disables the high capacitance mode.
Parameters: channel (int) – SMU Channel
-
disableRemoteSense
(channel)[source]¶ Disable Remote Sense (4-wire) measurements
Parameters: channel (int) – SMU Channel
-
enableAutoAperture
(channel)[source]¶ Enables the auto aperture function. When enabled, the instrument automatically sets the integration time suitable for the measurement range.
Parameters: channel (int) – SMU Channel
-
enableHighCapacitanceOutput
(channel)[source]¶ Enables the high capacitance mode. This mode is effective for high capacitance DUT
Parameters: channel (int) – SMU Channel
-
enableRemoteSense
(channel)[source]¶ Enable Remote Sense (4-wire) measurements
Parameters: channel (int) – SMU Channel
-
enableTraceBuffer
(channel)[source]¶ Enables the trace buffer to start collecting data points. Buffer size is set using setTraceBufferPoints.
Parameters: channel (int) – SMU Channel
-
frontPanelText
(text_top, text_bottom)[source]¶ Set the text on the front panel of the instrument. The top line is limited to 12 characters, the bottom line to 18 characters. You can use letters (A-Z), numbers (0-9), and special characters like “@”, “%”, “*”, etc. Use “#” character to display a degree symbol.
Parameters:
-
getApertureTime
(channel)[source]¶ Get the instrument aperture time.
Parameters: channel (int) – SMU Channel Returns: float
-
getError
()[source]¶ Get the last recorded error from the instrument
Returns: error code, error message
-
getMeasureMode
(channel)[source]¶ Get the enabled measurement functions
Parameters: channel (int) – SMU Channel Returns: str
-
getMeasurementData
(channel)[source]¶ Get the measurement data from the instrument
Parameters: channel (int) – SMU Channel
-
getMeasurementRange
(channel)[source]¶ Get the measurement range.
Parameters: channel (int) – SMU Channel
-
getScreenshot
(filename)[source]¶ Save a screenshot of the instrument. Supported picture formats are JPG, BMP, PNG, WMF.
Parameters: filename (str) – Filename for saved screenshot
-
getSourceCurrent
(channel)[source]¶ Get the source output current
Parameters: channel (int) – SMU Channel Returns: float
-
getSourceOutputMode
(channel)[source]¶ Get the source output mode. Returns ‘VOLT’ (Voltage) or ‘CURR’ (Current)
Parameters: channel (int) – SMU Channel Returns: str
-
getSourceVoltage
(channel)[source]¶ Get the source output voltage
Parameters: channel (int) – SMU Channel Returns: float
-
getTraceBuffer
(channel, offset=0, size=None)[source]¶ Returns data in the trace buffer of the specified channel.
Parameters: Returns:
-
getTraceBufferPoints
(channel)[source]¶ Get the size of the instrument trace buffer, and the number of data points currently in the buffer
Parameters: channel (int) – SMU Channel Returns: Buffer size, number of points in the buffer
-
getTriggerDelay
(channel)[source]¶ Get the time delay before the first trigger
Parameters: channel (int) – SMU Channel
-
getTriggerInterval
(channel)[source]¶ Get the time interval between triggers.
Parameters: channel (int) – SMU Channel
-
getTriggerSource
(channel)[source]¶ Get current trigger source.
Parameters: channel (int) – SMU Channel Returns: Trigger source Return type: str
-
powerOff
(channel)[source]¶ Power off the SMU using the previously programmed power-off mode
Parameters: channel (int) – SMU Channel
-
powerOn
(channel)[source]¶ Enable the SMU to the programmed output level
Parameters: channel (int) – SMU Channel
-
rampVoltage
(channel, startVoltage, stopVoltage, time, delay=0)[source]¶ Automated voltage ramp. Enables power output, sweeps from startVoltage to stopVoltage and keeps power enabled after ramp is complete.
Parameters:
-
setApertureTime
(channel, apertureTime)[source]¶ Sets the integration time for one point measurement. Aperture time must be between 8e-6 to 2 seconds. If the value specified is less than MIN or greater than MAX, the value is automatically set to MIN or MAX.
Parameters: Raises: RuntimeError on verification failure
-
setCurrentLimit
(channel, limit)[source]¶ Set current protection limit. Automatically enables current protection mode
Parameters:
-
setMeasureMode
(channel, measure_mode)[source]¶ Enable measurement functions. Instrument can measure Voltage (‘VOLT’), Current (‘CURR’) or Resistance (‘RES’)
Parameters: Raises: RuntimeError on verification failure
-
setMeasurementRange
(channel, meas_range)[source]¶ Set the measurement range.
Voltage Measurement Range +=============+===========================+============+ | Range Value | Voltage Measurement Value | Resolution | +=============+===========================+============+ | 0.2 V | 0 < Voltage < 0.212 | 0.1 uV | | 2.0 V | 0 < Voltage < 2.12 | 1.0 uV | | 20 V | 0 < Voltage < 21.2 | 10 uV | | 200 V | 0 < Voltage < 212 | 100 uV | +————-+—————————+————+
Current Measurement Range +=============+===========================+============+ | Range Value | Voltage Measurement Value | Resolution | +=============+===========================+============+ | 100 nA | 0 < Current < 106 nA | 100 fA | | 1 uA | 0 < Current < 1.06 uA | 1 pA | | 10 uA | 0 < Current < 10.6 uA | 10 pA | | 100 uA | 0 < Current < 106 uA | 100 pA | | 1 mA | 0 < Current < 1.06 mA | 1 nA | | 10 mA | 0 < Current < 10.6 mA | 10 nA | | 100 mA | 0 < Current < 106 mA | 100 nA | | 1 A | 0 < Current < 1.06 A | 1 uA | | 1.5 A | 0 < Current < 1.53 A | 1 uA | | 3 A | 0 < Current < 3.06 A | 10 uA | +————-+—————————+————+
Parameters:
-
setMeasurementRangeAuto
(channel)[source]¶ Set the measurement range mode to auto
Parameters: channel (int) – SMU Channel
-
setPowerOffMode
(channel, mode)[source]¶ Set the power off mode
- NORMAL - Normal (0V, output relay off)
- ZERO - Ground output (0V, output relay on)
- HIZ - Float output (Floating, output relay off)
Parameters: Returns:
-
setPowerOffModeFloat
(channel)[source]¶ Power off the SMU, output is left floating
Parameters: channel (int) – SMU Channel
-
setPowerOffModeZero
(channel)[source]¶ Power off the SMU, output is held at ground voltage
Parameters: channel (int) – SMU Channel
-
setSourceCurrent
(channel, current_base, current_trig=None)[source]¶ Set the source output current. current_trig is used to specify a current level when the instrument is triggered
Parameters: Raises: RuntimeError on verification failure
-
setSourceFixed
(channel)[source]¶ Set the source to fixed voltage/current mode.
Parameters: channel (int) – SMU Channel
-
setSourceList
(channel, source_points=())[source]¶ Set the source to list mode. Must set to current or voltage output mode first. Timing between each point is controlled by the trigger settings. Trigger points should equal the number of items in source_points. List mode is initiated by using the startProgram method. To set a fixed timing between list points, consider this example:
setTriggerSource(1, 'TIM') # Timer setTriggerInterval(1, 1e-3) # 1ms between sweep points powerOn(1) startProgram(1)
Parameters:
-
setSourceSweep
(channel, start, stop, points=2500)[source]¶ Set the source to sweep mode. Must set to current or voltage mode first. Sweeps from start to stop with points number of points. Timing between each sweep point is controlled by the trigger settings. Trigger points should match points. Sweep is initiated using the startProgram method. To set a fixed timing between sweep points, consider this example:
setTriggerSource(1, 'TIM') # Timer setTriggerInterval(1, 1e-3) # 1ms between sweep points powerOn(1) startProgram(1)
Parameters:
-
setSourceVoltage
(channel, voltage_base, voltage_trig=None)[source]¶ Set the source output voltage. voltage_trig is used to specify a voltage level when the instrument is triggered
Parameters: Raises: RuntimeError on verification failure
-
setTraceBufferPoints
(channel, data_points)[source]¶ Sets the size of the instrument trace buffer. The maximum number of data points in the trace buffer is 100,000.
Parameters:
-
setTriggerCount
(channel, number)[source]¶ Set the trigger count for the specified device action
Parameters:
-
setTriggerInterval
(channel, interval)[source]¶ Set the time interval between triggers. interval is the number of seconds, must be between 1E-5 and 1E+5.
Parameters: - channel (int) – SMU Channel
- interval – Trigger timer interval (seconds)
Float interval: float
-
setTriggerSource
(channel, triggerSource)[source]¶ Set the trigger source. See VALID_TRIGGER_SOURCES attribute for valid values for parameter triggerSource
Parameters:
-
setTriggerSourceTimer
(channel)[source]¶ Use the timer as the trigger source
Parameters: channel (int) – SMU Channel
-
BK_Precision.Load¶
BK Precision DC Loads
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Connection Instructions¶
The BK Precision 8500 Series DC Loads must be connected to a PC through a USB-to-Serial adapter. BK Precision also recommends using an RS-232-to-TTL isolated pass-through to protect the serial interface on the instrument.
These devices also use a custom communication protocol that does not support enumeration. In order to use the device, this driver must be loaded to the proper serial port before use. Once the driver is loaded, the device will be placed into Remote Control mode.
Driver¶
You may need to install a driver for the USB-to-Serial adapter. Follow the instructions from the device vendor’s website.
BK Precision provides a device for communicating with this class of DC load: IT-132 USB-to-Serial Adapter. The driver for this device can be found here
-
class
labtronyx.drivers.BK_Precision.Load.
d_85XX
(resource, **kwargs)[source]¶ Driver for BK Precision 8500 Series DC Loads
Adapted from reference code provided by BK Precision
-
disableLocalControl
()[source]¶ Disable local control of the load. User will be unable to control load functions using the front panel.
-
getInputValues
()[source]¶ Returns voltage in V, current in A, and power in W, op_state byte, and demand_state byte.
Returns: list: [voltage, current, power, op_state, demand_state]
-
getMode
()[source]¶ Gets the operating mode
Possible values:
- cc: Constant Current
- cv: Constant Voltage
- cw: Constant Power
- cr: Constant Resistance
Returns: str
-
getTransient
(mode)[source]¶ Gets the transient mode settings
Returns: tuple (Amplitude A, Width A, Amplitude B, Width B, Mode)
-
setBatteryTestVoltage
(min_voltage)[source]¶ Sets the battery test voltage
Parameters: min_voltage (float) – Minimum Voltage (volts)
-
setCurrent
(current)[source]¶ Sets the constant current mode’s current level
Parameters: current (float) – Current in Amps
-
setFunction
(function='fixed')[source]¶ Set the function (type of operation) of the load.
Parameters: function (str) – Function (“fixed”, “short”, “transient”, “list” or “battery”)
-
setLoadOnTimer
(time_in_s)[source]¶ Sets the time in seconds that the load will be on
Parameters: time_in_s (int) – Time (in seconds)
-
setLoadOnTimerState
(enabled=0)[source]¶ Enables or disables the LOAD ON timer state
Parameters: enabled (int) – Timer State (0: Disabled, 1: Enabled)
-
setMaxCurrent
(current)[source]¶ Sets the maximum current the load will sink
Parameters: current (float) – Current in Amps
-
setMaxPower
(power)[source]¶ Sets the maximum power the load will allow
Parameters: power (float) – Power in Watts
-
setMaxVoltage
(voltage)[source]¶ Sets the maximum voltage the load will allow
Parameters: voltage (float) – Voltage in Volts
-
setMode
(mode)[source]¶ Sets the operating mode
Possible values:
- cc: Constant Current
- cv: Constant Voltage
- cp: Constant Power
- cr: Constant Resistance
Parameters: mode (str) – Operating mode Raises: Exception
-
setPower
(power)[source]¶ Sets the constant power mode’s power level
Parameters: power (float) – Power in Watts
-
setResistance
(resistance)[source]¶ Sets the constant resistance mode’s resistance level
Parameters: resistance (str) – Resistance in Ohms
-
setTransient
(A, A_time_s, B, B_time_s, operation='continuous')[source]¶ Sets up the transient operation mode.
Parameters:
-
setTriggerSource
(source='IMMEDIATE')[source]¶ Set how the instrument will be triggered:
- “IMMEDIATE” means triggered from the front panel.
- “EXTERNAL” means triggered by a TTL signal on the rear panel.
- “BUS” means a software trigger (see Trigger()).
Parameters: source (str) – Source (“immediate”, “external” or “bus”) Raises: ValueError
-
BK_Precision.Multimeter¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Driver¶
The BK Precision Multimeters use a Silicon Labs CP210x USB to UART Bridge. This requires a third party driver that must be downloaded from the BK Precision website before connecting the device.
That driver can be downloaded from here
The driver officially supports Windows XP, Vista, 7
Configuration¶
In order to be recognized by the VISA driver, the instrument must be configured with a baudrate of 9600. This must be done on the instrument following the directions given in the user’s guide
-
class
labtronyx.drivers.BK_Precision.Multimeter.
d_2831
(resource, **kwargs)[source]¶ Driver for BK Precision 2831E and 5491B Digital Multimeters
-
disableFrontPanel
()[source]¶ Disables the front panel display. Display can be re-enabled by calling enableFrontPanel or pressing the LOCAL button on the instrument.
-
getIntegrationRate
()[source]¶ Get the integration period (measurement speed). Expressed as a factor of the power line frequency.
Returns: float
-
getMeasurement
()[source]¶ Get the last available reading from the instrument. This command does not trigger a measurement if trigger source is not set to IMMEDIATE.
Returns: float
-
setIntegrationRate
(value)[source]¶ Set the integration period (measurement speed) for the basic measurement functions (except frequency and period). Expressed as a factor of the power line frequency.
Parameters: value – Integration rate
-
setMeasurementOffset
(value=None)[source]¶ Establish a reference value for the measurement. When the offset is set, the result of a measurement will be the algebraic difference between the reference value and the current reading.
Expected value ranges:
- DC Voltage: 0 to 1000 Volts
- AC Voltage: 0 to 750 Volts
- Current: 0 to 20 Amps
- Resistance: 0 to 20e6 ohms
Parameters: value (float) – Reference value
-
setMode
(func)[source]¶ Set the configuration mode
Valid modes:
- ‘AC Voltage’
- ‘DC Voltage’
- ‘Resistance’
- ‘AC Current’
- ‘DC Current’
- ‘Frequency’
- ‘Period’
- ‘Diode’
- ‘Continuity’
Parameters: func (str) – Configuration mode
-
setRange
(value)[source]¶ Set the range for the measurement. The range is selected by specifying the expected reading as an absolute value. The instrument will then go to the most ideal range that will accomodate the expected reading
Possible values for value:
- ‘MIN’ or ‘0’
- Number (see ranges below)
- ‘DEFAULT’
- ‘MAX’
- ‘AUTO’
Expected value ranges:
- DC Voltage: 0 to 1000 Volts
- AC Voltage: 0 to 750 Volts
- Current: 0 to 20 Amps
- Resistance: 0 to 20e6 ohms
- Frequency or Period: 0 to 1010 Volts
Parameters: value (str) – Measurement Range
-
BK_Precision.Source¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Driver¶
The BK Precision 9110 Series DC Power Sources use the default USB Test and Measurement driver and should be recognized without problems when plugged in. If the device is not recognized, it is likely because there is a problem with the VISA driver installation.
The XLN Series DC Sources use a Silicon Labs CP210x USB to UART Bridge. This requires a third party driver that must be downloaded from the BK Precision website before connecting the device.
That driver can be downloaded from here
Remote Interface¶
The XLN series DC sources feature a remote web interface using the Ethernet connection, that can be accessed by typing in the instrument IP address into a Java-enabled web browser.
-
class
labtronyx.drivers.BK_Precision.Source.
d_911X
(resource, **kwargs)[source]¶ Driver for BK Precision 9110 Series DC Power Sources
-
clearProtectionState
()[source]¶ This command is used to clear the OVP (Over-Voltage Protection) state. Before sending this command, please increase the upper limitation of OVP or reduce the output voltage
-
disableFrontPanel
()[source]¶ Disables the front panel of the instrument. To re-enable the front panel, call setLocalControl
-
getProtectionState
()[source]¶ This command is used to query the executing state of OVP (Over-Voltage Protection). If 1, this indicates the OVP circuit has been triggered and must be cleared using clearProtectionState before normal operation can continue.
note..
This operation is not supported by the deviceReturns: int
-
getTerminalCurrent
()[source]¶ Get the measured current from the terminals of the instrument
Returns: float
-
getTerminalPower
()[source]¶ Get the measured power from the terminals of the instrument
Returns: float
-
getTerminalVoltage
()[source]¶ Get the measured voltage from the terminals of the instrument
Returns: float
-
getTriggeredCurrent
()[source]¶ Get the programmed output current level after a trigger has occurred.
Returns: float
-
getTriggeredVoltage
()[source]¶ Get the programmed output voltage level after a trigger has occurred.
Returns: float
-
setCurrent
(current)[source]¶ Set the output current level
Parameters: current (float) – Current (in Amps)
-
setProtection
(voltage=None)[source]¶ Enable the protection circuitry. If any of the parameters is zero, that protection is disabled.
Parameters: voltage (float) – OVP Setting (in Volts)
-
setProtectionDelay
(delay)[source]¶ Set the OVP (Over-Voltage Protection) circuitry delay. Can be used to set the delay (in seconds) before the OVP kicks in.
Delay must be between 0.001 - 0.6
Parameters: delay (float) – OVP delay (in seconds)
-
setTriggerSource
(source)[source]¶ Set the trigger source for the instrument. Manual trigger requires pressing the Trigger button on the front panel. Bus trigger requires a trigger command to be sent.
Parameters: source (str) – Trigger Source (“BUS” or “MANUAL”)
-
setTriggeredCurrent
(current)[source]¶ Set the programmed output current level after a trigger has occurred.
Parameters: current (float) – Current (in Amps)
-
setTriggeredVoltage
(voltage)[source]¶ Set the programmed output voltage level after a trigger has occurred.
Parameters: voltage (float) – Voltage (in Volts)
-
setVoltage
(voltage)[source]¶ Set the output voltage level
Parameters: voltage (float) – Voltage (in Volts)
-
setVoltageRange
(lower, upper)[source]¶ Set the lower and upper limitation of the output voltage
Parameters:
-
-
class
labtronyx.drivers.BK_Precision.Source.
d_XLN
(resource, **kwargs)[source]¶ Driver for BK Precision XLN Series DC Sources
-
clearProtection
()[source]¶ This command is used to clear the protection state. Before sending this command, please increase the upper limitation of OVP/OCP or reduce the output voltage/current
-
disableFrontPanel
()[source]¶ Disables the front panel of the instrument. To re-enable the front panel, call enableFrontPanel
-
getProtection
()[source]¶ Get the protection set points
Returns: dict with keys [‘Voltage’, ‘Current’, ‘Power’]
-
getProtectionState
()[source]¶ This command is used to query the executing state of the protection circuitry. If 1, this indicates the protection circuit has been triggered and must be cleared using clearProtection before normal operation can continue.
Returns: int
-
getTerminalCurrent
()[source]¶ Get the measured current from the terminals of the instrument
Returns: float
-
getTerminalPower
()[source]¶ Get the measured power from the terminals of the instrument
Returns: float
-
getTerminalVoltage
()[source]¶ Get the measured voltage from the terminals of the instrument
Returns: float
-
setCurrent
(current)[source]¶ Set the output current level
Parameters: current (float) – Current (in Amps)
-
setMaxCurrent
(current)[source]¶ Set the current limit
Parameters: current (float) – Current (in Amps)
-
setMaxVoltage
(voltage)[source]¶ Set the voltage limit
Parameters: voltage (float) – Voltage (in Volts)
-
setProtection
(voltage=None, current=None, power=None)[source]¶ Enable the protection circuitry. If any of the parameters is zero, that protection is disabled.
Parameters:
-
setSlewRate
(voltage, current)[source]¶ Set the voltage and current rise/fall time of the power supply. Units are seconds.
Parameters:
-
Chroma.Source¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Limitations¶
This driver does not include any of the device programming functionality, it is assumed that an automated program would be designed in a script that uses this driver.
-
class
labtronyx.drivers.Chroma.Source.
d_620XXP
(resource, **kwargs)[source]¶ Driver for Chroma 6200P Series DC Power Supplies
-
enableRemoteInhibit
()[source]¶ Enables the remote inhibit pin. This behaves as an external ON/OFF control.
-
getProtection
()[source]¶ Get the protection set points
Returns: dict with keys [‘Voltage’, ‘Current’, ‘Power’]
-
getTerminalCurrent
()[source]¶ Get the measured current from the terminals of the instrument
Returns: float
-
getTerminalPower
()[source]¶ Get the measured power from the terminals of the instrument
Returns: float
-
getTerminalVoltage
()[source]¶ Get the measured voltage from the terminals of the instrument
Returns: float
-
setCurrent
(current)[source]¶ Set the output current level in Amps
Parameters: current (float) – Current (in Amps)
-
setMaxCurrent
(current)[source]¶ Set the maximum output current
Parameters: current (float) – Current (in Amps)
-
setMaxVoltage
(voltage)[source]¶ Set the maximum output voltage
Parameters: voltage (float) – Voltage (in Volts)
-
setMeasurementAverage
(avg)[source]¶ Set the number of readings to average.
Parameters: avg (int) – Number of times to average (1, 2, 4 or 8)
-
setMeasurementAverageMethod
(avg)[source]¶ Set the number of readings to average.
Parameters: avg (str) – Method (‘FIX’ or ‘MOV’)
-
setMeasurementSpeed
(speed)[source]¶ Set the reading speed of the voltage/current sensor
Parameters: speed (int) – Samples per second (one of: 30, 60, 120, 240)
-
setProtection
(voltage=None, current=None, power=None)[source]¶ Enable the protection circuitry. If any of the parameters is zero, that protection is disabled.
Parameters:
-
setSlewRate
(voltage=None, current=None)[source]¶ Set the voltage and current rise/fall time of the power supply. Units are Volts per milliseconds.
Parameters:
-
Regatron.Source¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Connecting to the Instrument¶
The Regatron sources can be outfitted with Ethernet-to-USB adapters for use with the TopCon software. In order to connect to the source with an adapter installed, you must install the drivers so that the device appears as a local COM port to the operating system.
-
class
labtronyx.drivers.Regatron.Source.
d_TopCon
(resource, **kwargs)[source]¶ Driver for Regatron TopCon compatible Power Supplies
-
clearErrors
()[source]¶ Clear all errors and warnings. In a multi-unit system the errors and warnings of all slave units will be cleared as well.
-
getMode
()[source]¶ Returns the mode of the selected unit. Select a unit using selectUnit.
Possible values:
- ‘cv’: Constant Voltage
- ‘cc’: Constant Current
- ‘cp’: Constant Power
- ‘ulim’: Usense limit active
- ‘plim’: Psense limit active
- ‘cder’: Current derating active
Returns: str
-
getModuleCurrentRange
()[source]¶ Get the minimum and maximum current levels for the currently selected module.
Units: A
Returns: tuple (minimum, maximum)
-
getModulePowerRange
()[source]¶ Get the minimum and maximum power levels for the currently selected module.
Units: kW
Returns: tuple (minimum, maximum)
-
getModuleVoltageRange
()[source]¶ Get the minimum and maximum voltage levels for the currently selected module.
Units: V
Returns: tuple (minimum, maximum)
-
getState
()[source]¶ Returns the state of the selected unit. Select a unit using selectUnit.
Possible values with Voltage OFF:
- ‘POWERUP’
- ‘READY’
- ‘ERROR’
- ‘STOP’
Possible values with Voltage ON:
- ‘RUN’
- ‘WARN’
Returns: str
-
getSystemCurrentRange
()[source]¶ Get the minimum and maximum system current levels
Units: A
Returns: tuple (minimum, maximum)
-
getSystemPowerRange
()[source]¶ Get the minimum and maximum system power levels
Units: kW
Returns: tuple (minimum, maximum)
-
getSystemVoltageRange
()[source]¶ Get the minimum and maximum system voltage levels
Units: V
Returns: tuple (minimum, maximum)
-
getTerminalCurrent
()[source]¶ Get the actual system output current
Note:
The module select should be set to system using: `selectUnit(64)`
Returns: float
-
getTerminalPower
()[source]¶ Get the actual system output power
Note:
The module select should be set to system using: `selectUnit(64)`
Returns: float
-
getTerminalVoltage
()[source]¶ Get the actual system output voltage
Note:
The module select should be set to system using: `selectUnit(64)`
Returns: float
-
selectUnit
(index)[source]¶ Select a unit within the system for queries that require a unit to be selected.
Possible values: * 0: Master * 1-63: Slave * 64: System
The slave number (1 ... 63) required for the ModuleSelectIndex depends on the multi-unit operating mode and can be calculated with the values of the multi-unit ID selectors on the front panel according to the following formula:
+==============================+===================+ | Multi-unit operating mode | ModuleSelectIndex | +==============================+===================+ | Parallel or series operation | (8 * AH) + AL | +——————————+——————-+ | Multi-load operation | (16 * AH) + AL | +——————————+——————-+
Parameters: index (int) – ModuleSelectIndex
-
setCurrent
(neg, pos)[source]¶ Set the forward and reverse current flow limits.
Note:
The master unit must be selected using `selectUnit(0)`
Parameters:
-
Sorensen.Source¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
-
class
labtronyx.drivers.Sorensen.Source.
d_XFR
(resource, **kwargs)[source]¶ Driver for Sorensen XFR Series DC Power Supplies
-
getProtectionState
()[source]¶ This command is used to query the executing state of the protection circuitry. If one of the states has tripped, the protection state can be reset by turning the output off and then back on.
Returns: tuple (OVP, OCP)
-
getTerminalCurrent
()[source]¶ Get the measured current from the terminals of the instrument
Returns: float
-
getTerminalPower
()[source]¶ Get the measured power from the terminals of the instrument
Returns: float
-
getTerminalVoltage
()[source]¶ Get the measured voltage from the terminals of the instrument
Returns: float
-
setCurrent
(current)[source]¶ Set the output current level
Parameters: current (float) – Current (in Amps)
-
setProtection
(voltage=None, current=None)[source]¶ Enable the protection circuitry. If any of the parameters is zero, that protection is disabled.
Parameters:
-
setVoltage
(voltage)[source]¶ Set the output voltage level
Parameters: voltage (float) – Voltage (in Volts)
-
setVoltageSlewRate
(step, interval)[source]¶ Set the voltage slew rate as a function of change in the output voltage and a given time interval. The maximum slew rate is 1% rated voltage/150us. The slew rate is saved upon power off and restored at power on. Output ON/OFF and shutdown are not affected by the programmable slew rate. These functions have a slew rate of 1%/20ms.
The range of output voltage is 5% - 0.1% of rated voltage. The range of time interval is 1.5 s - 150 us. The negative slew rate is limited by the discharge rate of the output capacitors.
During current share, slaves operate with their default slew rate. The master operates at its programmed slew rate. Hence a programmable slew rate for the system is achieved. However, this slew rate is limited by the speed of the control loop. The slaves will return to their programmed slew rate when they exit current share slave operation.
The slew rate error increases as the slew rate increases.
Example:
Set a slew rate of 100V/10s. This slew rate is 1V/0.1s, which is within the acceptable range. >>> setVoltageSlewRate(1, 0.1)
Note:
Check both the voltage step and the interval to ensure that you get the required slew rate
Parameters: - step – voltage-step (units of Volts)
- current (float) – time interval (seconds)
-
TDI.Load¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Remote Interface¶
These loads feature a Ethernet connection that hosts a web-based interface from which you can control the load much like you would if you were sitting in front of it.
-
class
labtronyx.drivers.TDI.Load.
d_XBL
(resource, **kwargs)[source]¶ Driver for TDI XBL Series DC Electronic Loads
-
configurePulsing
(freq, duty, mode, base, peak)[source]¶ Mode can be one of:
- cc: Constant Current
- cv: Constant Voltage
- cw: Constant Power
- cr: Constant Resistance
-
configureSlewRate
(rate)[source]¶ Set the slew rate for a zero to full-scale transision.
Parameters: rate (float) – Rise and Fall time (in microseconds)
-
disableLocalControl
()[source]¶ Disable local control of the load. User will be unable to control load functions using the front panel.
-
setCurrent
(current)[source]¶ Sets the constant current mode’s current level
Parameters: current (float) – Current in Amps
-
setMaxCurrent
(current)[source]¶ Sets the maximum current the load will sink
Parameters: current (float) – Current in Amps
-
setMaxPower
(power)[source]¶ Sets the maximum power the load will allow
Parameters: power (float) – Power in Watts
-
setMaxVoltage
(voltage)[source]¶ Sets the maximum voltage the load will allow
Parameters: voltage (float) – Voltage in Volts
-
setPower
(power)[source]¶ Sets the constant power mode’s power level
Parameters: power (float) – Power in Watts
-
Tektronix.Oscilloscope¶
Code author: Kevin Kennedy <protonyx@users.noreply.github.com>
Supported Interfaces¶
- USB
- Ethernet (2000 Series requires the DPO2CONN Module)
Ethernet Interface¶
Tektronix oscilloscopes support Ethernet communication using the VXI extensions for VISA. The VISA driver should be used to detect the oscilloscope on the network, it is outside of the capabilities of the Labtronyx framework to discover VXI devices. For 2000 series oscilloscopes, the DPO2CONN Connectivity Module is required for ethernet communication.
5000, 7000 and 70000 Series Limitations¶
The oscilloscopes supported by this driver all run Windows and do not support the HARD COPY command to get screenshot data from the oscilloscope application. Screenshots can be saved to the oscilloscope hard drive and must be retrieved using other means.
-
class
labtronyx.drivers.Tektronix.Oscilloscope.
d_2XXX
(resource, **kwargs)[source]¶ Driver for Tektronix 2000 Series Oscilloscopes
-
getEnabledWaveforms
()[source]¶ Get a list of the enabled waveforms.
Example:
>> scope.getEnabledWaveforms() ['CH1', 'CH3']
Returns: list
-
saveScreenshot
(filename, format='PNG')[source]¶ Save a screenshot of the oscilloscope to a file on the local computer.
Parameters: - filename (str) – File to save
- format – File format (‘PNG’, ‘BMP’ or ‘TIFF’)
-
statusBusy
()[source]¶ Queries the scope to find out if it is busy
Returns: bool - True if Busy, False if not Busy
-
-
class
labtronyx.drivers.Tektronix.Oscilloscope.
d_5XXX7XXX
(resource, **kwargs)[source]¶ Driver for Tektronix 5000, 7000 and 70000 Series Oscilloscopes
-
exportWaveform
(**kwargs)[source]¶ Export the oscilloscope waveform to a .csv file.
Parameters: Filename (str) – Filename of output file Returns: bool - True if successful, False otherwise
-
getEnabledWaveforms
()[source]¶ Get a list of the enabled waveforms.
Example:
>> scope.getEnabledWaveforms() ['CH1', 'CH3']
Returns: list
-
getPackedWaveform
(ch)[source]¶ Get packed binary waveform data for a given channel
Parameters: ch (str) – Channel - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’] Returns: binary data
-
getProbeInformation
(**kwargs)[source]¶ Get Probe Data
Parameters: Waveform (str) – Channel - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’] Returns: dict Returned data has the following keys:
- ‘Type’ - Probe Type
- ‘Serial’ - Serial Number
- ‘Range’ - Attenuation Range
- ‘Resistance’ - Probe Resistance
- ‘Units’ - Measurement Units (Volts or Amps)
-
getSearchMarks
(**kwargs)[source]¶ Get a list of all mark locations. Manually iterates through all marks on the oscilloscope and gets the location.
Warning
Depending on the number of marks, this function can take some time to complete
Parameters: Search (int between 1-8) – Search slot number Returns: list of mark times (float)
-
getWaveform
()[source]¶ Refreshes the raw waveform data from the oscilloscope.
Returns: bool - True if successful, False otherwise
-
saveScreenshot
(**kwargs)[source]¶ Save a screenshot of the oscilloscope display onto the oscilloscope.
Parameters: Returns: bool - True if successful, False otherwise
-
setAcquisitionSetup
(**kwargs)[source]¶ Set Acquisition Modes
Note
Not all features are available on all models
Parameters: - State (str) – Run state - [‘SINGLE’, ‘OFF’, ‘ON’, ‘RUN’, ‘STOP’]
- FastAcq (str) – Fast Acquisition Mode - [‘ON’, ‘OFF’]
- MagniVu (str) – MagniVu Mode - [‘ON’, ‘OFF’]
- Mode (str) – Operating Mode - [‘Sample’, ‘PeakDetect’, ‘HighResolution’, ‘Average’, ‘WaveformDB’, ‘Envelope’]
- Number (int) – Number of samples when Mode is ‘Average’ or ‘Envelope’
- RollMode (str) – Horizontal Roll Mode - [‘AUTO’, ‘ON’, ‘OFF’]
- SamplingMode (str) – Sampling Mode - [‘RealTime’, ‘Equivalent’, ‘Interpolate’]
Operating Modes:
'Sample' specifies that the displayed data point value is the first sampled value that is taken during the acquisition interval. In sample mode, all waveform data has 8 bits of precision. You can request 16 bit data with a CURVe query but the lower-order 8 bits of data will be zero. SAMple is the default mode. 'PeakDetect' specifies the display of high-low range of the samples taken from a single waveform acquisition. The high-low range is displayed as a vertical column that extends from the highest to the lowest value sampled during the acquisition interval. PEAKdetect mode can reveal the presence of aliasing or narrow spikes. 'HighResolution' specifies Hi Res mode where the displayed data point value is the average of all the samples taken during the acquisition interval. This is a form of averaging, where the average comes from a single waveform acquisition. The number of samples taken during the acquisition interval determines the number of data values that compose the average. 'Average' specifies averaging mode, in which the resulting waveform shows an average of SAMple data points from several separate waveform acquisitions. The instrument processes the number of waveforms you specify into the acquired waveform, creating a running exponential average of the input signal. The number of waveform acquisitions that go into making up the average waveform is set or queried using the ACQuire:NUMEnv command. 'WaveformDB' (Waveform Database) mode acquires and displays a waveform pixmap. A pixmap is the accumulation of one or more acquisitions. 'Envelope' specifies envelope mode, where the resulting waveform shows the PeakDetect range of data points from several separate waveform acquisitions. The number of waveform acquisitions that go into making up the envelope waveform is set or queried using the ACQuire:NUMEnv command. The instrument acquires data after each trigger event using Sample mode; it then determines the pix map location of each sample point and accumulates it with stored data from previous acquisitions. A Pix map is a two dimensional array. The value at each point in the array is a counter that reflects the hit intensity. Infinite and noninfinite persist display modes affect how pix maps are accumulated. Zoom, Math, FastAcq, FastFrame, XY, Roll, and Interpolated Time (IT) Sampling Mode are conflicting features to WFMDB acqMode. Turning on one of them generally turns the other one off. Selection of some standard masks (for example, eye masks, which require option MTM) changes the acquisition mode to WFMDB.
-
setCursorSetup
(**kwargs)[source]¶ Set cursor configuration.
Parameters: - Type (str) – Cursor Type - [‘HBARS’, ‘VBARS’, ‘SCREEN’, ‘WAVEFORM’]
- Display (str) – Display Cursors - [‘ON’, ‘OFF’]
- Mode (str) – Cursor Mode - [‘Track’, ‘Independent’]
- LineStyle (str) – Cursor Line Style - [‘DASHED’, ‘SDASHED’, ‘SOLID’]
- Source1 (str) – Waveform for Source1 - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’, ‘MATH1’, ‘MATH2’, ‘MATH3’, ‘MATH4’, ‘REF1’, ‘REF2’, ‘REF3’, ‘REF4’]
- Source2 (str) – Waveform for Source2 - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’, ‘MATH1’, ‘MATH2’, ‘MATH3’, ‘MATH4’, ‘REF1’, ‘REF2’, ‘REF3’, ‘REF4’]
- Pos1 (int or float) – Pos1 in ‘HBARS’, ‘VBARS’ or ‘WAVEFORM’ Mode
- Pos2 (int or float) – Pos2 in ‘HBARS’, ‘VBARS’ or ‘WAVEFORM’ Mode
- X1 (int or float) – X1 in ‘SCREEN’ Mode
- X2 (int or float) – X2 in ‘SCREEN’ Mode
- Y1 (int or float) – Y1 in ‘SCREEN’ Mode
- Y2 (int or float) – Y2 in ‘SCREEN’ Mode
- Style (str) – Cursor Style in ‘SCREEN’ Mode - [‘LINE_X’, ‘LINES’, ‘X’]
Returns: bool - True if successful, False otherwise
-
setSearchSetup
(**kwargs)[source]¶ Set Search configuration
Parameters: Returns: bool - True if successful, False otherwise
Note
Only ‘TRANSITION’ Search Type is supported right now. The full range of possible Search Types are: [‘EDGE’, ‘RUNT’, ‘TRANSITION’, ‘PATTERN’, ‘GLITCH’, ‘SETHOLD’, ‘UNDEFINED’, WIDTH’, ‘TIMEOUT’, ‘WINDOW’, ‘STATE’, ‘DDRREAD’, ‘DDRWRITE’, ‘DDRREADWRITE’]
Parameters for ‘TRANSITION’ Search Type:
- ‘Source’ (str) - Channel source to search - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’, ‘REF1’, ‘REF2’, ‘REF3’, ‘REF4’, ‘MATH1’, ‘MATH2’, ‘MATH3’, ‘MATH4’]
- ‘Delta’ (float) - Time delta to limit matches
- ‘HighThreshold’ (float) - High Threshold level
- ‘LowThreshold’ (float) - Low Threshold level
- ‘Slope’ (str) - Polarity setting for mark placement - [‘EITHER’, ‘NEGATIVE’, ‘POSITIVE’]
- ‘Transition’ (str) - Transition Trigger Condition - [‘FASTERTHAN’, ‘SLOWERTHAN’]
-
setTriggerSetup
(**kwargs)[source]¶ Set Trigger Configuration
Note
Only a small subset of the trigger types are supported right now.
Parameters:
-
setVerticalSetup
(**kwargs)[source]¶ Set Vertical Configuration
Parameters: - Waveform (str) – Channel - [‘CH1’, ‘CH2’, ‘CH3’, ‘CH4’, ‘REF1’, ‘REF2’, ‘REF3’, ‘REF4’, ‘MATH1’, ‘MATH2’, ‘MATH3’, ‘MATH4’]
- Display (str) – Display Channel - [‘ON’, ‘OFF’]
- Label (str) – Channel Label
- Position (float) – Vertical Position of channel - divisions above or below center
- Scale (float) – Channel Vertical scale
- Coupling (str) – Input Attenuator Coupling Setting - [‘AC’, ‘DC’, ‘DCREJECT’, ‘GND’]
- Deskew (float) – Channel Deskew time (seconds)
- Bandwidth (str) – Low-Pass Bandwidth Limit Filter (Megahertz) - [‘FIVE’, ‘FULL’, ‘TWENTY’, ‘ONEFIFTY’, ‘TWOFIFTY’]
-
statusBusy
()[source]¶ Queries the scope to find out if it is busy
Returns: bool - True if Busy, False if not Busy
-
waitUntilReady
(interval=1.0, timeout=10.0)[source]¶ Poll the oscilloscope until ready or until timeout seconds has passed
Parameters: Returns: bool - True if instrument becomes ready, False if timeout occurs
-
waveformExport
(**kwargs)[source]¶ Alias for
exportWaveform()
-
Interfaces¶
Serial¶
The Serial interface is a wrapper for the pyserial library.
-
class
labtronyx.interfaces.i_Serial.
i_Serial
(manager, **kwargs)[source]¶ Serial Interface
Wraps PySerial.
-
class
labtronyx.interfaces.i_Serial.
r_Serial
(manager, resID, **kwargs)[source]¶ Serial Resource Base class.
Wraps PySerial
Resource API is compatible with VISA resources, so any driver written for a VISA resource should also work for serial resources in the case that a VISA library is not available.
-
close
()[source]¶ Close the resource. If a driver is loaded, that driver is also closed
Returns: True if successful, False otherwise
-
configure
(**kwargs)[source]¶ Configure Serial port parameters for the resource.
Parameters: - timeout (int) – Command timeout
- write_termination (str) – Write termination
- baud_rate (int) – Serial Baudrate. Default 9600
- data_bits (int) – Number of bits per frame. Default 8.
- parity (str) – Data frame parity (‘N’one, ‘E’ven, ‘O’dd, ‘M’ark or ‘S’pace)
- stop_bits (int) – Number of stop bits. Default 1
-
getProperties
()[source]¶ Get the property dictionary for the Serial resource.
Return type: dict[str:object]
-
inWaiting
()[source]¶ Return the number of bytes in the receive buffer
Returns: int Raises: InterfaceError
-
open
()[source]¶ Open the resource and prepare to receive commands. If a driver is loaded, the driver will also be opened
Returns: True if successful, False otherwise Raises: ResourceUnavailable
-
query
(data, delay=None)[source]¶ Retreive ASCII-encoded data from the device given a prompt.
A combination of write(data) and read()
Parameters: Returns: str
Raises: ResourceNotOpen
Raises: InterfaceTimeout
Raises: InterfaceError
-
read
(termination=None)[source]¶ Read string data from the instrument.
Reading stops when the device stops sending, or the termination characters sequence was detected.
All line-ending characters are stripped from the end of the string.
Raises: ResourceNotOpen
-
read_raw
(size=None)[source]¶ Read Binary-encoded data from the instrument.
No termination characters are stripped.
Parameters: size (int) – Number of bytes to read Returns: bytes Raises: ResourceNotOpen
-
VISA¶
VISA Interface module for Labtronyx
codeauthor: | Kevin Kennedy |
---|
-
class
labtronyx.interfaces.i_VISA.
i_VISA
(manager, **kwargs)[source]¶ VISA Controller
Wraps PyVISA. Requires a VISA driver to be installed on the system.
-
enumerate
()[source]¶ Identify all devices known to the VISA driver and create resource objects for valid resources
-
open
()[source]¶ Initialize the VISA Interface. Instantiates a VISA Resource Manager.
Returns: True if successful, False if an error occurred
-
-
class
labtronyx.interfaces.i_VISA.
r_VISA
(manager, resID, **kwargs)[source]¶ VISA Resource Base class.
Wraps PyVISA Resource Class
All VISA compliant devices will adhere to the IEEE 488.2 standard for responses to the *IDN? query. The expected format is: <Manufacturer>,<Model>,<Serial>,<Firmware>
BK Precision has a non-standard format for some of their instruments: <Model>,<Firmware>,<Serial>
Drivers derived from a VISA resource do not need to provide values for the following property attributes as they are derived from the identification string:
- deviceVendor
- deviceModel
- deviceSerial
- deviceFirmware
-
close
()[source]¶ Close the resource. If a driver is loaded, that driver is also closed
Returns: True if successful, False otherwise
-
configure
(**kwargs)[source]¶ Configure resource parameters to alter transmission characteristics or data interpretation
All VISA Resources
Parameters: Serial Resources
Parameters: - baud_rate (int) – Serial Baudrate. Default 9600
- data_bits (int) – Number of bits per frame. Default 8.
- parity (str) – Data frame parity (None, Even, Odd, Mark or Space)
- stop_bits (int) – Number of stop bits. Default 1
- break_length (int) – Duration of the break signal in milliseconds
- discard_null (bool) – Discard NUL characters
- send_end (bool) – Assert END during the transfer of the last byte of data in the buffer
Resource type dependent
Parameters:
-
getIdentity
(section=None)[source]¶ Get the comma-delimited identity string returned from *IDN? command on resource enumeration
Parameters: section (int) – Section of comma-split identity Return type: str
-
getProperties
()[source]¶ Get the property dictionary for the VISA resource.
Return type: dict[str:object]
-
getStatusByte
()[source]¶ Read the Status Byte Register (STB). Interpretation of the status byte varies by instrument
Returns:
-
identify
()[source]¶ Query the resource to find out what instrument it is. Uses the standard SCPI query string *IDN?. Will attempt to load a driver using the information returned.
-
inWaiting
()[source]¶ Return the number of bytes in the receive buffer for a Serial VISA Instrument. All other VISA instrument types will return 0.
Returns: int
-
lineBreak
(length)[source]¶ Suspends character transmission and places the transmission line in a break state
Parameters: length (int) – Length of time to break
-
loadDriver
(driverName=None, force=False)[source]¶ Load a Driver.
VISA supports enumeration and will thus search for a compatible driver. A driverName can be specified to load a specific driver, even if it may not be compatible with this resource. If more than one compatible driver is found, no driver will be loaded.
On startup, the resource will attempt to load a valid driver automatically. This function only needs to be called to override the default driver.
unloadDriver()
must be called before loading a new driver for a resource.Parameters: driverName (str) – Driver name to load Returns: True if successful, False otherwise
-
open
()[source]¶ Open the resource and prepare to receive commands. If a driver is loaded, the driver will also be opened
Returns: True if successful, False otherwise Raises: labtronyx.ResourceUnavailable
-
query
(data, delay=None)[source]¶ Retrieve ASCII-encoded data from the device given a prompt.
A combination of write(data) and read()
Parameters: Returns: str
Raises: labtronyx.ResourceNotOpen
Raises: labtronyx.InterfaceTimeout
Raises: labtronyx.InterfaceError
-
read
(termination=None, encoding=None)[source]¶ Read ASCII-formatted data from the instrument.
Reading stops when the device stops sending, or the termination characters sequence was detected. All line-ending characters are stripped from the end of the string.
Parameters: Returns: str
Raises: labtronyx.ResourceNotOpen
Raises: labtronyx.InterfaceTimeout
Raises: labtronyx.InterfaceError
-
read_raw
(size=None)[source]¶ Read Binary-encoded data directly from the instrument.
Parameters: size (int) – Number of bytes to read Raises: labtronyx.ResourceNotOpen Raises: labtronyx.InterfaceTimeout Raises: labtronyx.InterfaceError
-
reset
()[source]¶ Reset the instrument. Behavior varies by instrument, typically this will reset the instrument to factory default settings.
-
trigger
()[source]¶ Trigger the instrument using the common trigger command *TRG. Behavior varies by instrument
Developer Guide¶
Introduction¶
This developer guide details all of the plugin types in the Labtronyx framework, their function and basic requirements. Developers are encouraged to read the Architecture section to gain an understanding of how the framework is structured before developing any plugins.
Contributing¶
This project is a work in progress. Due to the nature of lab instruments, drivers must be developed to fully utilize the features unique to each device. Therefore, this framework cannot possibly hope to have a comprehensive collection of drivers for every device on the market. This documentation includes everything a developer would need to write drivers for new interfaces, devices and instruments.
Developers wishing to contribute to the project can fork the project on GitHub and create pull requests.
Reporting Bugs¶
All bugs should be reported to the GitHub issue tracker.
Style Guidelines¶
See Python PEP 8
Exceptions to those documents are listed in the following sections.
Naming Variables, Functions and Classes¶
Classes should be named using CamelCase with the first letter capitalized.
Functions should be named using camelCase with the first letter not capitalized.
Variables as class attributes should use camelCase, but variables within a function do not have to follow any particular convention.
Constants should be ALL_CAPS with underscores for spaces
Architecture¶
The InstrumentManager class uses a slightly modified Presentation-Abstraction-Control architectural pattern, which separates the low-level system calls from the high-level command set of each device. By using this design approach, there is a clear separation of concerns that allows the framework to be highly modular.
The core of the framework is the InstrumentManager
class, which is responsible for scanning all provided
directories for compatible plugins. Each Interface plugin found will be instantiated, which in turn will query the
system for any available resources.
Interfaces¶
Getting Started¶
Interfaces are responsible for discovering and instantiating resource objects. They may also handle low-level operating system interactions. This may include calls to hardware via driver stacks, or calls to other Python libraries. Resources do not have an inherent dependency on the interface that instantiates it.
All interfaces are subclasses of labtronyx.InterfaceBase
:
import labtronyx
class INTERFACE_CLASS_NAME(labtronyx.InterfaceBase):
pass
Required Attributes¶
Interfaces require some attributes to be defined
- interfaceName - str that names the interface.
- enumerable - True if the interface supports resource enumeration. If False, the interface should implement the
openResource()
method to manually open a resource given a string identifier.
-
class
labtronyx.bases.interface.
InterfaceBase
(manager, **kwargs)[source]¶ Interface Base Class
Parameters: - manager (labtronyx.manager.InstrumentManager) – InstrumentManager instance
- logger (logging.Logger) – Logger instance
-
close
()[source]¶ Destroy all resource objects owned by the interface.
May be extended by subclasses if any additional work is necessary to clean-up interface operations.
Returns: True if successful, False otherwise Return type: bool
-
enumerate
()[source]¶ Refreshes the resource list by enumerating all of the available devices on the interface.
-
getResource
(resID)[source]¶ Get a resource that may not be previously known to the interface. Attempts to open the resource using the given identifier. A ResourceUnavailable exception will be raised if the resource could not be located or opened.
Parameters: resID (str) – Resource Identifier Returns: object Raises: ResourceUnavailable
-
open
()[source]¶ Make any system driver calls necessary to initialize communication. This method must not raise any exceptions.
This function is meant to be implemented by subclasses.
Returns: True if ready, False if error occurred Return type: bool
-
refresh
()[source]¶ Macro for interfaces that support enumeration. Calls enumerate then prune to get an updated list of resources available to the interface
-
resources
¶ Dictionary of resource objects by UUID
Return type: dict{str: labtronyx.bases.resource.ResourceBase}
Resources¶
All resources must implement the Resource API:
Getting started¶
All resources are subclasses of the labtronyx.ResourceBase
class. Creating a resource is simple:
import labtronyx
class RESOURCE_CLASS_NAME(labtronyx.ResourceBase):
pass
Attributes¶
Resources have some attributes that should be defined:
- interfaceName - str that names the interface that owns the resource. Should match the interfaceName attribute of the corresponding interface.
Errors¶
Labtronyx has a number of build-in exception types that can be raised from resources. For more information about these exceptions and the proper times to raise them, see Exceptions
Usage Model¶
When resources are created, they should default to the closed state. This is to prevent any locking issues if multiple instances of Labtronyx are open. Resources should typically only be open if they are actively in use.
When a driver is loaded, the resource object acts as a proxy to access the driver methods. All driver functions are accessed directly from the resource object as if they were a single object. Some things to note:
- If there is a naming conflict between a method in the resource and a method in the driver, the resource method will take priority
- Driver functions are inaccessible and cannot be called if the resource is closed
Note
In order to support proper operation using Remote Resources and Instruments, some limitations should be imposed to ensure maximum compatibility. All methods within a resource or driver must return serializable data. Serializable data types include:
- str
- unicode
- int
- long
- float
- bool
- list
- tuple
- dict
- None
If a method returns an object that is not serializable, an exception will be passed back to the remote host. If the method returns a non-serializable data type, the method should be prefixed with an underscore (‘_’) to mark it as a protected function that cannot be accessed remotely.
Resources may implement more functions than just those which are defined in the API below, see the interface and resource class documentation to learn more.
-
class
labtronyx.bases.resource.
ResourceBase
(manager, resID, **kwargs)[source]¶ Resource Base Class. Acts as a proxy for driver if one is loaded.
Parameters: - manager (labtronyx.InstrumentManager) – InstrumentManager instance
- interface (labtronyx.bases.interface.InterfaceBase) – Reference to the interface instance
- resID (str) – Resource Identifier
- logger (logging.Logger) – Logger instance
-
getProperties
()[source]¶ Get the property dictionary for the resource. If a driver is loaded, the driver properties will be merged and returned as well
Return type: dict[str:object]
-
loadDriver
(driverName, force=False)[source]¶ Load a Driver for a resource. A driver name can be specified, even if it may not be compatible with this resource. Existing driver is no unloaded unless the force parameter is set to True.
Parameters: - driverName (str) – Module name of the desired Model
- force – Force load driver by unloading existing driver
Returns: True if successful, False otherwise
Raises: KeyError if driver class not found
-
open
()[source]¶ Open the resource. If a driver is loaded, the driver open method will also be called
Returns: True if open was successful, False otherwise Raises: ResourceUnavailable
-
unloadDriver
()[source]¶ If a driver is currently loaded for the resource, unload it. This will close the resource as well.
Returns: True if successful, False otherwise
-
driver
¶ Return type: labtronyx.bases.driver.DriverBase
Drivers¶
General information about drivers can be found at Resources
Getting Started¶
All Drivers extend labtronyx.DriverBase
:
import labtronyx
class DRIVER_CLASS_NAME(labtronyx.DriverBase):
pass
Required Attributes¶
Drivers require some attributes to be defined in order to specify which resource types and interfaces they are compatible with.
- deviceType - str to describe the type or function of the device
- compatibleInterfaces - list of interface names that the driver is compatible with e.g. [‘Serial’, ‘VISA’]
- compatibleInstruments - dict of vendors and models that the driver is compatible with. The keys to the dictionary are vendors and the values are a list of models e.g. {‘Agilent’: [‘ACME123’]}
Properties¶
Like Resources, Drivers can provide auxiliary information about a physical device by returning a dictionary of
key-value pairs from the method getProperties()
. Properties can be useful for application and script
development by enabling or disabling features according to data contained in the properties. Driver properties can
relate information about a device or instrument that require specific commands such as:
- Serial number
- Model number
- Firmware revision
- Product Codes
- Number of channels
- Operating Frequencies
- Command Set Revision
Warning:
The :func:`getProperties` method of the driver may be called when a resource is not open, so any commands that
require the resource to be open should be wrapped with :func:`isOpen` to prevent exceptions from being raised.
It is recommended that drivers should provide these properties to assist scripts or applications to locate a resource:
Key | Default Value | Examples |
---|---|---|
deviceVendor | ‘Generic’ | ‘Tektronix’, ‘Agilent Technologies’ |
deviceModel | ‘Device’ | ‘DPO2024’, ‘2831E’ |
deviceSerial | ‘Unknown’ | ‘12345’ |
deviceFirmware | ‘Unknown’ | ‘1.0.0’ |
If serial number and firmware information has be retrieved from the device, it should be done during the open()
method.
Usage Model¶
Driver objects are instantiated and stored in the resource object. When a driver is loaded, all methods are dynamically loaded into the resource object and can be accessed by calling the method from the resource. To prevent exceptions, Driver methods are inaccessible unless the resource is open by a call to the resource method open.
In order to maintain functional abstraction, Drivers should limit dependencies on outside libraries and avoid making system driver calls. All code contained in drivers should deal with the specific instrument’s command set and use resource API calls to communicate with the instrument.
If drivers need to support more than one interface, be sure to only use resource methods that are common to all interfaces.
Note
In order to support proper operation using Remote Resources and Instruments, some limitations should be imposed to ensure maximum compatibility. All methods within a resource or driver must return serializable data. Serializable data types include:
- str
- unicode
- int
- long
- float
- bool
- list
- tuple
- dict
- None
If a method returns an object that is not serializable, an exception will be passed back to the remote host. If the method returns a non-serializable data type, the method should be prefixed with an underscore (‘_’) to mark it as a protected function that cannot be accessed remotely.
-
class
labtronyx.bases.driver.
DriverBase
(resource, **kwargs)[source]¶ Driver Base Class
Parameters: - resource (labtronyx.bases.resource.ResourceBase) – Resource instance
- logger (logging.Logger) – Logger instance