Commit 8e94fd58 authored by Martin Drechsler's avatar Martin Drechsler

conflict resolved

parents 9e3c4ea3 6063820e
......@@ -11,4 +11,6 @@ CAMERA_TYPE: if dummy, then a dummy camera is loaded.
"""
WORKING_DIR = '/home/liaf-ankylosaurus-admin/Nextcloud/LIAF-labo/BLOGS/Blog_Ringtrap/measurements/'
CAMERA_TYPE = {'dummy': False}
CAMERA_TYPE = {'dummy': True}
RIGOL_GEN = True
......@@ -16,11 +16,15 @@ from subclasses.pyqtgraph_subclasses import CustomRectangularROI
from zylaCameraWorker import CameraWorker
from subclasses.controllayouts import LaserControlLayout, LaserScanLayout
from subclasses.cameraParameterFrame import CameraParameterFrame
from rigolGui import RigolGenGui
from resources.scanFunctions import create_measurement_array
from resources.storage import get_date_string
from resources.messages import show_warning
from appsettings import WORKING_DIR
from measurement import MeasurementFrame
from rigol_measurement import RigolMeasurementFrame
import sys, os
import numpy as np
......@@ -31,7 +35,8 @@ GUI_LOG = LOG.getChild('GUI logger')
class CameraGuiMainWindow(QMainWindow):
signalWithMeasurementParameters = QtCore.pyqtSignal(object)
roiDataReadySignal = QtCore.pyqtSignal(float)
signalWithRigolMeasurementParameters = QtCore.pyqtSignal(object)
roiDataReadySignal = QtCore.pyqtSignal(float, str)
def __init__(self):
super().__init__()
......@@ -63,18 +68,22 @@ class CameraGuiMainWindow(QMainWindow):
self.dMeasurement = dockarea.Dock("Measurement and saving")
self.dConsole = dockarea.Dock("Console for debugging")
self.dCameraScanAnal = dockarea.Dock("Zyla Camera Scan Analysis")
self.dRigolMeasurement = dockarea.Dock('Rigol Measurement')
self.area.addDock(self.dCameraView)
self.area.addDock(self.dCameraScanAnal, "left", self.dCameraView)
self.area.addDock(self.dCameraTimeAnal, "below", self.dCameraScanAnal)
self.area.addDock(self.dCameraControl, "right", self.dCameraView)
self.area.addDock(self.dConsole, "right", self.dCameraControl)
self.area.addDock(self.dMeasurement, "above", self.dConsole)
self.area.addDock(self.dRigolMeasurement, "below", self.dConsole)
#measurement frame
self.measurementFrame = MeasurementFrame()
self.dMeasurement.addWidget(self.measurementFrame)
self.rigolMeasurementFrame = RigolMeasurementFrame()
self.dRigolMeasurement.addWidget(self.rigolMeasurementFrame)
# button spinbox and label
self.cameraButton = QPushButton("Start Acquisition")
......@@ -163,6 +172,15 @@ class CameraGuiMainWindow(QMainWindow):
self.cameraParamFrame.saveImgButton.clicked.connect(self.save_current_image)
self.rigolMeasurementFrame.startMeasureButton.clicked.connect(self.emit_rigol_measurement_parameters_and_start)
self.rigolMeasurementFrame.startValue.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.endValue.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.stepsNum.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.saveMeasureButton.clicked.connect(
lambda: self.rigolMeasurementFrame.saveMeasureButton.setEnabled(False)
)
self.rigolMeasurementFrame.abortMeasureButton.clicked.connect(backend.abort_measurement)
for roi in self.rois:
self.cameraParamFrame.saveRoiButton.clicked.connect(lambda: roi.save(
current_binning=self.cameraParamFrame.paramTree.p.child('Basic acq parameters')
......@@ -212,9 +230,8 @@ class CameraGuiMainWindow(QMainWindow):
roiSlice = roi.getArrayRegion(self.img.image, img=self.img)
self.newData = np.mean(roiSlice)
if self.isMeasuring:
self.roiDataReadySignal.emit(self.newData)
self.roiDataReadySignal.emit(self.newData, self.meas_type)
self.timeROIdataY = np.roll(self.timeROIdataY, -1)
self.scanROIdataY[self.iROIdata] = self.newData
self.timeROIdataY[-1] = self.newData
......@@ -264,15 +281,24 @@ class CameraGuiMainWindow(QMainWindow):
)
self.previous_frame_index = self.frame_index
#@QtCore.pyqtSlot()
def measurement_starting(self):
@QtCore.pyqtSlot(str)
def measurement_starting(self, meas_type):
self.cameraButton.setEnabled(False)
self.measurementFrame.startMeasureButton.setEnabled(False)
self.rigolMeasurementFrame.startMeasureButton.setEnabled(False)
self.meas_type = meas_type
self.isMeasuring = True
start = self.measurementFrame.startValue.value()
end = self.measurementFrame.endValue.value()
steps = self.measurementFrame.stepsNum.value()
if self.meas_type == 'simple':
start = self.measurementFrame.startValue.value()
end = self.measurementFrame.endValue.value()
steps = self.measurementFrame.stepsNum.value()
elif self.meas_type == 'rigol':
start = self.rigolMeasurementFrame.startValue.value()
end = self.rigolMeasurementFrame.endValue.value()
steps = self.rigolMeasurementFrame.stepsNum.value()
else:
raise 'Oh, wrong meas type'
self.frame_index = 0
self.iROIdata = 0
self.scanROIdataX = create_measurement_array(start, end, steps)
......@@ -284,12 +310,15 @@ class CameraGuiMainWindow(QMainWindow):
print('gui meas start')
#@QtCore.pyqtSlot()
@QtCore.pyqtSlot(str)
def measurement_ending(self):
print('entering gui measure ending')
self.cameraButton.setEnabled(True)
self.measurementFrame.startMeasureButton.setEnabled(True)
self.measurementFrame.saveMeasureButton.setEnabled(True)
self.rigolMeasurementFrame.startMeasureButton.setEnabled(True)
self.rigolMeasurementFrame.saveMeasureButton.setEnabled(True)
self.isMeasuring = False
scanned_sb_name = self.measurementFrame.selectScanSignal.currentText()
......@@ -312,6 +341,7 @@ class CameraGuiMainWindow(QMainWindow):
measure_params['steps'] = self.measurementFrame.stepsNum.value()
measure_params['directory'] = self.measurementFrame.folderBrowser.toPlainText()
measure_params['comment'] = self.measurementFrame.comments.toPlainText()
for l in LaserControlLayout._registry:
for sb_name, sb in l.spinboxes.items():
measure_params[sb_name] = sb.value()
......@@ -319,8 +349,28 @@ class CameraGuiMainWindow(QMainWindow):
for roi in self.rois:
measure_params['Roi Pos'] = roi.pos()
measure_params['Roi Size'] = roi.size()
self.signalWithMeasurementParameters.emit(measure_params)
def emit_rigol_measurement_parameters_and_start(self):
measure_params = dict()
measure_params['gui params'] = 0
measure_params['start'] = self.rigolMeasurementFrame.startValue.value()
measure_params['end'] = self.rigolMeasurementFrame.endValue.value()
measure_params['steps'] = self.rigolMeasurementFrame.stepsNum.value()
measure_params['directory'] = WORKING_DIR
measure_params['comment'] = self.rigolMeasurementFrame.comments.toPlainText()
for l in LaserControlLayout._registry:
for sb_name, sb in l.spinboxes.items():
measure_params[sb_name] = sb.value()
for roi in self.rois:
measure_params['Roi Pos'] = roi.pos()
measure_params['Roi Size'] = roi.size()
self.signalWithRigolMeasurementParameters.emit(measure_params)
def save_current_image(self):
if self.cameraParamFrame.imagePrefix.text()=='':
show_warning('You have to write a filename')
......
......@@ -28,6 +28,7 @@ class ControlGui(QtGui.QFrame):
self.initUI()
def initUI(self):
self.setObjectName('Daq Gui')
self.menuBar = QtGui.QMenuBar(self)
self.area = dockarea.DockArea()
self.grid = QtGui.QGridLayout()
......
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 19:16:28 2019
@author: nicon
"""
import visa
import numpy as np
import time
class GeneradorFuncionesRigol(object):
def __init__(self, instrument_addres='TCPIP0::10.99.45.51::INSTR'):
self.rm = visa.ResourceManager()
try:
self.inst = self.rm.open_resource(instrument_addres)
except:
raise 'no rigo gen in lan detected'
if self.inst != []:
try:
print('El IDN del instrumento es ', self.inst.query("*IDN?"))
except:
print('El instrumento no respondió cuando se le preguntó el nombre.')
def TurnOn(self, channel = 1):
self.inst.write("OUTPut{}:STATe ON".format(channel))
def TurnOff(self, channel = 1):
self.inst.write("OUTPut{}:STATe OFF".format(channel))
def State(self, channel = 1):
print(self.inst.query('OUTP{}:STAT?'.format(channel)))
@property
def Frequency(self, channel = 1):
"""
The frequency you set is in Hz
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[1]
@Frequency.setter
def Frequency(self, freq, channel = 1):
self.inst.write("SOURce{}:FREQuency {}".format(channel,freq))
@property
def Shape(self, channel = 1):
"""
SINusoid|SQUare|RAMP|PULSe|NOISe|USER|DC|SINC|EXPRise|EXPFall|CARDiac|GAUSsian
|HAVersine|LORentz|ARBPULSE|DUAltone
"""
print(self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[0])
@Shape.setter
def Shape(self, shape, channel = 1):
self.inst.write('SOURce{}:FUNCtion {}'.format(channel, shape))
@property
def Voltage(self, channel = 1):
"""
The voltage you set is in Vpp
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[2]
@Voltage.setter
def Voltage(self, voltage, channel = 1):
self.inst.write('SOURce{}:VOLTage:LEVel:IMMediate:AMPLitude {}'.format(channel, voltage))
@property
def Offset(self, channel = 1):
"""
The offset you set is in Vpp
"""
return self.inst.query(':SOUR{}:APPL?'.format(channel)).split(",")[3]
@Offset.setter
def Offset(self, offset, channel = 1):
self.inst.write('SOURce{}:VOLTage:LEVel:IMMediate:OFFSet {}'.format(channel, offset))
def GeneralSet(self, freq, voltage, offset = '0 V', shape = 'SIN', channel = 1):
self.SetFrequency(freq, channel)
self.SetVoltage(voltage, channel)
self.SetOffset(offset, channel)
def DiscreteSweep(self, freqini, freqfin, step, timeoff = 1, channel = 1):
Frequencies = np.arange(freqini, freqfin + step, step)
for Fr in Frequencies:
self.inst.write("SOURce{}:FREQuency {}".format(channel, Fr))
time.sleep(timeoff)
def __del__(self):
self.TurnOff()
self.rm.close()
\ No newline at end of file
from appsettings import CAMERA_TYPE
from appsettings import CAMERA_TYPE, RIGOL_GEN
if CAMERA_TYPE['dummy']==True:
from drivers.dummyAndor import AndorZyla
else:
from drivers.andorzyla import AndorZyla
from drivers.GeneradorFuncionesRigol import GeneradorFuncionesRigol
from rigolGui import RigolGenGui
from cameraGui import CameraGuiMainWindow
from zylaCameraWorker import CameraWorker
from MCDAQcontrolsignals import anal_control_signal
......@@ -39,6 +42,10 @@ if __name__ == "__main__":
app.setWindowIcon(app_icon)
camera = AndorZyla(0)
if RIGOL_GEN:
rigGen = GeneradorFuncionesRigol()
rigGenGui = RigolGenGui(rigGen)
piezoA397 = anal_control_signal('piezoA397', channel=13, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB397 = anal_control_signal('piezoB397', channel=7, ao_type='cavity_piezo')
......@@ -74,7 +81,11 @@ if __name__ == "__main__":
cameraMainWindow = CameraGuiMainWindow()
cameraWorker = CameraWorker(camera)
if RIGOL_GEN:
cameraWorker = CameraWorker(camera, rigGen)
else:
cameraWorker = CameraWorker(camera)
cameraWorker.moveToThread(backendThread)
......@@ -85,4 +96,10 @@ if __name__ == "__main__":
controlGui.toolbar.load()
sys.exit(app.exec_())
app.exec_()
if RIGOL_GEN:
rigGen.__del__()
try:
camera.shutdown()
except:
print('Proper shutdown of camera failed')
\ No newline at end of file
......@@ -11,7 +11,7 @@ The ui skeleton is built with qtdesigner and its structur lies in the measuremen
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from measurement_ui import Ui_Frame
from resources.measurement_ui import Ui_Frame
from MCDAQcontrolsignals import anal_control_signal
from appsettings import WORKING_DIR
......
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'rigol_gen.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(469, 343)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 441, 321))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1)
self.cb_onOff = QtWidgets.QCheckBox(self.gridLayoutWidget)
self.cb_onOff.setObjectName("cb_onOff")
self.gridLayout.addWidget(self.cb_onOff, 0, 1, 1, 1)
self.label = QtWidgets.QLabel(self.gridLayoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
self.sb_freq = SpinBox(self.gridLayoutWidget)
self.sb_freq.setObjectName("sb_freq")
self.gridLayout.addWidget(self.sb_freq, 1, 1, 1, 1)
self.sb_amp = SpinBox(self.gridLayoutWidget)
self.sb_amp.setObjectName("sb_amp")
self.gridLayout.addWidget(self.sb_amp, 2, 1, 1, 1)
self.sb_offset = SpinBox(self.gridLayoutWidget)
self.sb_offset.setObjectName("sb_offset")
self.gridLayout.addWidget(self.sb_offset, 3, 1, 1, 1)
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label_3.setText(_translate("Frame", "On/Off"))
self.label_2.setText(_translate("Frame", "Offset"))
self.cb_onOff.setText(_translate("Frame", "Ch 1 On"))
self.label.setText(_translate("Frame", "Amplitude"))
self.label_4.setText(_translate("Frame", "Frequency"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Frame</class>
<widget class="QFrame" name="Frame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>333</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>231</width>
<height>211</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Start freq </string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="comments"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="stepsNum"/>
</item>
<item row="0" column="1">
<widget class="SpinBox" name="startValue"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>End freq</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Steps num</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="SpinBox" name="endValue"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Comments</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="startMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Start measurement</string>
</property>
</widget>
<widget class="QTreeView" name="treeView">
<property name="geometry">
<rect>
<x>250</x>
<y>30</y>
<width>281</width>
<height>111</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>260</x>
<y>10</y>
<width>161</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Info about measurement</string>
</property>
</widget>
<widget class="QPushButton" name="saveMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save measurement</string>
</property>
</widget>
<widget class="QPushButton" name="abortMeasureButton">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Abort measurement</string>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>SpinBox</class>
<extends>QDoubleSpinBox</extends>
<header location="global">pyqtgraph</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'rigol_measurement.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(592, 333)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 231, 211))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
self.comments = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.comments.setObjectName("comments")
self.gridLayout.addWidget(self.comments, 3, 1, 1, 1)
self.stepsNum = QtWidgets.QSpinBox(self.gridLayoutWidget)
self.stepsNum.setObjectName("stepsNum")
self.gridLayout.addWidget(self.stepsNum, 2, 1, 1, 1)
self.startValue = SpinBox(self.gridLayoutWidget)
self.startValue.setObjectName("startValue")
self.gridLayout.addWidget(self.startValue, 0, 1, 1, 1)
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1)
self.endValue = SpinBox(self.gridLayoutWidget)
self.endValue.setObjectName("endValue")
self.gridLayout.addWidget(self.endValue, 1, 1, 1, 1)
self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 3, 0, 1, 1)
self.startMeasureButton = QtWidgets.QPushButton(Frame)
self.startMeasureButton.setGeometry(QtCore.QRect(10, 240, 171, 23))
self.startMeasureButton.setObjectName("startMeasureButton")
self.treeView = QtWidgets.QTreeView(Frame)
self.treeView.setGeometry(QtCore.QRect(250, 30, 281, 111))
self.treeView.setObjectName("treeView")
self.label_6 = QtWidgets.QLabel(Frame)
self.label_6.setGeometry(QtCore.QRect(260, 10, 161, 20))
self.label_6.setObjectName("label_6")
self.saveMeasureButton = QtWidgets.QPushButton(Frame)
self.saveMeasureButton.setGeometry(QtCore.QRect(10, 270, 151, 23))
self.saveMeasureButton.setObjectName("saveMeasureButton")
self.abortMeasureButton = QtWidgets.QPushButton(Frame)
self.abortMeasureButton.setGeometry(QtCore.QRect(10, 300, 151, 23))
self.abortMeasureButton.setObjectName("abortMeasureButton")
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label_2.setText(_translate("Frame", "Start freq "))
self.label_3.setText(_translate("Frame", "End freq"))
self.label_4.setText(_translate("Frame", "Steps num"))
self.label_5.setText(_translate("Frame", "Comments"))
self.startMeasureButton.setText(_translate("Frame", "Start measurement"))
self.label_6.setText(_translate("Frame", "Info about measurement"))
self.saveMeasureButton.setText(_translate("Frame", "Save measurement"))
self.abortMeasureButton.setText(_translate("Frame", "Abort measurement"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 24 13:07:06 2019
@author: martindrech
"""
from rigol_gen_ui import Ui_Frame
from GeneradorFuncionesRigol import GeneradorFuncionesRigol
from PyQt5 import QtWidgets, QtCore
import sys
rigGen = GeneradorFuncionesRigol()
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
@QtCore.pyqtSlot(object)
def set_freq(sb):
rigGen.Frequency = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def set_amp(sb):
rigGen.Voltage = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def set_offset(sb):
rigGen.Offset = sb.value()
print(sb.value())
@QtCore.pyqtSlot(object)
def turn_on_off():
if ui.cb_onOff.isChecked():
rigGen.TurnOn()
else:
rigGen.TurnOff()
ui.sb_amp.setValue(1)
ui.sb_amp.setRange(0, 20)
ui.sb_amp.setSuffix('V')
ui.sb_amp.setSingleStep(.2)
ui.sb_amp.setOpts(siPrefix=True)
ui.sb_freq.setValue(50)
ui.sb_freq.setRange(0, 10000000)
ui.sb_freq.setSingleStep(200)
ui.sb_freq.setOpts(siPrefix=True)
ui.sb_freq.setSuffix('Hz')
ui.sb_offset.setValue(0)
ui.sb_offset.setRange(-7.5, 7.5)
ui.sb_offset.setSuffix('V')
ui.sb_offset.setSingleStep(.2)
ui.sb_offset.setOpts(siPrefix=True)
ui.cb_onOff.stateChanged.connect(turn_on_off)
ui.sb_amp.sigValueChanging.connect(set_amp)
ui.sb_freq.sigValueChanging.connect(set_freq)
ui.sb_offset.sigValueChanging.connect(set_offset)
Frame.show()
sys.exit(app.exec_())
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
tip: pyuic5 -x ventana.ui -o ventana_ui.py
@author: martindrech
Control of rigol function generator
"""
from resources.rigol_gen_ui import Ui_Frame
from PyQt5 import QtCore, QtWidgets, QtGui
class RigolGenGui(QtWidgets.QFrame, Ui_Frame):
registry = []
def __init__(self, rigGen):
super().__init__()
self.setupUi(self)
self.registry.append(self)
self.rigGen = rigGen
self.sb_amp.setRange(0, 20)
self.sb_amp.setSuffix('V')
self.sb_amp.setSingleStep(.2)
self.sb_amp.setOpts(siPrefix=True)
self.sb_freq.setRange(0, 10000000)
self.sb_freq.setSingleStep(200)
self.sb_freq.setOpts(siPrefix=True)
self.sb_freq.setSuffix('Hz')
self.sb_offset.setRange(-7.5, 7.5)
self.sb_offset.setSuffix('V')
self.sb_offset.setSingleStep(.2)
self.sb_offset.setOpts(siPrefix=True)
self.make_connections()
self.sb_amp.setValue(1)
self.rigGen.Voltage = 1
self.sb_freq.setValue(50)
self.rigGen.Frequency = 50
self.sb_offset.setValue(0)
self.rigGen.Offset = 0
self.show()
def make_connections(self):
self.cb_onOff.stateChanged.connect(self.turn_on_off)
self.sb_amp.sigValueChanging.connect(self.set_amp)
self.sb_freq.sigValueChanging.connect(self.set_freq)
self.sb_offset.sigValueChanging.connect(self.set_offset)
@QtCore.pyqtSlot(object)
def set_freq(self, sb):
self.rigGen.Frequency = sb.value()
@QtCore.pyqtSlot(object)
def set_amp(self, sb):
self.rigGen.Voltage = sb.value()
@QtCore.pyqtSlot(object)
def set_offset(self, sb):
self.rigGen.Offset = sb.value()
@QtCore.pyqtSlot()
def turn_on_off(self):
if self.cb_onOff.isChecked():
self.rigGen.TurnOn()
else:
self.rigGen.TurnOff()
def __del__(self):
self.rigGen.__del__()
\ No newline at end of file
......@@ -20,13 +20,15 @@ from resources.storage import Storage
class CameraWorker(QtCore.QObject):
imageReadySignal = QtCore.pyqtSignal(np.ndarray, int)
measurementStartingSignal = QtCore.pyqtSignal()
measurementEndingSignal = QtCore.pyqtSignal()
measurementStartingSignal = QtCore.pyqtSignal(str)
measurementEndingSignal = QtCore.pyqtSignal(str)
def __init__(self, andor_camera):
def __init__(self, andor_camera, rigGen):
super().__init__()
self.cam = andor_camera
self.rigGen = rigGen
self.cam.Init()
self.cam.SensorCooling.setValue(True)
print("camera worker initialized")
......@@ -49,6 +51,13 @@ class CameraWorker(QtCore.QObject):
)
)
frontend.signalWithRigolMeasurementParameters.connect(self.rigol_measurement_start)
frontend.rigolMeasurementFrame.saveMeasureButton.clicked.connect(
lambda: self.permanent_save_measurement(
comment=frontend.rigolMeasurementFrame.comments.toPlainText()
)
)
# internal connections
self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired)
#self.cam.helper.timeoutSignal.connect()
......@@ -130,7 +139,7 @@ class CameraWorker(QtCore.QObject):
show_warning('Can not start measurement if camera is acquiring')
return 0
self.measurementStartingSignal.emit()
self.measurementStartingSignal.emit('simple')
self.ao_to_scan = self.get_scan_signal(measure_params['signal_to_scan'])
self.ao_initial_value = self.ao_to_scan.AO.get_current_value()
......@@ -160,7 +169,7 @@ class CameraWorker(QtCore.QObject):
def simple_scan_measurement_end(self):
print('entering scan ending in worker')
self.measurementEndingSignal.emit()
self.measurementEndingSignal.emit('simple')
self.cam.trigger()
self._stop_acquisition_loop()
self.ao_to_scan.go_softly_to_value(self.ao_initial_value)
......@@ -185,11 +194,20 @@ class CameraWorker(QtCore.QObject):
def get_scan_signal(self, ao_name):
return [ao for ao in anal_control_signal._registry if ao.name == ao_name][0]
@QtCore.pyqtSlot(float)
def save_data_from_scan_step(self, roiData):
row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
self.storage.append_data_to_current_file(row)
self.simple_scan_measurement_step()
@QtCore.pyqtSlot(float, str)
def save_data_from_scan_step(self, roiData, meas_type):
if meas_type == 'simple':
row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
self.storage.append_data_to_current_file(row)
self.simple_scan_measurement_step()
elif meas_type == 'rigol':
row = [time.time(), float(self.rigGen.Frequency), roiData]
self.storage.append_data_to_current_file(row)
self.rigol_measurement_step()
else:
raise 'Oh, wrong meas type'
def abort_measurement(self):
......@@ -203,4 +221,60 @@ class CameraWorker(QtCore.QObject):
{'Final comment': comment}
)
self.storage.permanent_save_current_data()
\ No newline at end of file
def rigol_measurement_start(self, measure_params):
if self.cam.CameraAcquiring.getValue():
show_warning('Can not start measurement if camera is acquiring')
return 0
self.measurementStartingSignal.emit('rigol')
self.measure_params = measure_params
self.measure_params['Amplitude'] = self.rigGen.Voltage
self.measure_params['Offset'] = self.rigGen.Offset
start = self.measure_params['start']
end = self.measure_params['end']
step_num = self.measure_params['steps']
self.scan_array_gen = yield_array(create_measurement_array(start, end, step_num))
time.sleep(1)
self.storage.set_directory(measure_params['directory'])
self.storage.create_data_file('Time', 'frequency', 'Roi data')
self.storage.append_metadata_to_current_file(self.cam.GetMetaData(), self.measure_params)
self.cam.TriggerMode.setString('Software')
self._start_acquisition_loop()
self.acq_thread = threading.Thread(
target=self.cam.live_acquisition_loop
)
self.acq_thread.start()
#with self._lock:
self.rigol_measurement_step()
def rigol_measurement_step(self):
try:
print('Setting value of step')
value = next(self.scan_array_gen)
print('value set to ' + str(value))
self.rigGen.Frequency = value
print('value sent to rigol')
# aca puede esperar o chequear algo, por ahora nada
self.cam.trigger()
print('trigger')
except StopIteration:
self.rigol_measurement_end()
except:
raise
def rigol_measurement_end(self):
print('entering scan ending in worker')
self.measurementEndingSignal.emit('rigol')
self.cam.trigger()
self._stop_acquisition_loop()
self.cam.TriggerMode.setString('Internal')
print('exiting scan ending in worker')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment