-
Notifications
You must be signed in to change notification settings - Fork 2
/
SR830.py
349 lines (311 loc) · 12.5 KB
/
SR830.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# -*- coding: utf-8 -*-
# Stanford Research Systems SR830 controller
# Version 1.0 (2017-05-08)
# Daan Wielens (ICE/QTM)
import sys
import time
import requests
try:
# These modules will import succesfully for Python 2.x
import Tkinter
import ttk
import tkMessageBox as messagebox
import tkFont as font
except ImportError:
# For Python 3.x, we need these (renamed) modules
import tkinter as Tkinter
from tkinter import ttk
from tkinter import messagebox
from tkinter import font
novisa = 0
# Testing GUI on a pc without VISA:
if len(sys.argv) == 2:
if sys.argv[1] == '--novisa':
novisa = 1
else:
print('Warning: your input argument (' + sys.argv[1] + ') is not recognized by this program and will be ignored. Please use --novisa if you want to simulate the GUI.')
# Initialise VISA
if novisa == 0:
import visa
rm = visa.ResourceManager()
# Dictionaries
global sensitivities
sensitivities = {
'0': '2 nV',
'1': '5 nV',
'2': '10 nV',
'3': '20 nV',
'4': '50 nV',
'5': '100 nV',
'6': '200 nV',
'7': '500 nV',
'8': '1 uV',
'9': '2 uV',
'10': '5 uV',
'11': '10 uV',
'12': '20 uV',
'13': '50 uV',
'14': '100 uV',
'15': '200 uV',
'16': '500 uV',
'17': '1 mV',
'18': '2 mV',
'19': '5 mV',
'20': '10 mV',
'21': '20 mV',
'22': '50 mV',
'23': '100 mV',
'24': '200 mV',
'25': '500 mV',
'26': '1 V',
}
timeconstants = {
'0': '10 us',
'1': '30 us',
'2': '100 us',
'3': '300 us',
'4': '1 ms',
'5': '3 ms',
'6': '10 ms',
'7': '30 ms',
'8': '100 ms',
'9': '300 ms',
'10': '1 s',
'11': '3 s',
'12': '10 s',
'13': '30 s',
'14': '100 s',
'15': '300 s',
'16': '1 ks',
'17': '3 ks',
'18': '10 ks',
'19': '30 ks',
}
inputsources = {
'0': 'A',
'1': 'A-B',
'2': 'I (1 MΩ)',
'3': 'I (100 MΩ)',
}
inputground = {
'0': 'Float',
'1': 'Ground',
}
inputcoupling = {
'0': 'AC',
'1': 'DC',
}
reserves = {
'0': 'High reserve',
'1': 'Normal',
'2': 'Low noise',
}
references = {
'0': 'External',
'1': 'Internal',
}
def convertUnits(inputval):
# Check if number is written as scientific value
numberlist = inputval.split('e')
if len(numberlist) == 1:
return inputval
prefix = float(numberlist[0])
suffix = int(numberlist[1])
if suffix < -6:
multiplier = 9-abs(suffix)
prefix = prefix * 10**multiplier
value = str("%.3f" % prefix) + ' n'
return value
if suffix < -3 and suffix >= -6:
multiplier = 6-abs(suffix)
prefix = prefix * 10**multiplier
value = str("%.3f" % prefix) + ' u'
return value
if suffix < 0 and suffix >= -3:
multiplier = 3-abs(suffix)
prefix = prefix * 10**multiplier
value = str("%.3f" % prefix) + ' m'
return value
def SetGPIB():
global GPIBaddress
GPIBaddress = setGPIBtxt.get().replace('\n','').replace('\r','')
try:
GPIBaddress = int(GPIBaddress)
except Exception:
messagebox.showerror("Error","The GPIB address must be an integer value.")
setGPIBtxt.delete(0, Tkinter.END)
return
if novisa == 0:
SR = rm.open_resource("GPIB0::" + str(GPIBaddress) + "::INSTR")
# Check if GPIB address points to a SR830 system
try:
identifier = SR.query("*IDN?")
except Exception:
messagebox.showerror('Error','There is no device responding to this GPIB address.')
setGPIBtxt.delete(0, Tkinter.END)
return
if identifier.split(',')[1] != 'SR830':
messagebox.showerror("Error","The selected GPIB address does not point to a SR830 system.")
setGPIBtxt.delete(0, Tkinter.END)
return
ReadSettings()
ReadValues()
def ReadSettings():
global tConst
global Sensi
global sigInSrc
global sigInGnd
global sigInCpl
global Resrv
global Refsrc
# Check if GPIB address is set
if 'GPIBaddress' not in globals():
messagebox.showerror("Error","Please set a GPIB address before trying to read settings.")
return
if novisa == 0:
SR = rm.open_resource("GPIB0::" + str(GPIBaddress) + "::INSTR")
getTimeconst = SR.query('OFLT?').replace('\n','').replace('\r','')
txtTimec = str(getTimeconst)
tConst.set(timeconstants[txtTimec])
getSensitiv = SR.query('SENS?').replace('\n','').replace('\r','')
txtSensitiv = str(getSensitiv)
Sensi.set(sensitivities[txtSensitiv])
getInpSrc = SR.query('ISRC?').replace('\n','').replace('\r','')
txtInpSrc = str(getInpSrc)
sigInSrc.set('Input: ' + inputsources[txtInpSrc])
getInpGnd = SR.query('IGND?').replace('\n','').replace('\r','')
txtInpGnd = str(getInpGnd)
sigInGnd.set('Grounding: ' + inputground[txtInpGnd])
getInpCpl = SR.query('ICPL?').replace('\n','').replace('\r','')
txtInpCpl = str(getInpCpl)
sigInCpl.set('Coupling: ' + inputcoupling[txtInpCpl])
getResrv = SR.query('RMOD?').replace('\n','').replace('\r','')
txtResrv = str(getResrv)
Resrv.set(reserves[txtResrv])
getRefsrc = SR.query('FMOD?').replace('\n','').replace('\r','')
txtRefsrc = str(getRefsrc)
Refsrc.set(references[txtRefsrc])
SR.close()
else:
tConst.set('noVISA')
Sensi.set('noVISA')
sigInSrc.set('noVISA')
sigInGnd.set('noVISA')
sigInCpl.set('noVISA')
Resrv.set('noVISA')
Refsrc.set('noVISA')
def ReadValues():
global readX
global readY
global readTheta
global readFreq
global readAmpl
# Check if GPIB address is set
if 'GPIBaddress' not in globals():
messagebox.showerror("Error","Please set a GPIB address before trying to read values.")
return
if novisa == 0:
SR = rm.open_resource("GPIB0::" + str(GPIBaddress) + "::INSTR")
getData = SR.query('SNAP?1,2,4,9').replace('\n','').replace('\r','')
txtData = str(getData)
numberX = txtData.split(',')[0]
numberY = txtData.split(',')[1]
numberX = convertUnits(numberX)
numberY = convertUnits(numberY)
readX.set(numberX + 'V')
readY.set(numberY + 'V')
readTheta.set(txtData.split(',')[2] + ' deg')
readFreq.set(txtData.split(',')[3] + ' Hz')
getAmpl = SR.query('SLVL?').replace('\n','').replace('\r','')
txtAmpl = str(getAmpl)
readAmpl.set(txtAmpl + ' V')
SR.close()
else:
readX.set('noVISA')
readY.set('noVISA')
readTheta.set('noVISA')
readFreq.set('noVISA')
readAmpl.set('noVISA')
# Create GUI
top = Tkinter.Tk()
top.lift()
top.title('SR830 Controller')
# Title bar
titleFont = font.Font(family="Helvetica", size=16, weight="bold")
titleText = Tkinter.Label(top, text="SR830 Controller", fg="white", bg="#a6211f", font=titleFont).grid(row=0, columnspan=1000, sticky=Tkinter.W+Tkinter.E)
vLine1 = Tkinter.Frame(top, bg="black", width=675, height=1).grid(row=1, columnspan=1000)
# Main area
lblFont = font.Font(family="Helvetica", size=12)
headFont = font.Font(family="Helvetica", size=14, weight="bold")
# Program settings frame
fSettings = Tkinter.Frame(top, width=400, height=400, relief=Tkinter.RIDGE, borderwidth=3)
fSettings.grid(row=2, padx=3, pady=3, sticky=Tkinter.W+Tkinter.N, columnspan=1000)
lblSetHead = Tkinter.Label(fSettings, text="Program settings:", font=headFont).grid(row=3, sticky=Tkinter.W+Tkinter.N)
lblSetGPIB = Tkinter.Label(fSettings, text="GPIB address: [int]", font=lblFont).grid(row=4, sticky=Tkinter.W+Tkinter.N)
global setGPIBtxt
setGPIBtxt = Tkinter.Entry(fSettings,exportselection=0)
setGPIBtxt.grid(row=4, column=1, sticky=Tkinter.W+Tkinter.N)
btnSetGPIB = Tkinter.Button(fSettings, text="Set GPIB", command=SetGPIB).grid(row=4, column=2, columnspan=1000)
# Information frame
fInfo = Tkinter.Frame(top, width=400, height=400, relief=Tkinter.RIDGE, borderwidth=3)
fInfo.grid(row=5, padx=3, pady=3, sticky=Tkinter.W+Tkinter.N)
lblHeader = Tkinter.Label(fInfo, text="Lock-In settings:", font=headFont).grid(row=6, sticky=Tkinter.W+Tkinter.N)
lblL1 = Tkinter.Label(fInfo, text="Time constant: ", font=lblFont).grid(row=7, sticky=Tkinter.W+Tkinter.N)
lblL2 = Tkinter.Label(fInfo, text="Sensitivity: ", font=lblFont).grid(row=8,sticky=Tkinter.W+Tkinter.N, pady=(3,0))
vLine2 = Tkinter.Frame(fInfo, bg="black", width=400, height=1).grid(row=9, columnspan=1000)
lblL3 = Tkinter.Label(fInfo, text="Signal input: ", font=lblFont).grid(row=10, sticky=Tkinter.W+Tkinter.N)
lblL4 = Tkinter.Label(fInfo, text="Reserve: ", font=lblFont).grid(row=13, sticky=Tkinter.W+Tkinter.N)
lblL5 = Tkinter.Label(fInfo, text="Reference source: ", font=lblFont).grid(row=14, sticky=Tkinter.W+Tkinter.N)
tConst = Tkinter.StringVar()
tConst.set("...,.. ms")
lblV1 = Tkinter.Label(fInfo, textvariable=tConst, font=lblFont).grid(row=7, column=1, columnspan=1000, sticky=Tkinter.W)
Sensi = Tkinter.StringVar()
Sensi.set("...,.. mV")
lblV2 = Tkinter.Label(fInfo, textvariable=Sensi, font=lblFont).grid(row=8, column=1, columnspan=1000, sticky=Tkinter.W)
sigInSrc = Tkinter.StringVar()
sigInSrc.set("....,....,....")
lblV3 = Tkinter.Label(fInfo, textvariable=sigInSrc, font=lblFont).grid(row=10, column=1, columnspan=1000, sticky=Tkinter.W)
sigInGnd = Tkinter.StringVar()
sigInGnd.set("....,....,....")
lblV3 = Tkinter.Label(fInfo, textvariable=sigInGnd, font=lblFont).grid(row=11, column=1, columnspan=1000, sticky=Tkinter.W)
sigInCpl = Tkinter.StringVar()
sigInCpl.set("....,....,....")
lblV3 = Tkinter.Label(fInfo, textvariable=sigInCpl, font=lblFont).grid(row=12, column=1, columnspan=1000, sticky=Tkinter.W)
Resrv = Tkinter.StringVar()
Resrv.set("........")
lblV4 = Tkinter.Label(fInfo, textvariable=Resrv, font=lblFont).grid(row=13, column=1, columnspan=1000, sticky=Tkinter.W)
Refsrc = Tkinter.StringVar()
Refsrc.set("........")
lblV5 = Tkinter.Label(fInfo, textvariable=Refsrc, font=lblFont).grid(row=14, column=1, columnspan=1000, sticky=Tkinter.W)
# Readings frame
fRead = Tkinter.Frame(top, width=400, height=400, relief=Tkinter.RIDGE, borderwidth=3)
fRead.grid(row=5, column=2, padx=(0, 3), pady=3, sticky=Tkinter.W+Tkinter.N)
lblHeader = Tkinter.Label(fRead, text="Data values:", font=headFont).grid(row=6, sticky=Tkinter.W+Tkinter.N)
lblL1 = Tkinter.Label(fRead, text="X: ", font=lblFont).grid(row=7, sticky=Tkinter.W+Tkinter.N)
lblL2 = Tkinter.Label(fRead, text="Y: ", font=lblFont).grid(row=8,sticky=Tkinter.W+Tkinter.N, pady=(3,0))
vLine2 = Tkinter.Frame(fRead, bg="black", width=250, height=1).grid(row=9, columnspan=1000)
lblL3 = Tkinter.Label(fRead, text="Theta: ", font=lblFont).grid(row=10, sticky=Tkinter.W+Tkinter.N)
lblL4 = Tkinter.Label(fRead, text="Frequency: ", font=lblFont).grid(row=11, sticky=Tkinter.W+Tkinter.N)
lblL5 = Tkinter.Label(fRead, text="Sine amplitude: ", font=lblFont).grid(row=12, sticky=Tkinter.W+Tkinter.N)
readX = Tkinter.StringVar()
readX.set('....,.. V')
lvlV1 = Tkinter.Label(fRead, textvariable=readX, font=lblFont).grid(row=7, column=1, columnspan=1000, sticky=Tkinter.W)
readY = Tkinter.StringVar()
readY.set('....,.. V')
lvlV2 = Tkinter.Label(fRead, textvariable=readY, font=lblFont).grid(row=8, column=1, columnspan=1000, sticky=Tkinter.W)
readTheta = Tkinter.StringVar()
readTheta.set('....,.. deg')
lvlV3 = Tkinter.Label(fRead, textvariable=readTheta, font=lblFont).grid(row=10, column=1, columnspan=1000, sticky=Tkinter.W)
readFreq = Tkinter.StringVar()
readFreq.set('....,.. Hz')
lvlV4 = Tkinter.Label(fRead, textvariable=readFreq, font=lblFont).grid(row=11, column=1, columnspan=1000, sticky=Tkinter.W)
readAmpl = Tkinter.StringVar()
readAmpl.set('....,.. Hz')
lvlV5 = Tkinter.Label(fRead, textvariable=readAmpl, font=lblFont).grid(row=12, column=1, columnspan=1000, sticky=Tkinter.W)
# Buttons
fButton = Tkinter.Frame(top, width=400, height=400)
fButton.grid(row=15, pady=3, sticky=Tkinter.N+Tkinter.W)
btnReadSettings = Tkinter.Button(fButton, text="Read settings", command=ReadSettings).grid(row=16, column=0, sticky=Tkinter.W)
btnReadValues = Tkinter.Button(fButton, text="Read data values", command=ReadValues).grid(row=16, column=1, sticky=Tkinter.W)
# Main loop
top.mainloop()