Commit 376b2636 authored by Martin Drechsler's avatar Martin Drechsler

A lot of changes. The most relevant: scan functions added.

parent 5f3c4d43
...@@ -5,41 +5,80 @@ Created on Thu May 31 14:22:48 2018 ...@@ -5,41 +5,80 @@ Created on Thu May 31 14:22:48 2018
@author: Usuario @author: Usuario
""" """
from pyqtgraph.Qt import QtGui import sys
sys.setrecursionlimit(50000)
from pyqtgraph.Qt import QtCore, QtGui
from myWidgets import anal_control_signal, digital_control_signal from myWidgets import anal_control_signal, digital_control_signal
from pyqtgraph.Qt import QtWidgets
from pyqtgraph import dockarea
import pyqtgraph as pg
import telnetlib
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QLCDNumber
#This creates the window for the gui #This creates the window for the gui
app = QtGui.QApplication([]) app = QtGui.QApplication([])
win = QtGui.QMainWindow() win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: SpinBox') win.setWindowTitle('My GUI')
win.setWindowIcon(QtGui.QIcon('snuffles.png'))
app_icon = QtGui.QIcon()
app_icon.addFile('snuffles.png')
app.setWindowIcon(app_icon)
area = dockarea.DockArea()
win.setCentralWidget(area)
cw = QtGui.QWidget() cw = QtGui.QWidget()
layout = QtGui.QGridLayout()
cw.setLayout(layout)
win.setCentralWidget(cw)
win.show() win.show()
###############################################################################
# Here I create the layouts
layout397 = pg.LayoutWidget()
layout866 = pg.LayoutWidget()
layoutPI = pg.LayoutWidget()
layoutIMG = pg.LayoutWidget()
layoutWM = pg.LayoutWidget()
layout397_scan = pg.LayoutWidget()
layout866_scan = pg.LayoutWidget()
layout423_scan = pg.LayoutWidget()
# Here I create the docks
s1 = 1
s2 = 1
d397 = dockarea.Dock("Dock397", size=(s1, s2))
d866 = dockarea.Dock("Dock866", size=(s1, s2))
dPI = dockarea.Dock("DockPI", size=(s1, s2))
dWM = dockarea.Dock("DockWM", size=(s1, s2))
d397_scan = dockarea.Dock("Dock 397 scan", size=(s1, s2))
d866_scan = dockarea.Dock("Dock 866 scan", size=(s1, s2))
d423_scan = dockarea.Dock("Dock 423 scan", size=(s1, s2))
layout397 = QtGui.QGridLayout() # Here I add the docks
layout866 = QtGui.QGridLayout() area.addDock(d397, 'left')
layoutPI = QtGui.QGridLayout() area.addDock(d866, 'bottom', d397)
layoutIMG = QtGui.QGridLayout() area.addDock(dPI, 'bottom', d866)
layout397_scan = QtGui.QGridLayout() area.addDock(dWM, 'bottom', dPI)
area.addDock(d397_scan, 'right', d397)
area.addDock(d423_scan, 'right', dPI)
area.addDock(d866_scan, 'right', d866)
layout.addLayout(layout397, 1, 1)
layout.addLayout(layout866, 2, 1)
layout.addLayout(layoutPI, 3, 1)
layout.addLayout(layoutIMG, 4, 1)
layout.addLayout(layout397_scan, 1, 2)
l1 = QtGui.QLabel()
l1.setGeometry(50, 50, 25, 25) # Here I add the layouts to the corresponding dock
pixmap = QtGui.QPixmap("snuffles.png") d397.addWidget(layout397)
pixmap = pixmap.scaledToWidth(100) d866.addWidget(layout866)
l1.setPixmap(pixmap) dPI.addWidget(layoutPI)
layoutIMG.addWidget(l1) dWM.addWidget(layoutWM)
d397_scan.addWidget(layout397_scan)
d866_scan.addWidget(layout866_scan)
d423_scan.addWidget(layout423_scan)
############ creating the controls ######################## ############ creating the controls ########################
...@@ -50,13 +89,13 @@ piezoA866 = anal_control_signal('piezoA866', 2) ...@@ -50,13 +89,13 @@ piezoA866 = anal_control_signal('piezoA866', 2)
piezoB866 = anal_control_signal('piezoB866', 3) piezoB866 = anal_control_signal('piezoB866', 3)
piezoA423 = anal_control_signal('piezoA423', 4) piezoA423 = anal_control_signal('piezoA423', 4)
shutter397 = digital_control_signal('shutter397', 0) shutter397 = digital_control_signal('shutter397', 0)
shutter866 = digital_control_signal('shutter866', 2) shutter866 = digital_control_signal('shutter866', 2)
shutter423 = digital_control_signal('shutter423', 1) shutter423 = digital_control_signal('shutter423', 1)
shutterLED = digital_control_signal('shutterLED', 3) shutterLED = digital_control_signal('shutterLED', 3)
#Adding the controls:
button = QtWidgets.QPushButton('Touch me, babe')
######### 397 ########### ######### 397 ###########
layout397.addWidget(QtGui.QLabel('397'), 0, 0) layout397.addWidget(QtGui.QLabel('397'), 0, 0)
...@@ -64,8 +103,13 @@ layout397.addWidget(QtGui.QLabel(piezoA397.name), 1, 1), layout397.addWidget(pie ...@@ -64,8 +103,13 @@ layout397.addWidget(QtGui.QLabel(piezoA397.name), 1, 1), layout397.addWidget(pie
layout397.addWidget(QtGui.QLabel(piezoB397.name), 2, 1), layout397.addWidget(piezoB397.sb, 2, 2) layout397.addWidget(QtGui.QLabel(piezoB397.name), 2, 1), layout397.addWidget(piezoB397.sb, 2, 2)
layout397.addWidget(QtGui.QLabel(shutter397.name), 3, 1), layout397.addWidget(shutter397.cb, 3, 2) layout397.addWidget(QtGui.QLabel(shutter397.name), 3, 1), layout397.addWidget(shutter397.cb, 3, 2)
layout397_scan.addWidget(button, 1, 3) layout397_scan.addWidget(QtGui.QLabel('397 Scan'), 0, 0)
#layout397.addWidget(QtGui.QLabel('shutter'), 3, 1), layout397.addWidget(shutter397, 3, 2) layout397_scan.addWidget(QtGui.QLabel('start'), 1, 1), layout397_scan.addWidget(piezoA397.scan_sb_start, 1, 2)
layout397_scan.addWidget(QtGui.QLabel('stop'), 2, 1), layout397_scan.addWidget(piezoA397.scan_sb_stop, 2, 2)
layout397_scan.addWidget(QtGui.QLabel('period'), 3, 1), layout397_scan.addWidget(piezoA397.scan_sb_period, 3, 2)
layout397_scan.addWidget(QtGui.QLabel('Scanning'), 4, 1), layout397_scan.addWidget(piezoA397.scan_button, 4, 2)
######################### #########################
######### 866 ########### ######### 866 ###########
...@@ -73,6 +117,12 @@ layout866.addWidget(QtGui.QLabel('866'), 0, 0) ...@@ -73,6 +117,12 @@ layout866.addWidget(QtGui.QLabel('866'), 0, 0)
layout866.addWidget(QtGui.QLabel(piezoA866.name), 1, 1), layout866.addWidget(piezoA866.sb, 1, 2) layout866.addWidget(QtGui.QLabel(piezoA866.name), 1, 1), layout866.addWidget(piezoA866.sb, 1, 2)
layout866.addWidget(QtGui.QLabel(piezoB866.name), 2, 1), layout866.addWidget(piezoB866.sb, 2, 2) layout866.addWidget(QtGui.QLabel(piezoB866.name), 2, 1), layout866.addWidget(piezoB866.sb, 2, 2)
layout866.addWidget(QtGui.QLabel(shutter866.name), 3, 1), layout866.addWidget(shutter866.cb, 3, 2) layout866.addWidget(QtGui.QLabel(shutter866.name), 3, 1), layout866.addWidget(shutter866.cb, 3, 2)
layout866_scan.addWidget(QtGui.QLabel('866 Scan'), 0, 0)
layout866_scan.addWidget(QtGui.QLabel('start'), 1, 1), layout866_scan.addWidget(piezoA866.scan_sb_start, 1, 2)
layout866_scan.addWidget(QtGui.QLabel('stop'), 2, 1), layout866_scan.addWidget(piezoA866.scan_sb_stop, 2, 2)
layout866_scan.addWidget(QtGui.QLabel('period'), 3, 1), layout866_scan.addWidget(piezoA866.scan_sb_period, 3, 2)
layout866_scan.addWidget(QtGui.QLabel('Scanning'), 4, 1), layout866_scan.addWidget(piezoA866.scan_button, 4, 2)
######################### #########################
######### PI ########### ######### PI ###########
...@@ -80,6 +130,12 @@ layoutPI.addWidget(QtGui.QLabel('Photoion'), 0, 0) ...@@ -80,6 +130,12 @@ layoutPI.addWidget(QtGui.QLabel('Photoion'), 0, 0)
layoutPI.addWidget(QtGui.QLabel(piezoA423.name), 1, 1), layoutPI.addWidget(piezoA423.sb, 1, 2) layoutPI.addWidget(QtGui.QLabel(piezoA423.name), 1, 1), layoutPI.addWidget(piezoA423.sb, 1, 2)
layoutPI.addWidget(QtGui.QLabel(shutter423.name), 2, 1), layoutPI.addWidget(shutter423.cb, 2, 2) layoutPI.addWidget(QtGui.QLabel(shutter423.name), 2, 1), layoutPI.addWidget(shutter423.cb, 2, 2)
layoutPI.addWidget(QtGui.QLabel(shutterLED.name), 3, 1), layoutPI.addWidget(shutterLED.cb, 3, 2) layoutPI.addWidget(QtGui.QLabel(shutterLED.name), 3, 1), layoutPI.addWidget(shutterLED.cb, 3, 2)
layout423_scan.addWidget(QtGui.QLabel('423 Scan'), 0, 0)
layout423_scan.addWidget(QtGui.QLabel('start'), 1, 1), layout423_scan.addWidget(piezoA423.scan_sb_start, 1, 2)
layout423_scan.addWidget(QtGui.QLabel('stop'), 2, 1), layout423_scan.addWidget(piezoA423.scan_sb_stop, 2, 2)
layout423_scan.addWidget(QtGui.QLabel('period'), 3, 1), layout423_scan.addWidget(piezoA423.scan_sb_period, 3, 2)
layout423_scan.addWidget(QtGui.QLabel('Scanning'), 4, 1), layout423_scan.addWidget(piezoA423.scan_button, 4, 2)
######################### #########################
...@@ -105,42 +161,51 @@ shutter866.cb.stateChanged.connect(lambda: whenChangeDigital(shutter866.cb, shut ...@@ -105,42 +161,51 @@ shutter866.cb.stateChanged.connect(lambda: whenChangeDigital(shutter866.cb, shut
shutter423.cb.stateChanged.connect(lambda: whenChangeDigital(shutter423.cb, shutter423.DO)) shutter423.cb.stateChanged.connect(lambda: whenChangeDigital(shutter423.cb, shutter423.DO))
shutterLED.cb.stateChanged.connect(lambda: whenChangeDigital(shutterLED.cb, shutterLED.DO)) shutterLED.cb.stateChanged.connect(lambda: whenChangeDigital(shutterLED.cb, shutterLED.DO))
#%%
import time
i = 0
t = 1.5
time.sleep(1)
while(i<10):
shutter397.DO.set_out(0)
shutter423.DO.set_out(1)
shutter866.DO.set_out(1)
time.sleep(t)
shutter397.DO.set_out(1)
shutter423.DO.set_out(0)
shutter866.DO.set_out(1)
time.sleep(t)
shutter397.DO.set_out(1)
shutter423.DO.set_out(1)
shutter866.DO.set_out(0)
time.sleep(t)
i = i + 1
print('iteration finished')
#%%
########################################################### ###########################################################
#all shutter start in False: #all shutter start in False:
shutters = [shutter397, shutter866, shutter423, shutterLED] shutters = [shutter397, shutter866, shutter423, shutterLED]
for sh in shutters: for sh in shutters:
sh.DO.set_out(True) sh.DO.set_out(True)
#read wavemeter
tn = telnetlib.Telnet(host = "wannanosaurus", port = 1234)
tn.write(b'++eos 1\n')
lcd = QLCDNumber()
lcd.setDigitCount(9)
lcd.display("000000 00")
def update_label():
tn.sock_avail()
tn.write(b'++read <cr>\n')
a = tn.read_very_eager().decode("utf-8")
#print(a)
try:
lcd.display(a[3:12])
except:
lcd.display("000000 00")
layoutWM.setGeometry(300, 300, 250, 150)
layoutWM.show()
layoutWM.timer = QTimer()
layoutWM.timer.timeout.connect(update_label)
layoutWM.timer.start(1000) # every 10,000 milliseconds
layoutWM.addWidget(lcd)
dWM.addWidget(layoutWM)
###############################################################################
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
\ No newline at end of file
...@@ -8,11 +8,15 @@ This is a temporary script file. ...@@ -8,11 +8,15 @@ This is a temporary script file.
import pyqtgraph as pg import pyqtgraph as pg
from ADoutputs import daq_AO, daq_DO from ADoutputs import daq_AO, daq_DO
from pyqtgraph.Qt import QtGui from pyqtgraph.Qt import QtGui
from PyQt5.QtCore import QBasicTimer
from PyQt5.QtWidgets import (QPushButton, QWidget)
#An example of a class #An example of a class
class anal_control_signal: class anal_control_signal(QWidget):
def __init__(self, name, channel): def __init__(self, name, channel):
super().__init__()
self.name = name self.name = name
self.ch = channel self.ch = channel
...@@ -27,6 +31,19 @@ class anal_control_signal: ...@@ -27,6 +31,19 @@ class anal_control_signal:
self.AO = daq_AO(self.ch) self.AO = daq_AO(self.ch)
self.scan_button = QPushButton('Start scan')
self.timer = QBasicTimer()
self.scan_step = 0
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)
self.scan_sb_period = pg.SpinBox(value = 1, bounds=[0, 100], step = 0.1, siPrefix = True, suffix = 's')
self.scan_direction = 0
self.scan_button.clicked.connect(self.doAction)
def set_name(self, name): def set_name(self, name):
self.name = name self.name = name
...@@ -48,7 +65,41 @@ class anal_control_signal: ...@@ -48,7 +65,41 @@ class anal_control_signal:
def set_sufix(self, value): def set_sufix(self, value):
self.sufix = value self.sufix = value
class digital_control_signal:
def timerEvent(self, e):
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:
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 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)
if self.timer.isActive():
self.timer.stop()
self.scan_button.setText('Start scan')
self.scan_button.setStyleSheet('background-color: None')
self.scan_step = 0
self.AO.set_out(self.sb.val)
else:
self.scan_button.setStyleSheet("background-color: green")
self.timer.start(1, self)
self.scan_button.setText('Scanning')
class digital_control_signal(QWidget):
def __init__(self, name, channel): def __init__(self, name, channel):
self.name = name self.name = name
...@@ -57,7 +108,6 @@ class digital_control_signal: ...@@ -57,7 +108,6 @@ class digital_control_signal:
self.initial_value = 0 self.initial_value = 0
self.DO = daq_DO(self.ch) self.DO = daq_DO(self.ch)
#win = QtGui.QMainWindow()
self.cb = QtGui.QCheckBox() self.cb = QtGui.QCheckBox()
def set_name(self, name): def set_name(self, name):
...@@ -65,4 +115,36 @@ class digital_control_signal: ...@@ -65,4 +115,36 @@ class digital_control_signal:
def set_initial_value(self, value): def set_initial_value(self, value):
self.initial_value = value self.initial_value = value
"""
class analog_scan:
def __init__(self, signal):
self.signal = signal
self.sb_start = pg.SpinBox(value = 0, bounds=[signal.min, signal.max], step = signal.step, siPrefix = signal.siPrefix, suffix = signal.suffix)
self.sb_stop = pg.SpinBox(value = 0, bounds=[signal.min, signal.max], step = signal.step, siPrefix = signal.siPrefix, suffix = signal.suffix)
self.sb_period = pg.SpinBox(value = 1, bounds=[0, 100], step = 0.1, siPrefix = True, suffix = 's')
self.cb = QtGui.QCheckBox()
self.cb.stateChanged.connect(self.scan)
def scan(self):
ao = self.signal
start, stop, period = self.sb_start.value(), self.sb_stop.value(), self.sb_period.value()
dt = 1e-3
n = period / (2*dt)
voltages = np.linspace(start, stop, n)
i = 0
scanning = self.cb.isChecked()
while(scanning):
while( i<len(voltages)-1 ):
ao.set_out(voltages[i])
i = i + 1
time.sleep(dt)
while(i>0):
ao.set_out(voltages[i])
i = i - 1
time.sleep(dt)
scanning = self.cb.isChecked()
"""
\ 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