Commit 7b6acad6 authored by Martin Drechsler's avatar Martin Drechsler

Scans functions corrected, now the time step is 5ms and that way works fine...

Scans functions corrected, now the time step is 5ms and that way works fine for now. Also dark theme option enabled.
parent 01b1ca55
......@@ -18,10 +18,13 @@ import pyqtgraph as pg
import myToolbar
import qdarkstyle
import os
os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'
###############################################################################
#This creates the window for the gui
app = QtGui.QApplication([])
app.setStyleSheet(qdarkstyle.load_stylesheet_from_environment(is_pyqtgraph=True)) # set dark style
win = QtGui.QMainWindow()
......@@ -80,6 +83,7 @@ area.addDock(d423_scan, 'right', dPI)
area.addDock(d866_scan, 'right', d866)
area.addDock(dactivate, 'right', dtrap_electrodes)
area.moveDock(dWM, 'above', dtrap_electrodes)
# Here I add the layouts to the corresponding dock
d397.addWidget(layout397)
......@@ -96,10 +100,10 @@ dactivate.addWidget(layout_activate)
############ creating the controls ########################
piezoA397 = anal_control_signal('piezoA397', 13, out_minimum=0, out_maximum=4, out_step=0.01)
piezoB397 = anal_control_signal('piezoB397', 7)
piezoB397 = anal_control_signal('piezoB397', 7, out_step = 0.01)
piezoA866 = anal_control_signal('piezoA866', 14, out_minimum=0, out_maximum=4, out_step=0.01)
piezoB866 = anal_control_signal('piezoB866', 6)
piezoA423 = anal_control_signal('piezoA423', 1)
piezoB866 = anal_control_signal('piezoB866', 6, out_step = 0.01)
piezoA423 = anal_control_signal('piezoA423', 1, out_step = 0.01)
trapDCA = anal_control_signal('DC A', 2)
trapDCB = anal_control_signal('DC B', 3)
......@@ -117,6 +121,13 @@ shutterLED = digital_control_signal('shutterLED', 3)
myToolbar.first_load(anal_control_signal._registry)
myToolbar.incorporate_toolbar(win, anal_control_signal._registry)
###############################################################################
#here I connect the spinboxes to the daq analog outputs:
for ao in anal_control_signal._registry:
ao.connectSpinBoxesToDaq()
###############################################################################
#activate button
actB = activation_button()
layout_activate.addWidget(actB.button)
......@@ -130,13 +141,13 @@ layout397.addWidget(QtGui.QLabel(piezoA397.name), 1, 0), layout397.addWidget(pie
layout397.addWidget(QtGui.QLabel(piezoB397.name), 2, 0), layout397.addWidget(piezoB397.sb, 2, 1)
layout397.addWidget(QtGui.QLabel(shutter397.name), 3, 0), layout397.addWidget(shutter397.cb, 3, 1)
layout397_scan.addWidget(QtGui.QLabel('397 Scan piezo A'), 0, 0)
layout397_scan.addWidget(QtGui.QLabel('start'), 1, 0), layout397_scan.addWidget(piezoA397.scan_sb_start, 1, 1)
layout397_scan.addWidget(QtGui.QLabel('stop'), 2, 0), layout397_scan.addWidget(piezoA397.scan_sb_stop, 2, 1)
layout397_scan.addWidget(QtGui.QLabel('period'), 3, 0), layout397_scan.addWidget(piezoA397.scan_sb_period, 3, 1)
layout397_scan.addWidget(QtGui.QLabel('Scanning'), 4, 0), layout397_scan.addWidget(piezoA397.scan_button, 4, 1)
layout397_scan.addWidget(piezoA397.scanLabelValue, 5, 0)
layout397_scan.addWidget(piezoA397.scanpBar, 5, 1)
layout397_scan.addWidget(QtGui.QLabel('397 Scan piezo B'), 0, 0)
layout397_scan.addWidget(QtGui.QLabel('start'), 1, 0), layout397_scan.addWidget(piezoB397.scan_sb_start, 1, 1)
layout397_scan.addWidget(QtGui.QLabel('stop'), 2, 0), layout397_scan.addWidget(piezoB397.scan_sb_stop, 2, 1)
layout397_scan.addWidget(QtGui.QLabel('period'), 3, 0), layout397_scan.addWidget(piezoB397.scan_sb_period, 3, 1)
layout397_scan.addWidget(QtGui.QLabel('Scanning'), 4, 0), layout397_scan.addWidget(piezoB397.scan_button, 4, 1)
layout397_scan.addWidget(piezoB397.scanLabelValue, 5, 0)
layout397_scan.addWidget(piezoB397.scanpBar, 5, 1)
#########################
......
......@@ -13,6 +13,7 @@ from PyQt5.QtWidgets import (QPushButton, QWidget, QVBoxLayout, QLCDNumber, QPro
import telnetlib
import os
#An example of a class
class anal_control_signal(QWidget):
_registry = []
......@@ -38,17 +39,21 @@ class anal_control_signal(QWidget):
self.AO = daq_AO(self.ch)
except:
print('Analog output %i not found. Daq might not be connected' % self.ch)
self.sb.sigValueChanging.connect(self.sb_analog_change)
self.scan_button = QPushButton('Start scan')
self.timer = QTimer()
self.ScanTimer = QTimer()
self.ScanTimer.timeout.connect(self.scanEvent)
self.scan_step = 0
self.scanpBar = QProgressBar(self)
#self.scanpBar.setTextVisible(False)
self.scanLabelValue = QLabel(self)
self.PbarTimer = QTimer(self)
self.PbarTimer.timeout.connect(self.PbarEvent)
self.scan_sb_start = pg.SpinBox(value = 0, bounds=[self.min, self.max], step = self.step, siPrefix = self.siPrefix, suffix = self.suffix)
self.scan_sb_stop = pg.SpinBox(value = 0, bounds=[self.min, self.max], step = self.step, siPrefix = self.siPrefix, suffix = self.suffix)
......@@ -56,15 +61,19 @@ class anal_control_signal(QWidget):
self.scan_direction = 0
self.scan_button.clicked.connect(self.doAction)
self.scan_button.clicked.connect(self.doScanAction)
self.spin_boxes = [('sb', self.sb), ('scan_sb_start', self.scan_sb_start), ('scan_sb_stop', self.scan_sb_stop), ('scan_sb_period', self.scan_sb_period)]
#set minimum height for spinboxes:
self.sb.setMinimumHeight(22)
self.scan_sb_period.setMinimumHeight(22)
self.scan_sb_start.setMinimumHeight(22)
self.scan_sb_stop.setMinimumHeight(22)
def sb_analog_change(self):
#self.AO.set_out(self.sb.val)
print(self.sb.val)
self.AO.set_out(self.sb.val)
def set_name(self, name):
self.name = name
......@@ -78,38 +87,60 @@ class anal_control_signal(QWidget):
self.sufix = value
def connectSpinBoxesToDaq(self):
print(self.name + 'Initial value: ', self.sb.val)
self.sb_analog_change()
self.sb.sigValueChanging.connect(self.sb_analog_change)
def scanEvent(self):
if abs(abs(self.scan_step)-abs(float(self.scan_sb_start.val)))<1e-6 or abs(abs(self.scan_step)-abs(float(self.scan_sb_stop.val)))<1e-6:
if abs(float(self.scan_step)-float(float(self.scan_sb_start.val)))<1e-6 or abs(float(self.scan_step)-float(self.scan_sb_stop.val))<1e-6:
self.scan_direction = (-1) * self.scan_direction
#print(self.scan_step, float(self.scan_sb_start.val), abs(self.scan_step-float(self.scan_sb_stop.val)))
self.scan_step = self.scan_step + self.scan_direction
self.AO.set_out(self.scan_step)
def PbarEvent(self):
try:
self.scanpBar.setValue( 100 * float(self.scan_step-float(self.scan_sb_start.val))/float(self.scan_sb_stop.val-self.scan_sb_start.val) )
self.scanLabelValue.setText("%.2f" % self.scan_step + ' V')
#print(self.scan_step)
except ZeroDivisionError:
print('Oh dear, you might be trying to scan from 0 to 0. Plase never do that again. ')
def doScanAction(self):
def doAction(self):
self.scan_direction = -float( (self.scan_sb_stop.val-self.scan_sb_start.val)/self.scan_sb_period.val ) * float(2 * 1e-3)
self.scan_step = float(self.scan_sb_start.val)
#self.scan_direction = -float( (self.scan_sb_stop.val-self.scan_sb_start.val)/self.scan_sb_period.val ) * 5e-3 * 2
#self.scan_step = float(self.scan_sb_start.val)
b = float(self.scan_sb_stop.val)
a = float(self.scan_sb_start.val)
dt = 5.0e-3
T = float(self.scan_sb_period.val)
n = T/(2*dt)
self.scan_direction = -(b-a)/n # this is the size in voltage of each step
self.scan_step = float(self.sb.val) # from here it beggins
if self.timer.isActive():
self.timer.stop()
if self.ScanTimer.isActive():
self.ScanTimer.stop()
self.scan_button.setText('Start scan')
self.scan_button.setStyleSheet('background-color: None')
self.PbarTimer.stop()
self.scan_step = 0
self.AO.set_out(self.sb.val)
else:
if self.scan_step > b or self.scan_step < a:
print('scan can not start outside scan range')
else:
self.scan_button.setStyleSheet("background-color: green")
self.timer.start(1)
self.timer.timeout.connect(self.scanEvent)
self.ScanTimer.start(dt*1e3)
self.scan_button.setText('Scanning')
self.PbarTimer.start(dt*1e3)
......
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