Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
total_control_app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Drechsler
total_control_app
Commits
376b2636
Commit
376b2636
authored
Jun 27, 2018
by
Martin Drechsler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A lot of changes. The most relevant: scan functions added.
parent
5f3c4d43
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
210 additions
and
63 deletions
+210
-63
myGUI.py
myGUI.py
+124
-59
myWidgets.py
myWidgets.py
+86
-4
No files found.
myGUI.py
View file @
376b2636
...
...
@@ -5,41 +5,80 @@ Created on Thu May 31 14:22:48 2018
@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
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
app
=
QtGui
.
QApplication
([])
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
()
layout
=
QtGui
.
QGridLayout
()
cw
.
setLayout
(
layout
)
win
.
setCentralWidget
(
cw
)
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
()
layout397
=
QtGui
.
QGridLayout
()
layout866
=
QtGui
.
QGridLayout
()
layoutPI
=
QtGui
.
QGridLayout
()
layoutIMG
=
QtGui
.
QGridLayout
()
layout397_scan
=
QtGui
.
QGridLayout
()
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
)
# 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
))
l1
=
QtGui
.
QLabel
()
l1
.
setGeometry
(
50
,
50
,
25
,
25
)
pixmap
=
QtGui
.
QPixmap
(
"snuffles.png"
)
pixmap
=
pixmap
.
scaledToWidth
(
100
)
l1
.
setPixmap
(
pixmap
)
layoutIMG
.
addWidget
(
l1
)
# Here I add the docks
area
.
addDock
(
d397
,
'left'
)
area
.
addDock
(
d866
,
'bottom'
,
d397
)
area
.
addDock
(
dPI
,
'bottom'
,
d866
)
area
.
addDock
(
dWM
,
'bottom'
,
dPI
)
area
.
addDock
(
d397_scan
,
'right'
,
d397
)
area
.
addDock
(
d423_scan
,
'right'
,
dPI
)
area
.
addDock
(
d866_scan
,
'right'
,
d866
)
# Here I add the layouts to the corresponding dock
d397
.
addWidget
(
layout397
)
d866
.
addWidget
(
layout866
)
dPI
.
addWidget
(
layoutPI
)
dWM
.
addWidget
(
layoutWM
)
d397_scan
.
addWidget
(
layout397_scan
)
d866_scan
.
addWidget
(
layout866_scan
)
d423_scan
.
addWidget
(
layout423_scan
)
############ creating the controls ########################
...
...
@@ -50,13 +89,13 @@ piezoA866 = anal_control_signal('piezoA866', 2)
piezoB866
=
anal_control_signal
(
'piezoB866'
,
3
)
piezoA423
=
anal_control_signal
(
'piezoA423'
,
4
)
shutter397
=
digital_control_signal
(
'shutter397'
,
0
)
shutter866
=
digital_control_signal
(
'shutter866'
,
2
)
shutter423
=
digital_control_signal
(
'shutter423'
,
1
)
shutterLED
=
digital_control_signal
(
'shutterLED'
,
3
)
button
=
QtWidgets
.
QPushButton
(
'Touch me, babe'
)
#Adding the controls:
######### 397 ###########
layout397
.
addWidget
(
QtGui
.
QLabel
(
'397'
),
0
,
0
)
...
...
@@ -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
(
shutter397
.
name
),
3
,
1
),
layout397
.
addWidget
(
shutter397
.
cb
,
3
,
2
)
layout397_scan
.
addWidget
(
button
,
1
,
3
)
#layout397.addWidget(QtGui.QLabel('shutter'), 3, 1), layout397.addWidget(shutter397, 3, 2)
layout397_scan
.
addWidget
(
QtGui
.
QLabel
(
'397 Scan'
),
0
,
0
)
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 ###########
...
...
@@ -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
(
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_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 ###########
...
...
@@ -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
(
shutter423
.
name
),
2
,
1
),
layoutPI
.
addWidget
(
shutter423
.
cb
,
2
,
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
shutter423
.
cb
.
stateChanged
.
connect
(
lambda
:
whenChangeDigital
(
shutter423
.
cb
,
shutter423
.
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
)
###########################################################
#all shutter start in False:
shutters
=
[
shutter397
,
shutter866
,
shutter423
,
shutterLED
]
for
sh
in
shutters
:
sh
.
DO
.
set_out
(
True
)
shutter397
.
DO
.
set_out
(
1
)
shutter423
.
DO
.
set_out
(
1
)
shutter866
.
DO
.
set_out
(
0
)
time
.
sleep
(
t
)
#read wavemeter
tn
=
telnetlib
.
Telnet
(
host
=
"wannanosaurus"
,
port
=
1234
)
tn
.
write
(
b
'++eos 1
\n
'
)
lcd
=
QLCDNumber
()
i
=
i
+
1
lcd
.
setDigitCount
(
9
)
lcd
.
display
(
"000000 00"
)
print
(
'iteration finished'
)
#%%
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"
)
###########################################################
#all shutter start in False:
shutters
=
[
shutter397
,
shutter866
,
shutter423
,
shutterLED
]
for
sh
in
shutters
:
sh
.
DO
.
set_out
(
True
)
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
myWidgets.py
View file @
376b2636
...
...
@@ -8,11 +8,15 @@ This is a temporary script file.
import
pyqtgraph
as
pg
from
ADoutputs
import
daq_AO
,
daq_DO
from
pyqtgraph.Qt
import
QtGui
from
PyQt5.QtCore
import
QBasicTimer
from
PyQt5.QtWidgets
import
(
QPushButton
,
QWidget
)
#An example of a class
class
anal_control_signal
:
class
anal_control_signal
(
QWidget
)
:
def
__init__
(
self
,
name
,
channel
):
super
()
.
__init__
()
self
.
name
=
name
self
.
ch
=
channel
...
...
@@ -27,6 +31,19 @@ class anal_control_signal:
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
):
self
.
name
=
name
...
...
@@ -48,7 +65,41 @@ class anal_control_signal:
def
set_sufix
(
self
,
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
):
self
.
name
=
name
...
...
@@ -57,7 +108,6 @@ class digital_control_signal:
self
.
initial_value
=
0
self
.
DO
=
daq_DO
(
self
.
ch
)
#win = QtGui.QMainWindow()
self
.
cb
=
QtGui
.
QCheckBox
()
def
set_name
(
self
,
name
):
...
...
@@ -65,4 +115,36 @@ class digital_control_signal:
def
set_initial_value
(
self
,
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment