Commit f00ff9e8 authored by Martin Drechsler's avatar Martin Drechsler
parents a4800b2c a2488054
......@@ -21,7 +21,7 @@ try:
from props.digital import DigitalProps
from props.ao import AnalogOutputProps
except ValueError:
except:
warnings.warn('Problem importing ul from mcculw, Thus might happen in Linux')
import uldaq as ul
from uldaq import InterfaceType
......@@ -130,4 +130,4 @@ class daq_DO(object):
print('Digital out %i set to %s' % (self.out_num, bit_value) )
return bit_value, self.out_num
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
This is a temporary script file.
"""
from ADoutputs import daq_AO, daq_DO
from PyQt5 import QtCore
AO_TYPES = ['cavity_piezo', 'electrode', 'laser_piezo']
class anal_control_signal(QtCore.QObject):
_registry = []
def __init__(self, name, channel, ao_type, out_minimum = -10, out_maximum = 10, out_step = 0.1, feedfoward = False):
super().__init__()
self._registry.append(self)
if ao_type not in AO_TYPES:
raise ValueError("Invalid ao type. Expected one of: %s" % AO_TYPES)
self.name = name
self.ch = channel
self.ao_type = ao_type
self.is_feedwoward_enabled = feedfoward
self.initial_value = 0
self.max = out_maximum
self.min = out_minimum
self.step = out_step
self.siPrefix = True
self.suffix = 'V'
\ No newline at end of file
......@@ -10,8 +10,9 @@ import sys
from pyqtgraph.Qt import QtGui
from myWidgets import anal_control_signal, digital_control_signal, activation_button, burleighWM
from PyQt5.QtWidgets import QMainWindow
from myWidgets import anal_control_signal, digital_control_signal, activation_button, burleighWM, coherentWM, kick_ions_hard, kick_ions_soft
from PyQt5.QtWidgets import QMainWindow, QPushButton
from PyQt5.QtCore import QTimer
from pyqtgraph import dockarea
import pyqtgraph as pg
......@@ -49,6 +50,8 @@ class GuiMainWindow(QMainWindow):
self.layoutPI = pg.LayoutWidget()
self.layoutIMG = pg.LayoutWidget()
self.layoutWM = pg.LayoutWidget()
self.layoutWM_coherent = pg.LayoutWidget()
self.layout397_scan = pg.LayoutWidget()
self.layout866_scan = pg.LayoutWidget()
self.layout423_scan = pg.LayoutWidget()
......@@ -62,6 +65,8 @@ class GuiMainWindow(QMainWindow):
self.d866 = dockarea.Dock("Dock866", size=(self.s1, self.s2))
self.dPI = dockarea.Dock("DockPI", size=(self.s1, self.s2))
self.dWM = dockarea.Dock("DockWM", size=(self.s1, self.s2))
self.dWM_coherent = dockarea.Dock("DockWM_coherent", size=(self.s1, self.s2))
self.d397_scan = dockarea.Dock("Dock 397 scan", size=(self.s1, self.s2))
self.d866_scan = dockarea.Dock("Dock 866 scan", size=(self.s1, self.s2))
self.d423_scan = dockarea.Dock("Dock 423 scan", size=(self.s1, self.s2))
......@@ -70,42 +75,53 @@ class GuiMainWindow(QMainWindow):
self.dactivate.hideTitleBar()
# Here I add the docks
self.area.addDock( self.dtrap_electrodes)
self.area.addDock(self.dtrap_electrodes)
self.area.addDock(self.d397, 'bottom', self.dtrap_electrodes)
self.area.addDock(self.d866, 'bottom', self.d397)
self.area.addDock(self.dPI, 'bottom', self.d866)
self.area.addDock(self.dWM, 'bottom', self.dPI)
self.area.addDock(self.dWM)
self.area.addDock(self.dWM_coherent)
self.area.addDock(self.dPI, 'bottom', self.dWM)
self.area.addDock(self.d397_scan, 'right', self.d397)
self.area.addDock(self.d423_scan, 'right', self.dPI)
self.area.addDock(self.d866_scan, 'right', self.d866)
self.area.addDock(self.dactivate, 'right', self.dtrap_electrodes)
#self.area.addDock(self.dactivate, 'right', self.dtrap_electrodes)
self.area.moveDock(self.dWM, 'above', self.dtrap_electrodes)
self.area.moveDock(self.dWM_coherent, 'above', self.dWM)
self.area.moveDock(self.dPI, 'above', self.d423_scan)
# Here I add the layouts to the corresponding dock
self.d397.addWidget(self.layout397)
self.d866.addWidget(self.layout866)
self.dPI.addWidget(self.layoutPI)
self.dWM.addWidget(self.layoutWM)
self.dWM_coherent.addWidget(self.layoutWM_coherent)
self.d397_scan.addWidget(self.layout397_scan)
self.d866_scan.addWidget(self.layout866_scan)
self.d423_scan.addWidget(self.layout423_scan)
self.dtrap_electrodes.addWidget(self.layout_trap_electrodes)
self.dactivate.addWidget(self.layout_activate)
#self.dactivate.addWidget(self.layout_activate)
############ creating the controls ########################
self.piezoA397 = anal_control_signal('piezoA397', 13, out_minimum=0, out_maximum=4, out_step=0.01)
self.piezoB397 = anal_control_signal('piezoB397', 7, out_step = 0.01)
self.piezoA866 = anal_control_signal('piezoA866', 14, out_minimum=0, out_maximum=4, out_step=0.01)
self.piezoB866 = anal_control_signal('piezoB866', 6, out_step = 0.01)
self.piezoA423 = anal_control_signal('piezoA423', 1, out_step = 0.01)
self.trapDCA = anal_control_signal('DC A', 2)
self.trapDCB = anal_control_signal('DC B', 3)
self.trapCompC = anal_control_signal('Comp C', 4)
self.trapCompD = anal_control_signal('Comp D', 5)
self.piezoA397 = anal_control_signal('piezoA397', 13, ao_type ='cavity_piezo' , out_minimum=0, out_maximum=4, out_step=0.01)
self.piezoB397 = anal_control_signal('piezoB397', 7, ao_type ='cavity_piezo', out_step = 0.01)
self.piezoA866 = anal_control_signal('piezoA866', 14, ao_type ='cavity_piezo', out_minimum=0, out_maximum=4, out_step=0.01)
self.piezoB866 = anal_control_signal('piezoB866', 9, ao_type ='cavity_piezo', out_step = 0.01, out_minimum= -2, out_maximum= 10)
self.piezoA423 = anal_control_signal('piezoA423', 8, ao_type ='laser_piezo', out_step = 0.01)
self.trapDCA = anal_control_signal('DC A', 2, ao_type ='electrode')
self.trapDCB = anal_control_signal('DC B', 1, ao_type ='electrode')
self.trapCompC = anal_control_signal('Comp C', 4, ao_type ='electrode')
self.trapCompC.sb.setEnabled(False)
self.trapCompD = anal_control_signal('Comp D', 5, ao_type ='electrode')
self.trapCompOven = anal_control_signal('Comp Oven', 0, ao_type ='electrode')
self.trapCompExYb = anal_control_signal('Comp Ex Yb', 6, ao_type ='electrode')
......@@ -114,14 +130,30 @@ class GuiMainWindow(QMainWindow):
self.shutter423 = digital_control_signal('shutter423', 1)
self.shutterLED = digital_control_signal('shutterLED', 3)
self.soft_kick_button = QPushButton('kick!')
self.soft_kick_button.clicked.connect(lambda: kick_ions_soft(self.shutter866, self.trapDCA, self.trapDCB))
self.hard_kick_button = QPushButton('kick!!')
self.hard_kick_button.clicked.connect(lambda: kick_ions_hard(self.shutter866, self.trapDCA, self.trapDCB))
#############Toolbar and initial loading of config ############################
toolbar = myToolbarMenu(self.win, anal_control_signal._registry )
self.toolbar = myToolbarMenu(self.win, anal_control_signal._registry )
self.toolbar.load(anal_control_signal._registry)
#print('Defined analog outputs: \n', self.toolbar.aosDicc.keys())
self.autosave_timer = QTimer()
self.autosave_timer.timeout.connect(lambda: self.toolbar.save(anal_control_signal._registry))
self.autosave_timer.start(10000)
###############################################################################
#here I connect the spinboxes to the daq analog outputs:
for ao in anal_control_signal._registry:
ao.connectSpinBoxesToDaq()
print('Analog control pinout:')
for ao in anal_control_signal._registry:
print(ao.name + ' -> ' + 'ao' + str(ao.ch))
###############################################################################
......@@ -154,6 +186,9 @@ class GuiMainWindow(QMainWindow):
self.layout866.addWidget(QtGui.QLabel(self.piezoA866.name), 1, 0), self.layout866.addWidget(self.piezoA866.sb, 1, 1)
self.layout866.addWidget(QtGui.QLabel(self.piezoB866.name), 2, 0), self.layout866.addWidget(self.piezoB866.sb, 2, 1)
self.layout866.addWidget(QtGui.QLabel(self.shutter866.name), 3, 0), self.layout866.addWidget(self.shutter866.cb, 3, 1)
self.layout866.addWidget(QtGui.QLabel("866 WM"), 3, 2), self.layout866.addWidget(self.shutterLED.cb, 3, 3)
self.layout866.addWidget(QtGui.QLabel("Blink"), 4, 0), self.layout866.addWidget(self.shutter866.blink_cb, 4, 1)
self.layout866.addWidget(self.layout866.addWidget(self.shutter866.blink_time_sb, 4, 2))
self.layout866_scan.addWidget(QtGui.QLabel('866 Scan piezo B'), 0, 0)
self.layout866_scan.addWidget(QtGui.QLabel('start'), 1, 0), self.layout866_scan.addWidget(self.piezoB866.scan_sb_start, 1, 1)
......@@ -168,7 +203,7 @@ class GuiMainWindow(QMainWindow):
self.layoutPI.addWidget(QtGui.QLabel('Photoion'), 0, 0)
self.layoutPI.addWidget(QtGui.QLabel(self.piezoA423.name), 1, 0), self.layoutPI.addWidget(self.piezoA423.sb, 1, 1)
self.layoutPI.addWidget(QtGui.QLabel(self.shutter423.name), 2, 0), self.layoutPI.addWidget(self.shutter423.cb, 2, 1)
self.layoutPI.addWidget(QtGui.QLabel(self.shutterLED.name), 3, 0), self.layoutPI.addWidget(self.shutterLED.cb, 3, 1)
#self.layoutPI.addWidget(QtGui.QLabel(self.shutterLED.name), 3, 0), self.layoutPI.addWidget(self.shutterLED.cb, 3, 1)
self.layout423_scan.addWidget(QtGui.QLabel('423 Scan piezo A'), 0, 0)
self.layout423_scan.addWidget(QtGui.QLabel('start'), 1, 0), self.layout423_scan.addWidget(self.piezoA423.scan_sb_start, 1, 1)
......@@ -178,14 +213,20 @@ class GuiMainWindow(QMainWindow):
self.layout423_scan.addWidget(self.piezoA423.scanLabelValue, 5, 0)
self.layout423_scan.addWidget(self.piezoA423.scanpBar, 5, 1)
#########################
######### trap electrodes ###########
self.layout_trap_electrodes.addWidget(QtGui.QLabel('Trap electrodes'), 0, 0)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapDCA.name), 1, 1), self.layout_trap_electrodes.addWidget(self.trapDCA.sb, 1, 2)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapDCB.name), 2, 1), self.layout_trap_electrodes.addWidget(self.trapDCB.sb, 2, 2)
self.layout_trap_electrodes.addWidget(self.soft_kick_button, 1, 0)
self.layout_trap_electrodes.addWidget(self.hard_kick_button, 2, 0)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapCompC.name), 1, 3), self.layout_trap_electrodes.addWidget(self.trapCompC.sb, 1, 4)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapCompD.name), 2, 3), self.layout_trap_electrodes.addWidget(self.trapCompD.sb, 2, 4)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapCompOven.name), 1, 5), self.layout_trap_electrodes.addWidget(self.trapCompOven.sb, 1, 6)
self.layout_trap_electrodes.addWidget(QtGui.QLabel(self.trapCompExYb.name), 2, 5), self.layout_trap_electrodes.addWidget(self.trapCompExYb.sb, 2, 6)
###########################################################
......@@ -202,7 +243,7 @@ class GuiMainWindow(QMainWindow):
# read wavemeter
self.wavemeter = burleighWM(self.layoutWM, self.dWM)
self.wm_coherent = coherentWM(self.layoutWM_coherent, self.dWM_coherent)
###############################################################################
......
......@@ -38,19 +38,22 @@ class myToolbarMenu(QWidget):
menubar = win.menuBar()
saveAct = QAction('Save', win)
# saveAct = QAction('Save', win)
loadAct = QAction('Load', win)
saveAsAct = QAction('Save as' , win)
openFromAct = QAction('open from', win)
loadElectrodesAct = QAction('Load electrodes', win)
win.statusBar()
menubar = win.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(saveAct)
#fileMenu.addAction(saveAct)
fileMenu.addAction(loadAct)
fileMenu.addAction(saveAsAct)
fileMenu.addAction(openFromAct)
fileMenu.addAction(loadElectrodesAct)
viewMenu = menubar.addMenu('Monitor')
......@@ -62,8 +65,9 @@ class myToolbarMenu(QWidget):
plotRoi = QAction('Open roi plot', win)
roiMenu.addAction(plotRoi)
saveAct.triggered.connect(lambda: self.save(analog_control_signals))
#☺saveAct.triggered.connect(lambda: self.save(analog_control_signals))
loadAct.triggered.connect(lambda: self.load(analog_control_signals))
loadElectrodesAct.triggered.connect(lambda: self.open_from([ao for ao in analog_control_signals if ao.ao_type == 'electrode'], win))
saveAsAct.triggered.connect(lambda: self.save_as(analog_control_signals, win))
openFromAct.triggered.connect(lambda: self.open_from(analog_control_signals, win))
viewWebcams.toggled.connect(lambda: self.putWebcams(viewWebcams.isChecked()) )
......@@ -79,7 +83,7 @@ class myToolbarMenu(QWidget):
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving')
#print('saving')
def load(self, aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
......@@ -88,7 +92,10 @@ class myToolbarMenu(QWidget):
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
try:
spinb.setValue( float(spin) )
except TypeError:
spinb.setValue( float(ao.initial_value) )
settings.endGroup()
def first_load(self, aos):
......@@ -110,6 +117,10 @@ class myToolbarMenu(QWidget):
def save_as(self, aos, window):
name = QFileDialog.getSaveFileName(window, 'Save File')
if not name[0]:
print('Saving was canceled')
return 0
file = open(name[0], 'w+')
file.close()
settings = QSettings(name[0], QSettings.IniFormat)
......@@ -126,6 +137,10 @@ class myToolbarMenu(QWidget):
def open_from(self, aos, window):
name = QFileDialog.getOpenFileName(window, 'Save File')
if not name[0]:
print('Opening was canceled')
return 0
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
......
......@@ -9,24 +9,34 @@ import pyqtgraph as pg
from ADoutputs import daq_AO, daq_DO
from pyqtgraph.Qt import QtGui, QtCore
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import (QPushButton, QWidget, QVBoxLayout, QLCDNumber, QProgressBar, QLabel)
from PyQt5.QtWidgets import (QPushButton, QWidget, QVBoxLayout, QLCDNumber, QProgressBar, QLabel, QCheckBox, QComboBox)
import telnetlib
import os
import os, serial, time
from messages import show_warning
import scanFunctions
import wav_coherent
#An example of a class
class anal_control_signal(QWidget):
_registry = []
def __init__(self, name, channel, out_minimum = -10, out_maximum = 10, out_step = 0.1):
def __init__(self, name, channel, ao_type, out_minimum = -10, out_maximum = 10, out_step = 0.1, feedfoward = False):
super().__init__()
self._registry.append(self)
ao_types = ['cavity_piezo', 'electrode', 'laser_piezo']
if ao_type not in ao_types:
raise ValueError("Invalid ao type. Expected one of: %s" % ao_types)
self.name = name
self.ch = channel
self.ao_type = ao_type
self.is_feedwoward_enabled = feedfoward
self.initial_value = 0
......@@ -37,6 +47,33 @@ class anal_control_signal(QWidget):
self.suffix = 'V'
self.sb = pg.SpinBox(value = self.initial_value, bounds=[self.min, self.max], step = self.step, siPrefix = self.siPrefix, suffix = self.suffix)
# set button context menu policy
self.sb.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.sb.customContextMenuRequested.connect(self.on_context_menu)
# create context menu
self.popMenu = QtGui.QMenu(self)
self.act_2_step = QtGui.QAction('2 mV steo', self)
self.act_5_step = QtGui.QAction('5 mV step', self)
self.act_10_step = QtGui.QAction('10 mV step', self)
self.act_100_step = QtGui.QAction('100 mV step', self)
self.popMenu.addAction(self.act_2_step)
self.popMenu.addAction(self.act_5_step)
self.popMenu.addAction(self.act_10_step)
self.popMenu.addAction(self.act_100_step)
self.act_2_step.triggered.connect(lambda: self.sb.setSingleStep(0.002))
self.act_5_step.triggered.connect(lambda: self.sb.setSingleStep(0.005))
self.act_10_step.triggered.connect(lambda: self.sb.setSingleStep(0.01))
self.act_100_step.triggered.connect(lambda: self.sb.setSingleStep(0.1))
try:
self.AO = daq_AO(self.ch)
except:
......@@ -44,8 +81,6 @@ class anal_control_signal(QWidget):
self.scan_button = QPushButton('Start scan')
self.ScanTimer = QTimer()
......@@ -59,7 +94,7 @@ class anal_control_signal(QWidget):
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_sb_period = pg.SpinBox(value = 1, bounds=[0, 10000], step = 0.1, siPrefix = True, suffix = 's')
self.scan_button.clicked.connect(self.doScanAction)
......@@ -72,7 +107,19 @@ class anal_control_signal(QWidget):
self.scan_sb_start.setMinimumHeight(22)
self.scan_sb_stop.setMinimumHeight(22)
self.scan_feedfoward_button = QCheckBox('Feedfoward')
self.scan_feedfoward_sb = pg.SpinBox(value = 0, bounds=[0, 0.005], step = 0.0005)
self.scan_feedfoward_sb.setMinimumHeight(22)
self.scan_feedfoward_step = 0
self.scan_feedfoward_analogOut = None
def on_context_menu(self, point):
# show context menu
self.popMenu.exec_(self.sb.mapToGlobal(point))
def sb_analog_change(self):
self.AO.set_out(self.sb.val)
......@@ -99,6 +146,10 @@ class anal_control_signal(QWidget):
self.scan_step = next(self.scan_array_gen)
self.AO.set_out(self.scan_step)
if self.is_feedwoward_enabled and self.scan_feedfoward_button.isChecked():
self.scan_feedfoward_step = next(self.scan_array_feedfoward_gen)
self.AO_feedfoward.set_out(self.scan_feedfoward_step)
def PbarEvent(self):
try:
......@@ -125,11 +176,24 @@ class anal_control_signal(QWidget):
else:
dt = 5.0e-3
first_value = float(self.sb.val)
self.scan_array = scanFunctions.create_scan_array(self.scan_sb_start.val, self.scan_sb_stop.val, self.scan_sb_period.val, first_value,dt)
self.scan_array = scanFunctions.create_scan_array(self.scan_sb_start.val, self.scan_sb_stop.val, self.scan_sb_period.val, first_value, dt)
self.scan_array_gen = scanFunctions.yield_scan_array(self.scan_array)
self.scan_array_feedfoward = scanFunctions.create_scan_array(self.scan_sb_start.val, self.scan_sb_stop.val,
self.scan_sb_period.val, first_value, dt,
normalized=True, normalization_constant = float(self.scan_feedfoward_sb.val) )
self.scan_array_feedfoward_gen = scanFunctions.yield_scan_array(self.scan_array_feedfoward)
# import pylab as plt
# plt.figure()
# plt.plot(self.scan_array, label = 'scan')
# plt.plot(self.scan_array_feedfoward, label = 'feedfoward')
# plt.legend()
# plt.xlabel('u.a'), plt.ylabel('Voltaje [V]')
# plt.show()
#
if first_value > float(self.scan_sb_stop.val) or first_value < float(self.scan_sb_start.val):
details = 'Remember remember the fifth of November.' + '\n' + 'Also remember that scan starts from the value of the corresponding spin box'
......@@ -147,7 +211,8 @@ class anal_control_signal(QWidget):
def set_scan_feedfoward_analog_out(self, feedfoward_channel):
self.AO_feedfoward = daq_AO(feedfoward_channel)
......@@ -169,6 +234,16 @@ class digital_control_signal(QWidget):
self.cb = QtGui.QCheckBox()
self.cb.stateChanged.connect(self.whenChangeDigital)
self.blink_cb = QtGui.QCheckBox()
self.blink_time_sb = pg.SpinBox(value = 1, bounds=[0.2, 5], step = 0.2, siPrefix = True, suffix = 's')
self.blink_time_sb.setMinimumHeight(22)
self.blink_cb.stateChanged.connect(self.blink)
self.blink_timer = QTimer()
self.blink_timer.timeout.connect(self._blinkEvent)
self.blink_variable = True
def set_name(self, name):
self.name = name
......@@ -178,7 +253,25 @@ class digital_control_signal(QWidget):
def whenChangeDigital(self):
self.DO.set_out(not self.cb.isChecked())
def blink(self):
if self.blink_cb.isChecked():
self.blink_variable = self.cb.isChecked()
blink_period = float(self.blink_time_sb.val) * 1e3
self.blink_timer.start(blink_period)
print("starting blinkin")
else:
self.blink_timer.stop()
self.DO.set_out( not self.cb.isChecked() )
print("finishing blink")
def _blinkEvent(self):
self.blink_variable = not self.blink_variable
self.DO.set_out(self.blink_variable)
class activation_button(QWidget):
def __init__(self):
......@@ -237,8 +330,143 @@ class burleighWM(QWidget):
self.layoutWM.addWidget(lcd)
self.dockWM.addWidget(self.layoutWM)
class coherentWM(QWidget):
def __init__(self, layout, dock):
super().__init__()
self.dockWM = dock
self.layoutWM = layout
wavemeter_ok = False
try:
wavCoh= serial.Serial('COM11', timeout=1, rtscts=True)
wavCoh.close()
wav_coherent.read_measurement(wavCoh)
wavemeter_ok = True
print('coherent wavemeter connected')
except:
show_warning('Coherent wavemeter not connected')
if wavemeter_ok:
lcd = QLCDNumber()
lcd.setDigitCount(11)
lcd.display("00000000 0")
wav_coherent.set_unit(wavCoh, b'F')
def update_label():
try:
value = wav_coherent.read_measurement(wavCoh)
unit = wav_coherent.check_unit(wavCoh)
except:
print("coherent wm problem, closing communication")
wavCoh.close()
self.layoutWM.timer.stop()
try:
lcd.display(value + ' ' + unit)
except:
lcd.display("error000 0")
self.layoutWM.timer = QTimer()
self.layoutWM.timer.timeout.connect(update_label)
self.layoutWM.timer.start(500) # every 10,000 milliseconds
self.layoutWM.setGeometry(300, 300, 250, 150)
def reconnect():
try:
wavCoh= serial.Serial('COM11', timeout=1, rtscts=True)
wavCoh.close()
self.layoutWM.timer.start(500)
except:
print("cannot reconnect")
self.reactivateButton = QPushButton('Reconnect')
self.reactivateButton.clicked.connect(reconnect)
combo = QComboBox()
combo.addItem("Frequency")
combo.addItem("Wavelength Vac")
combo.addItem("Wavelength Air")
def comboActivated(text):
if text == "Frequency":
unit = b'F'
if text == "Wavelength Vac":
unit = b'V'
if text == "Wavelength Air":
unit = b'A'
with wavCoh as w:
wav_coherent.set_unit(w, unit)
\ No newline at end of file
combo.activated[str].connect(comboActivated)
self.layoutWM.addWidget(lcd, 0, 0)
self.layoutWM.addWidget(combo, 1, 0)
self.dockWM.addWidget(self.layoutWM)
self.dockWM.addWidget(self.reactivateButton)
def kick_ions_soft(laser_to_shutter, *voltages_to_shake):
"""
Pone los electrodos pasados en el segundo argumento al minimo, mientras cierra uno de los laseres.
"""
if laser_to_shutter.cb.isChecked():
laser_to_shutter.DO.set_out(True)
current_sb_values = []
for signal in voltages_to_shake:
current_sb_values.append(float(signal.sb.val))
signal.AO.set_out(signal.min)
time.sleep(1)
i = 0
for signal in voltages_to_shake:
signal.AO.set_out(current_sb_values[i])
i = i + 1
if laser_to_shutter.cb.isChecked():
laser_to_shutter.DO.set_out(False)
def kick_ions_hard(laser_to_shutter, *voltages_to_shake):
"""
Pone los electrodos pasados en el segundo argumento al minimo y al maximo para sacudirlos, de a uno. Mientras cierra uno de los laseres.
"""
if laser_to_shutter.cb.isChecked():
laser_to_shutter.DO.set_out(True)
for signal in voltages_to_shake:
current_sb_value = float(signal.sb.val)
for i in range(5):
signal.AO.set_out(signal.min)
time.sleep(.05)
signal.AO.set_out(signal.max)
time.sleep(.05)
signal.AO.set_out(current_sb_value)
if laser_to_shutter.cb.isChecked():
laser_to_shutter.DO.set_out(False)
\ No newline at end of file
......@@ -5,7 +5,7 @@ from mcculw import ul
from mcculw.enums import BoardInfo, InfoType, ULRange, ErrorCode, ScanOptions
from mcculw.ul import ULError
from examples.props.propsbase import Props
from props.propsbase import Props
class AnalogOutputProps(Props):
......
......@@ -5,7 +5,7 @@ from builtins import * # @UnusedWildImport
from mcculw import ul
from mcculw.enums import InfoType, BoardInfo, DigitalInfo, DigitalPortType, \
DigitalIODirection, FunctionType
from examples.props.propsbase import Props
from props.propsbase import Props
from mcculw.ul import ULError
......
from __future__ import absolute_import, division, print_function
from builtins import * # @UnusedWildImport
from mcculw import ul
class Props(object):
"""The base class for classes that provide hardware information for the
library examples. Subclasses of this class may change hardware values.
It is recommended that the values provided by these classes be
hard-coded in production code.
"""
def __init__(self, params): pass
def get_config_array(self, info_type, board_num, count_item, value_item,
wrapper_type=None):
result = []
count = ul.get_config(info_type, board_num, 0, count_item)
for item_num in range(count):
config_value = ul.get_config(
info_type, board_num, item_num, value_item)
if wrapper_type == None:
result.append(config_value)
else:
result.append(wrapper_type(config_value))
return result
......@@ -7,9 +7,8 @@ These instructions will get you a copy of the project up and running on your loc
## Requisites
In windows, the mcculw package is needed. You can install it from https://pypi.org/project/mcculw/
In windows, the mcculw package is needed. You can install it from https://pypi.org/project/mcculw/, where you need to follow some simple instrucions. After following those, open the installed
program Instalcal at least once for getting some neccesary updates.
In Linux, you will need the mccdaq package. You can install it from https://pypi.org/project/uldaq/.
However, until futher notice, the app will only be working properly under Windows. In Linux it can be tested thou, but without connecting to any device. In this case, the outputs are printed on
the console.
\ No newline at end of file
In Linux, you will need the mccdaq package. You can install it from https://pypi.org/project/uldaq/. There you should go to the github repository and follow the build instructions.
Also, check requisites.txt, and install the python packages listed there. This can be usually done via PIP.
\ No newline at end of file
......@@ -11,22 +11,36 @@ Auxiliary functions for performing scans in a cleaner way
import numpy as np
def create_scan_array(scan_start, scan_stop, scan_period, first_value, dt):
def create_scan_array(scan_start, scan_stop, scan_period, first_value, dt, normalized = False, normalization_constant = 0):
"""
Returns the array that represents one period of the scan, including up and down paths of the triangle.
The first_value param is were the scan actually starts. The scan_start and scan_top give the range.
If normalized is true, then it returns the array from 1 to -1 (including up and down paths) multiplied by
the value normalization_constant
"""
scan_start = float(scan_start)
scan_stop = float(scan_stop)
scan_period = float(scan_period)
number_of_points = 1 + (scan_period+dt)//(2*dt)
scan_array_norm = np.linspace(1* normalization_constant, -1*normalization_constant, int(number_of_points) )
scan_array_norm = np.concatenate((scan_array_norm, np.flip(scan_array_norm, 0)[1:]))
scan_array = np.linspace(scan_start, scan_stop, int(number_of_points))
scan_array = np.concatenate((scan_array, np.flip(scan_array, 0)[1:]))
starting_index = np.abs(scan_array-first_value).argmin()+1
scan_array = np.roll(scan_array, starting_index)
scan_array_norm = np.roll(scan_array_norm, starting_index)
return scan_array
if normalized:
return scan_array_norm
else:
return scan_array
def _yield_array(arr):
larr = len(arr)
......
from pyqtgraph import dockarea
from pyqtgraph.Qt import QtGui, QtCore
from PyQt5.QtWidgets import QPushButton, QProgressBar, QLabel
import pyqtgraph as pg
class CustomSpinBox(pg.SpinBox):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self._on_context_menu)
self.popMenu = QtGui.QMenu(self)
self.act_2_step = QtGui.QAction('2 mV step', self)
self.act_5_step = QtGui.QAction('5 mV step', self)
self.act_10_step = QtGui.QAction('10 mV step', self)
self.act_100_step = QtGui.QAction('100 mV step', self)
self.popMenu.addAction(self.act_2_step)
self.popMenu.addAction(self.act_5_step)
self.popMenu.addAction(self.act_10_step)
self.popMenu.addAction(self.act_100_step)
self.act_2_step.triggered.connect(lambda: self.setSingleStep(0.002))
self.act_5_step.triggered.connect(lambda: self.setSingleStep(0.005))
self.act_10_step.triggered.connect(lambda: self.setSingleStep(0.01))
self.act_100_step.triggered.connect(lambda: self.setSingleStep(0.1))
def _on_context_menu(self, point):
# show context menu
self.popMenu.exec_(self.mapToGlobal(point))
class LaserControlLayout(pg.LayoutWidget):
"""
A class for creating a layout with spinboxes and checkboxes to control a laser.
"""
def __init__(self, name, spinboxes = ['sbA', 'sbB'], checkboxes = ['cbA', 'cbB']):
super().__init__()
self.name = name
self.layout.addWidget(QtGui.QLabel(self.name), 0, 0)
self.spinboxes = {}
self.checkboxes = {}
for i, sb_name in enumerate(spinboxes, start = 1):
self.spinboxes[sb_name] = CustomSpinBox()
self.addWidget(QtGui.QLabel(sb_name), i, 0)
self.addWidget(self.spinboxes[sb_name], i, 1)
for i, cb_name in enumerate(checkboxes, start = 0):
self.checkboxes[cb_name] = QtGui.QCheckBox()
row = len(spinboxes) + 1
self.addWidget(QtGui.QLabel(cb_name), row, 2*i)
self.addWidget(self.checkboxes[cb_name], row, 2*i + 1)
class LaserScanLayout(pg.LayoutWidget):
"""
A class for creating a layout for scanning a laser piezo.
"""
def __init__(self, name, feedforward_enables = False):
super().__init__()
self.name = name
self.addWidget(QtGui.QLabel(self.name), 0, 0)
self.spinboxes = {}
self.spinboxes['start'] = CustomSpinBox()
self.spinboxes['stop'] = CustomSpinBox()
self.spinboxes['period'] = CustomSpinBox()
self.scan_button = QPushButton('Start scan')
self.scanpBar = QProgressBar(self)
self.scanLabelValue = QLabel(self)
self.addWidget(QtGui.QLabel('start'), 1, 0),
self.addWidget(self.spinboxes['start'], 1, 1)
self.addWidget(QtGui.QLabel('stop'), 2, 0)
self.addWidget(self.spinboxes['stop'], 2, 1)
self.addWidget(QtGui.QLabel('period'), 3, 0),
self.addWidget(self.spinboxes['period'], 3, 1)
self.addWidget(QtGui.QLabel('Scanning'), 4, 0)
self.addWidget(self.scan_button, 4, 1)
self.addWidget(self.scanLabelValue, 5, 0)
self.addWidget(self.scanpBar, 5, 1)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QMainWindow
app = QtGui.QApplication([])
frame = QtGui.QFrame()
area = dockarea.DockArea()
grid = QtGui.QGridLayout()
frame.setLayout(grid)
myDock = dockarea.Dock('397', (100, 100))
area.addDock(myDock)
grid.addWidget(area, 0, 0)
l = LaserControlLayout('397', checkboxes = ['cb1', 'cb2', 'cb3'])
l_scan = LaserScanLayout('397 scan')
myDock.addWidget(l)
myDock.addWidget(l_scan)
frame.show()
sys.exit(app.exec_())
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 6 13:07:39 2019
@author: Usuario
"""
#import serial
import time
#
#wavCoh=serial.Serial('COM10', timeout=1, rtscts=True)
#wavCoh.close()
#%%
def read_measurement(wm):
with wm as w:
w.write(b'VAL?\n')
#time.sleep(0.2)
a = w.readline().decode("utf-8")
a = a.split(',')[1]
a = a.split('\r')[0]
return a
def read_measurement_forever(wm):
with wm as w:
while(True):
w.write(b'VAL?\n')
#time.sleep(0.2)
a = w.readline().decode("utf-8")
try:
a = a.split(',')[1]
a = a.split('\r')[0]
print(a)
except:
print("wrong value read")
time.sleep(1)
def set_unit(wm, unit):
"""
unit can be:
A: wl in air
V: wl in vacuum
F: frequency
W: wavenumber
"""
with wm as w:
string_to_write = b'UNI ' + unit + b'\n'
w.write(string_to_write)
def check_unit(wm):
with wm as w:
w.write(b'UNI? \n')
#time.sleep(0.2)
unit = w.readline().decode("utf-8")
if unit[5:6] == 'V':
return 'U'
return unit[5:6]
#%%
if __name__ == '__main__':
import serial
import time
wavCoh=serial.Serial('COM11', timeout=1, rtscts=True)
wavCoh.close()
set_unit(wavCoh, b'F')
print(read_measurement(wavCoh))
read_measurement_forever(wavCoh)
# print(a[12:20])
# check_unit(wavCoh)
# import os
# scriptDirectory = os.path.dirname(os.path.realpath(__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