Skip to content

Commit

Permalink
Merge pull request #3 from PyMoDAQ/pymeasure_driver
Browse files Browse the repository at this point in the history
Pymeasure driver
  • Loading branch information
seb5g authored May 16, 2024
2 parents c3874c2 + 689ba86 commit 2e7f620
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ 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
=========================

* 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)

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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]}',
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.1.0

0 comments on commit 2e7f620

Please sign in to comment.