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
This diff is collapsed.
......@@ -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:
......
This diff is collapsed.
......@@ -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