-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNI_GUI.py
191 lines (137 loc) · 4.54 KB
/
NI_GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
import numpy
import math
import hardware.ni_AGY as ni
# set up to NI
# VOLTAGE PARAMETERS
daq_rate = 1e5 # Hz
daq_name = '6738' # PCIe card name
daq_board = 'Dev1'
daq_num_channels = 32 # AO channels
n2c = {'xgalvo': 29,
'ygalvo': 30,
'etl': 31}
# ############## CONNECT NIDAQ ###############
ao = ni.Analog_Out(num_channels=daq_num_channels,
rate=daq_rate,
daq_type=daq_name,
board_name=daq_board,
verbose=False)
# root window
root = tk.Tk()
# root.geometry("300x150")
root.resizable(False, False)
root.title('Voltage control')
# store voltage values
Xmax = tk.StringVar()
Xmin = tk.StringVar()
Xpp = tk.StringVar()
Ymax = tk.StringVar()
Ymin = tk.StringVar()
Ypp = tk.StringVar()
Econst = tk.StringVar()
def update_voltages():
""" callback when the login button clicked
"""
freq = 100 # Hz
duration = 1.0 # seconds
period_pix = ao.s2p(1/freq)
nFrames = freq * duration
try:
Xamp = float(Xpp.get()) / 2
Xoff = (float(Xmax.get()) + float(Xmin.get())) / 2
Yamp = float(Ypp.get()) / 2
Yoff = (float(Ymax.get()) + float(Ymin.get())) / 2
Eamp = 0.0
Eoff = float(Econst.get())
except ValueError:
msg = f'Invalid voltages, please try again'
showinfo(
title='Error',
message=msg
)
return
voltages = []
for sl in range(int(nFrames)): # add buffer for scan rampup
v = numpy.zeros((period_pix, daq_num_channels), 'float64')
# X galvo
time = numpy.linspace(0, 2*math.pi, period_pix)
v[:, n2c['xgalvo']] = 2*Xamp/math.pi*numpy.sin(time)+Xoff
# Y galvo
time = numpy.linspace(0, 2*math.pi, period_pix)
v[:, n2c['ygalvo']] = 2*Yamp/math.pi*numpy.sin(time)+Yoff
# ETL
time = numpy.linspace(0, 2*math.pi, period_pix)
v[:, n2c['etl']] = 2*Eamp/math.pi*numpy.sin(time)+Eoff
voltages.append(v)
voltages = numpy.concatenate(voltages, axis=0)
# Check final voltages for sanity
# Assert that voltages are safe
assert numpy.max(voltages[:, n2c['xgalvo']]) <= 5.0
assert numpy.min(voltages[:, n2c['xgalvo']]) >= -5.0
# assert numpy.max(voltages[:,n2c['ygalvo']]) <= 5.0
# assert numpy.min(voltages[:,n2c['ygalvo']]) >= -5.0
# assert numpy.max(voltages[:,n2c['etl']]) <= 5.0
# assert numpy.min(voltages[:,n2c['etl']]) >= 0.0
print('potato')
return voltages
# Main frame
main_frame = ttk.Frame(root)
main_frame.pack(padx=10, pady=10, fill='x', expand=True)
# Xmax
Xmax_label = ttk.Label(main_frame, text="Xmax:")
Xmax_label.pack(fill='x', expand=True)
Xmax_entry = ttk.Entry(main_frame, textvariable=Xmax)
Xmax_entry.pack(fill='x', expand=True)
Xmax_entry.insert(0, "0.0")
# Xmax_entry.focus()
# Xmin
Xmin_label = ttk.Label(main_frame, text="Xmin:")
Xmin_label.pack(fill='x', expand=True)
Xmin_entry = ttk.Entry(main_frame, textvariable=Xmin)
Xmin_entry.pack(fill='x', expand=True)
Xmin_entry.insert(0, "0.0")
# Xpp
Xpp_label = ttk.Label(main_frame, text="Xpp:")
Xpp_label.pack(fill='x', expand=True)
Xpp_entry = ttk.Entry(main_frame, textvariable=Xpp)
Xpp_entry.pack(fill='x', expand=True)
Xpp_entry.insert(0, "0.0")
# Ymax
Ymax_label = ttk.Label(main_frame, text="Ymax:")
Ymax_label.pack(fill='x', expand=True)
Ymax_entry = ttk.Entry(main_frame, textvariable=Ymax)
Ymax_entry.pack(fill='x', expand=True)
Ymax_entry.insert(0, "0.0")
# Xmax_entry.focus()
# Ymin
Ymin_label = ttk.Label(main_frame, text="Ymin:")
Ymin_label.pack(fill='x', expand=True)
Ymin_entry = ttk.Entry(main_frame, textvariable=Ymin)
Ymin_entry.pack(fill='x', expand=True)
Ymin_entry.insert(0, "0.0")
# Ypp
Ypp_label = ttk.Label(main_frame, text="Ypp:")
Ypp_label.pack(fill='x', expand=True)
Ypp_entry = ttk.Entry(main_frame, textvariable=Ypp)
Ypp_entry.pack(fill='x', expand=True)
Ypp_entry.insert(0, "0.0")
# Econst
Econst_label = ttk.Label(main_frame, text="Econst:")
Econst_label.pack(fill='x', expand=True)
Econst_entry = ttk.Entry(main_frame, textvariable=Econst)
Econst_entry.pack(fill='x', expand=True)
Econst_entry.insert(0, "0.0")
# update button
update_button = ttk.Button(main_frame, text="Update voltages",
command=update_voltages)
update_button.pack(fill='x', expand=True, pady=10)
def playV():
print('Send', Xmax.get())
ao.play_voltages(voltages, block=False)
root.after(1000, playV)
voltages = update_voltages()
playV()
root.mainloop()