From 7c8d3b1439c98dee9379974f1e3ee00f4697ed9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Weber?= Date: Thu, 16 May 2024 17:37:58 +0200 Subject: [PATCH 1/2] done ith using pymeasure driver --- README.rst | 10 ++- ...r_SR830.py => daq_0Dviewer_LockInSR830.py} | 20 ++--- .../plugins_1D/daq_1Dviewer_LockInSR830.py | 75 +++++++++++++++++++ 3 files changed, 89 insertions(+), 16 deletions(-) rename src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/{daq_0Dviewer_SR830.py => daq_0Dviewer_LockInSR830.py} (89%) create mode 100644 src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_1D/daq_1Dviewer_LockInSR830.py diff --git a/README.rst b/README.rst index db94fe1..4659cb8 100644 --- a/README.rst +++ b/README.rst @@ -38,9 +38,16 @@ Below is the list of instruments included in this plugin Viewer0D ++++++++ -* **LockinSR830**: LockIn Amplifier SR830 +* **LockinSR830Legacy**: LockIn Amplifier SR830 using direct VISA SPI commands (no more maintained) +* **LockinSR830**: LockIn Amplifier SR830 using the pymeasure SR830 driver (preferred) +Viewer1D +++++++++ + +* **LockinSR830**: LockIn Amplifier SR830 using the pymeasure SR830 driver and using the internal buffer memory. Get the + two channels outputs. Should be fast but is in fact quite slow... + Installation instructions @@ -48,4 +55,5 @@ Installation instructions * PyMoDAQ version > 4.0.8 * VISA backend if connected using GPIB +* pymeasure version >= 0.14.0 needed (if not yet available install from its github repository) diff --git a/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_SR830.py b/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_LockInSR830.py similarity index 89% rename from src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_SR830.py rename to src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_LockInSR830.py index e8ca946..340a3ea 100644 --- a/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_SR830.py +++ b/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_0D/daq_0Dviewer_LockInSR830.py @@ -19,7 +19,7 @@ break -class DAQ_0DViewer_SR830(DAQ_Viewer_base): +class DAQ_0DViewer_LockInSR830(DAQ_Viewer_base): """ Instrument plugin class for a OD viewer. This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via @@ -142,20 +142,10 @@ def grab_data(self, Naverage=1, **kwargs): kwargs: dict others optionals arguments """ - self.controller.clear() - rate = self.settings['acq', 'sampling_rate'] - self.controller.reset_buffer() - start = perf_counter() - self.controller.start_buffer() - COUNTS = 10 - self.controller.wait_for_buffer(COUNTS, timeout=60, timestep=0.01) - print(f'acq time: {perf_counter() - start}s, should be: {COUNTS / rate}') - ch1 = self.controller.get_buffer(1) - ch2 = self.controller.get_buffer(2) - self.controller.start_buffer(False) - selected_channels = self.settings.child('acq', 'channels').value()['selected'] - data_list_array = [np.array([snapped]) for snapped in self.controller.snap(*selected_channels)] + selected_channels = self.settings['acq', 'channels']['selected'] + snapped_list = self.controller.snap(*selected_channels)[:len(selected_channels)] + data_list_array = [np.array([snapped]) for snapped in snapped_list] dwas = self.create_dwas(data_list_array) self.dte_signal.emit(DataToExport(name='SR830', data=dwas)) @@ -172,7 +162,7 @@ def create_dwas(self, data_list_array: List[np.ndarray]) -> List[DataFromPlugins ------- List[DataFromPlugins] """ - selected_channels = self.settings.child('acq', 'channels').value()['selected'] + selected_channels = self.settings['acq', 'channels']['selected'] if self.settings['acq', 'separate_viewers']: dwas = [DataFromPlugins(f'SR830:{selected_channels[ind]}', diff --git a/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_1D/daq_1Dviewer_LockInSR830.py b/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_1D/daq_1Dviewer_LockInSR830.py new file mode 100644 index 0000000..1a539af --- /dev/null +++ b/src/pymodaq_plugins_stanford_research_systems/daq_viewer_plugins/plugins_1D/daq_1Dviewer_LockInSR830.py @@ -0,0 +1,75 @@ +from typing import List +from time import perf_counter +from qtpy.QtCore import QThread +import numpy as np +from pymodaq.utils.daq_utils import ThreadCommand +from pymodaq.utils.data import DataFromPlugins, DataToExport +from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main +from pymodaq.utils.parameter import Parameter + +from pymeasure.instruments.srs.sr830 import SR830 +from pyvisa import ResourceManager + +from pymodaq_plugins_stanford_research_systems.daq_viewer_plugins.plugins_0D.daq_0Dviewer_LockInSR830 import ( + DAQ_0DViewer_LockInSR830) + + +class DAQ_1DViewer_LockInSR830(DAQ_0DViewer_LockInSR830): + """ Instrument plugin class for a OD viewer. + + This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via + DAQ_Viewer_base. It makes a bridge between the DAQ_Viewer module and the Python wrapper of a particular instrument. + + Attributes: + ----------- + controller: object + The particular object that allow the communication with the hardware, in general a python wrapper around the + hardware library. + + """ + params = [ + {'title': 'Npts:', 'name': 'npts', 'type': 'int', 'min': 1, 'max': 16380, 'value': 10}, + ] + DAQ_0DViewer_LockInSR830.params + + def ini_detector(self, controller=None): + info, initialized = super().ini_detector(controller) + self.settings.child('acq', 'separate_viewers').show(False) + self.settings.child('acq', 'channels').show(False) + + self.dte_signal_temp.emit(DataToExport(name='SR830', data=[ + DataFromPlugins('CH1', data=[np.zeros((self.settings['npts'],))], labels=['CH1']), + DataFromPlugins('CH2', data=[np.zeros((self.settings['npts'],))], labels=['CH2']), + ])) + return info, initialized + + 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 + """ + self.controller.clear() + rate = self.settings['acq', 'sampling_rate'] + self.controller.reset_buffer() + start = perf_counter() + self.controller.start_scan() + counts = self.settings['npts'] + self.controller.wait_for_buffer(counts, timeout=60, timestep=0.01) + print(f'acq time: {perf_counter() - start}s, should be: {counts / rate}') + ch1 = self.controller.get_buffer(1) + ch2 = self.controller.get_buffer(2) + self.controller.pause_scan() + + self.dte_signal.emit(DataToExport(name='SR830', data=[ + DataFromPlugins('CH1', data=[ch1], labels=['CH1']), + DataFromPlugins('CH2', data=[ch2], labels=['CH2']), + ])) + + +if __name__ == '__main__': + main(__file__, init=False) From 689ba8603c782746a9462edb3bab5aac324bbb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Weber?= Date: Thu, 16 May 2024 17:38:25 +0200 Subject: [PATCH 2/2] Update VERSION --- src/pymodaq_plugins_stanford_research_systems/resources/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_stanford_research_systems/resources/VERSION b/src/pymodaq_plugins_stanford_research_systems/resources/VERSION index 6812f81..6c6aa7c 100644 --- a/src/pymodaq_plugins_stanford_research_systems/resources/VERSION +++ b/src/pymodaq_plugins_stanford_research_systems/resources/VERSION @@ -1 +1 @@ -0.0.3 \ No newline at end of file +0.1.0 \ No newline at end of file