-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/keithley2600 daq1d #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
astroloba
wants to merge
6
commits into
PyMoDAQ:main
Choose a base branch
from
astroloba:feature/keithley2600_daq1d
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c38d5e
Add Keithley 2600 sourcemeter driver
astroloba 6fa8a1c
Add pyusb to plugin requirements
astroloba 3d01fe1
Add Keithley2600 DAQ1D viewer
astroloba 7ad1ab8
Update contributors
astroloba c1760aa
Update README with Keithley 2600
astroloba 2ff30df
Update README
astroloba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/pymodaq_plugins_keithley/daq_viewer_plugins/plugins_1D/daq_1Dviewer_Keithley2600.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import numpy as np | ||
|
|
||
| from pymodaq_utils.utils import ThreadCommand | ||
| from pymodaq_data.data import DataToExport, Axis, Q_ | ||
| from pymodaq_gui.parameter import Parameter | ||
|
|
||
| from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main | ||
| from pymodaq.utils.data import DataFromPlugins | ||
|
|
||
| import pyvisa | ||
| from pymodaq_plugins_keithley.hardware.keithley2600.keithley2600_VISADriver import Keithley2600VISADriver | ||
|
|
||
|
|
||
| # Helper functions | ||
| def _get_VISA_resources(pyvisa_backend="@py"): | ||
|
|
||
| # Get list of VISA resources | ||
| resourceman = pyvisa.ResourceManager(pyvisa_backend) | ||
| resources = list(resourceman.list_resources()) | ||
|
|
||
| # Move the first USB connection to the top | ||
| for i, val in enumerate(resources): | ||
| if val.startswith("USB0"): | ||
| resources.remove(val) | ||
| resources.insert(0, val) | ||
| break | ||
|
|
||
| # Return list of resources | ||
| return resources | ||
|
|
||
|
|
||
| def _build_param(name, title, type, value, limits=None, unit=None, **kwargs): | ||
| params = {} | ||
| params["name"] = name | ||
| params["title"] = title | ||
| params["type"] = type | ||
| params["value"] = value | ||
| if limits is not None: | ||
| params["limits"] = limits | ||
| if unit is not None: | ||
| params["suffix"] = unit | ||
| params["siPrefix"] = True | ||
| for argn, argv in kwargs.items(): | ||
| params[argn] = argv | ||
| return params | ||
|
|
||
|
|
||
| def _emit_xy_data(self, x, y): | ||
| x_axis = Axis(data=x, label="Voltage", units="V", index=0) | ||
| self.dte_signal.emit(DataToExport("Keithley2600", | ||
| data=[DataFromPlugins(name="Keithley2600", | ||
| data=[y], | ||
| units="A", | ||
| dim="Data1D", labels=["I-V"], | ||
| axes=[x_axis])])) | ||
|
|
||
|
|
||
| class DAQ_1DViewer_Keithley2600(DAQ_Viewer_base): | ||
| """ Instrument plugin class for a Keithley 2600 sourcemeter. | ||
|
|
||
| Attributes: | ||
| ----------- | ||
| controller: object | ||
| The particular object that allow the communication with the hardware, in general a python wrapper around the | ||
| hardware library. | ||
|
|
||
| # TODO add your particular attributes here if any | ||
|
|
||
| """ | ||
| params = comon_parameters+[ | ||
| _build_param("resource_name", "VISA resource", "list", "", limits=_get_VISA_resources()), | ||
| _build_param("channel", "Channel", "str", "A"), | ||
| _build_param("startv", "Sweep start voltage", "float", 0, unit="V"), | ||
| _build_param("stopv", "Sweep stop voltage", "float", 1, unit="V"), | ||
| _build_param("stime", "Sweep stabilization time", "float", 1e-3, unit="s"), | ||
| _build_param("npoints", "Sweep points", "int", 101), | ||
| _build_param("ilimit", "Current limit", "float", 0.1, unit="A"), | ||
| _build_param("autorange", "Autorange", "bool", True) | ||
| ] | ||
|
|
||
|
|
||
| def ini_attributes(self): | ||
| # Type declaration of the controller | ||
| self.controller: Keithley2600VISADriver = None | ||
|
|
||
|
|
||
| def commit_settings(self, param: Parameter): | ||
| """Apply the consequences of a change of value in the detector settings | ||
|
|
||
| Parameters | ||
| ---------- | ||
| param: Parameter | ||
| A given parameter (within detector_settings) whose value has been changed by the user | ||
| """ | ||
| # Dispatch arguments | ||
| name = param.name() | ||
| val = param.value() | ||
| unit = param.opts.get("suffix") | ||
| qty = Q_(val, unit) | ||
|
|
||
| # Current limit | ||
| if name == "ilimit": | ||
| self.controller.channel.current_limit = qty.to("A") | ||
|
|
||
|
|
||
| def ini_detector(self, controller=None): | ||
| """Detector communication initialization | ||
|
|
||
| Parameters | ||
| ---------- | ||
| controller: (object) | ||
| custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller | ||
| (Master case) | ||
|
|
||
| Returns | ||
| ------- | ||
| info: str | ||
| initialized: bool | ||
| False if initialization failed otherwise True | ||
| """ | ||
|
|
||
| # If stand-alone device, initialize controller object | ||
| if self.is_master: | ||
|
|
||
| # Get initialization parameters | ||
| resource_name = self.settings["resource_name"] | ||
| channel = self.settings["channel"] | ||
| autorange = self.settings["autorange"] | ||
|
|
||
| # Initialize device | ||
| self.controller = Keithley2600VISADriver(resource_name, | ||
| channel_name=channel, | ||
| autorange=autorange) | ||
| initialized = True | ||
|
|
||
| # If slave device, retrieve controller object | ||
| else: | ||
| self.controller = controller | ||
| initialized = True | ||
|
|
||
| # Initialize viewers pannel with the future type of data | ||
| mock_x = np.linspace(0, 1, 101) | ||
| mock_y = np.zeros(101) | ||
| _emit_xy_data(self, mock_x, mock_y) | ||
|
|
||
| # Initialization successful | ||
| info = "Keithey 2600 initialization finished." | ||
| return info, initialized | ||
|
|
||
|
|
||
| def close(self): | ||
| """Terminate the communication protocol""" | ||
| if self.is_master: | ||
| self.controller.close() | ||
| self.controller = None | ||
|
|
||
|
|
||
| def grab_data(self, Naverage=1, **kwargs): | ||
| """Start a grab from the detector | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Naverage: int | ||
| Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to | ||
| True in class preamble and you should code this implementation) | ||
| kwargs: dict | ||
| others optionals arguments | ||
| """ | ||
|
|
||
| # Retrieve parameters | ||
| startv = self.settings["startv"] | ||
| stopv = self.settings["stopv"] | ||
| stime = self.settings["stime"] | ||
| npoints = self.settings["npoints"] | ||
|
|
||
| # Sweep and retrieve x and y axes | ||
| x, y = self.controller.channel.sweepV_measureI(startv, stopv, stime, npoints) | ||
|
|
||
| # Emit data to PyMoDAQ | ||
| _emit_xy_data(self, x, y) | ||
|
|
||
|
|
||
| def stop(self): | ||
| """Stop the current grab hardware wise if necessary""" | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main(__file__) |
179 changes: 179 additions & 0 deletions
179
src/pymodaq_plugins_keithley/hardware/keithley2600/keithley2600_VISADriver.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| import numpy as np | ||
| import pyvisa | ||
| from pymodaq_plugins_keithley import config | ||
| from pymodaq.utils.logger import set_logger, get_module_name | ||
| logger = set_logger(get_module_name(__file__)) | ||
|
|
||
|
|
||
| def table_to_np(table): | ||
| """Convert sequence of ASCII-encoded, comma-separated values to NumPy array.""" | ||
| split = table.split(", ") | ||
| floats = [float(x) for x in split] | ||
| array = np.array(floats) | ||
| return array | ||
|
|
||
|
|
||
| class Keithley2600VISADriver: | ||
| """VISA class driver for Keithley 2600 sourcemeters. | ||
|
|
||
| Communication with the device is performed in text mode (TSP). Detailed instructions can be found in: | ||
| https://download.tek.com/manual/2600BS-901-01_C_Aug_2016_2.pdf | ||
| """ | ||
|
|
||
|
|
||
| def __init__(self, resource_name, channel_name="A", autorange=True, pyvisa_backend="@py"): | ||
| """Initialize KeithleyVISADriver class. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| resource_name: str | ||
| VISA resource name. (ex: "USB0::1510::9782::1234567::0::INSTR") | ||
| channel_name: str, optional | ||
| Channel name. (default: "A") | ||
| autorange: bool, optional | ||
| Enable I and V autorange. (default: True) | ||
| pyvisa_backend: str, optional | ||
| pyvisa backend identifier or path to the visa backend dll (ref. to pyvisa) | ||
| (default: "@py") | ||
| """ | ||
|
|
||
| # Establish connection | ||
| resourceman = pyvisa.ResourceManager(pyvisa_backend) | ||
| self._instr = resourceman.open_resource(resource_name) | ||
|
|
||
| # Create channel | ||
| self.channel = Keithley2600Channel(self, channel_name, autorange) | ||
|
|
||
|
|
||
| def close(self): | ||
| """Terminate connection with the instrument.""" | ||
| self._instr.close() | ||
| self._instr = None | ||
|
|
||
|
|
||
| def _write(self, cmd): | ||
| """Convenience methode to send a TSP command to the device.""" | ||
| self._instr.write(cmd) | ||
|
|
||
|
|
||
| def _read(self): | ||
| """Convenience methode to get response from the device.""" | ||
| return self._instr.read() | ||
|
|
||
|
|
||
| class Keithley2600Channel: | ||
| """Class for handling a single channel on a Keithley 2600 sourcemeter.""" | ||
|
|
||
| def __init__(self, parent, channel, autorange): | ||
| """Initialize class. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| parent: Keithley2600 | ||
| Parent class. | ||
| channel: str | ||
| Identifier of the channel. (ex: "A") | ||
| autorange: bool | ||
| Enable I and V autorange. | ||
| """ | ||
|
|
||
| # Initialize variables | ||
| self.channel = channel | ||
| self.smu = f"smu{channel.lower()}" | ||
| self.parent = parent | ||
|
|
||
| # Set autorange if enabled | ||
| if autorange: | ||
| self.autorange() | ||
|
|
||
|
|
||
| def _write(self, cmd): | ||
| """Convenience methode to send a TSP command to the device.""" | ||
| self.parent._write(cmd) | ||
|
|
||
|
|
||
| def _read(self): | ||
| """Convenience methode to get response from the device.""" | ||
| return self.parent._read() | ||
|
|
||
|
|
||
| @property | ||
| def current_limit(self): | ||
| """Get current limit [A] of the channel. | ||
|
|
||
| Returns | ||
| ------- | ||
| current_limit: float | ||
| Current limit [A] of the selected channel. | ||
| """ | ||
| self._write(f"print({self.smu}.source.limiti)") | ||
| limit = self._read() | ||
| return float(limit) | ||
|
|
||
|
|
||
| @current_limit.setter | ||
| def current_limit(self, limit): | ||
| """Set current limit [A] of the channel. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| limit: float | ||
| Current limit [A] to set. | ||
| """ | ||
| limit = f"{limit:.6e}" | ||
| self._write(f"{self.smu}.source.limiti = {limit}") | ||
|
|
||
|
|
||
| def autorange(self): | ||
| """Set current and voltage measurements to autorange.""" | ||
| self._write(f"{self.smu}.measure.autorangei = {self.smu}.AUTORANGE_ON") | ||
| self._write(f"{self.smu}.measure.autorangev = {self.smu}.AUTORANGE_ON") | ||
|
|
||
|
|
||
| def sweepV_measureI(self, startv=0, stopv=1, stime=1e-3, npoints=100): | ||
| """Perform a linear voltage sweep and measure current. This version is called with arguments. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| startv: float | ||
| Starting voltage [V] of the sweep. | ||
| stopv: float | ||
| Stopping voltage [V] of the sweep. | ||
| stime: float | ||
| Stabilization time [s]. The device waits for this amount of time at each measurement | ||
| step, once voltage has reached the setpoint. In practice, actual step time is longer | ||
| than this value because of the time needed to reach the voltage setpoint. | ||
| npoints: int | ||
| Number of points to be acquired. Must be >2. | ||
|
|
||
| Returns | ||
| ------- | ||
| x: np.ndarray | ||
| Voltage values [V]. | ||
| y: np.ndarray | ||
| Current (intensity) values [A]. | ||
| """ | ||
|
|
||
| # Convert channel and step time | ||
| startv = f"{startv:.6e}" | ||
| stopv = f"{stopv:.6e}" | ||
| stime = f"{stime:.6e}" | ||
| npoints = str(npoints) | ||
|
|
||
| # Send request to sweep | ||
| self._write(f"SweepVLinMeasureI({self.smu}, {startv}, {stopv}, {stime}, {npoints})") | ||
| self._write(f"print(status.measurement.buffer_available.{self.smu.upper()})") | ||
| ret = self._read() | ||
| if not int(float(ret)) == 2: | ||
| raise ValueError(f"Return data {ret} != 2") | ||
|
|
||
| # Retrieve applied voltages | ||
| self._write(f"printbuffer(1, {npoints}, {self.smu}.nvbuffer1.sourcevalues)") | ||
| x = table_to_np(self._read()) | ||
|
|
||
| # Retrieve measured currents | ||
| self._write(f"printbuffer(1, {npoints}, {self.smu}.nvbuffer1.readings)") | ||
| y = table_to_np(self._read()) | ||
|
|
||
| # Return x and y vectors | ||
| return x, y |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is the 2600 serie you just workoed on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c1760aa