forked from jaskotmb/OLED_Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOLEDTools.py
447 lines (410 loc) · 15.2 KB
/
OLEDTools.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# 180719 MBJ
# Contains functions used to talk to Keysight 34460A Multimeter
# and Keysight B2901A Source Measure Unit (SMU)
# as well as some functions used in general device testing
import time
import csv
import os
import visa
import datetime
import scipy.integrate
def integrateSpectrum(wavelengthList,intensityList,minWvl,maxWvl):
relevantWvls = [x for x in wavelengthList if x > minWvl and x < maxWvl]
for index in range(len(intensityList)):
if relevantWvls[0] == wavelengthList[index]:
break
relevantIntens = intensityList[index:index+len(relevantWvls)]
auc = scipy.integrate.cumtrapz(relevantIntens,relevantWvls)
intBegin = relevantWvls[0]
intEnd = relevantWvls[len(relevantWvls)-1]
intAvg = auc[len(auc)-1]/(intEnd-intBegin)
# print("Integration from {} to {} = {}".format(intBegin,intEnd,intSum)))
return [intAvg,intBegin,intEnd]
def getSpectrum(fileName):
# given a filename for an OO spectrum file, returns [(wavelength, intensity),...] tuple list
file = open(fileName,"r")
header= []
begchar = ''
while begchar != '>':
temp = file.readline()
header.append(temp)
begchar = temp[0]
fname = header[0].split('from ')[1].split(' ')[0]
#print("Filename: {}".format(fname))
date = header[2].split(': ')[1].split('\n')[0]
#print("Date: {}".format(date))
inttime = float(header[6].split(': ')[1].split('\n')[0])
#print("Integration Time: {} seconds".format(inttime))
scansavg = header[7].split(': ')[1].split('\n')[0]
#print("Scans Averaged: {}".format(scansavg))
wvl = []
intens = []
line = "Test"
for line in file:
lsplit = line.split('\t')
wvl.append(float(lsplit[0]))
intens.append(float(lsplit[1].split('\n')[0]))
return list(zip(wvl,intens))
def iDevice():
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
smu = rm.open_resource(B2901A)
smu.write("*RST")
print("SMU: {}".format(smu.query("*IDN?")))
def currDecay(sourceCurrent,maxTime):
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
smu = rm.open_resource(B2901A)
mm = rm.open_resource(K34460A)
smu.write("*RST")
print("SMU: {}".format(smu.query("*IDN?")))
smu.write(":SOUR:FUNC:MODE CURR")
smu.write(":SOUR:CURR:RANG 0.01")
smu.write(":SOUR:CURR {}".format(sourceCurrent))
smu.write(":SENS:FUNC 'VOLTS'")
smu.write(":SENS:VOLT:RANG 200")
smu.write(":SENS:VOLT:NPLC 1")
smu.write(":SENS:VOLT:PROT 21")
mm.write("*RST")
mm.write(":CONF:CURR:DC")
mm.write(":CURR:DC:NPLC 1")
print("{} sec left".format(maxTime))
tbegin = datetime.datetime.now()
smu.write(":OUTP ON")
voltList = []
currList = []
timeList = []
brightList = []
smu.write(":INIT")
tRun = datetime.datetime.now() - tbegin
twait = 0
ret = ""
while (tRun.seconds<maxTime):
voltList.append(smu.query(":MEAS:VOLT?").split('\n')[0])
currList.append(smu.query(":MEAS:CURR?").split('\n')[0])
brightTemp = mm.query(":MEAS:CURR?").split('\n')[0]
brightList.append(brightTemp)
if float(brightTemp) < .005e-6:
print("No Output! Breaking Decay Loop...")
ret = "fail"
break
tRun = datetime.datetime.now() - tbegin
timeList.append(tRun.seconds+(1E-6)*tRun.microseconds)
time.sleep(twait)
smu.write(":OUTP OFF")
outList = list(zip(timeList,voltList,currList,brightList))
smu.write(":OUTP OFF")
if ret != "fail":
return outList
if ret == "fail":
return "fail"
def biasVoltsTime(totalTime,bias):
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
smu = rm.open_resource(B2901A_address)
smu.timeout = 5000000
print("Reverse Biasing at {}V for {}sec".format(bias,totalTime))
smu.write("*RST")
print("SMU: {}".format(smu.query("*IDN?")))
tbegin = datetime.datetime.now()
smu.write(":OUTP ON")
smu.write(":SOUR:FUNC:MODE VOLT")
smu.write(":SOUR:VOLT:RANG 20")
smu.write(":SOUR:VOLT {}".format(bias))
smu.write(":SENS:FUNC 'CURR'")
smu.write(":SENS:CURR:NPLC 1")
smu.write(":SENS:CURR:PROT .005")
tRun = datetime.datetime.now() - tbegin
twait = .5
smu.write(':INIT')
while (tRun.seconds<totalTime):
smu.query(":MEAS:CURR?")
tRun = datetime.datetime.now() - tbegin
time.sleep(twait)
smu.write(':OUTP OFF')
def findTurnOnVoltage(Vbegin, Vend, stepVolts, maxCurr, brThreshold):
#Does Linear sweep until V_TurnOn, then returns linear data with V_TurnOn as last data point
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
smu = rm.open_resource(B2901A_address)
mm = rm.open_resource(MM_34460_address)
step = abs(round((Vend-Vbegin) / stepVolts)) + 1
print("step: {}".format(step))
print("StepVolts: {}".format(stepVolts))
mm.timeout = 5000000
smu.timeout = 5000000
aperture = .15
nplcTime = 1
smu.write(":SOUR:FUNC:MODE VOLT")
smu.write(":SOUR:VOLT:MODE SWE")
smu.write(":SOUR:VOLT:RANG 20")
smu.write(":SOUR:VOLT:STAR {}".format(Vbegin))
smu.write(":SOUR:VOLT:STOP {}".format(Vend))
smu.write(":SOUR:VOLT:POIN {}".format(step))
smu.write(":SOUR:SWE:DIR UP")
smu.write(":SOUR:SWE:SPAC LIN")
mm.write('*RST')
mm.write(':CONF:CURR:DC')
mm.write(':CURR:DC:NPLC {}'.format(nplcTime))
mm.write(':TRIG:COUN {}'.format(step))
mm.write(':TRIG:SOUR EXT')
mm.write(':TRIG:DEL .01')
mm.write(':INIT')
smu.write(':SENS:FUNC ""CURR""')
smu.write(':SENS:CURR:RANG:AUTO ON')
smu.write(':SENS:CURR:APER {}'.format(aperture))
smu.write(':SENS:CURR:PROT {}'.format(maxCurr))
smu.write(':FORM:DATA ASC')
smu.write(':TRIG:SOUR AINT')
smu.write(':TRIG:COUN {}'.format(step))
smu.write(":TRIG:DEL .01")
smu.write(':OUTP ON')
smu.write(":SOUR:TOUT:STAT ON")
smu.write(":SOUR:TOUT:SIGN EXT3")
smu.write(":SOUR:DIG:EXT3:FUNC DIO")
smu.write(":SOUR:DIG:EXT3:TOUT:EDGE:POS BEF")
smu.write(':INIT (@1)')
brightCurr = mm.query(":FETC?").split(',')
measCurr = smu.query(':FETC:ARR:CURR? (@1)').split(',')
sourceVolts = smu.query(':FETC:ARR:VOLT? (@1)').split(',')
indexThr = False
if [x for x in brightCurr if float(x)>brThreshold]:
indexThr = brightCurr.index([x for x in brightCurr if float(x)>brThreshold][0])
print("indexThr = {}".format(indexThr))
print("brightCurr at this index = {}".format(brightCurr[indexThr]))
print("sourceVolts at this index = {}".format(sourceVolts[indexThr]))
else:
print("Turn-on Voltage not in range!")
smu.write(':OUTP OFF')
VIBList = list(zip(sourceVolts,measCurr,brightCurr))
if [x for x in brightCurr if float(x)>brThreshold]:
return sourceVolts[indexThr]
def IVBSweep(step, maxCurr, voltList):
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
smu = rm.open_resource(B2901A_address)
mm = rm.open_resource(MM_34460_address)
mm.timeout = 50000000
smu.timeout = 50000000
aperture = .04
nplcTime = 1
newSweep = 1
listString = ','.join(str(x) for x in voltList)
if newSweep == 1:
smu.write("*RST")
smu.write(":SOUR:FUNC:MODE VOLT")
smu.write(":SOUR:VOLT:RANG 20")
smu.write(":SOUR:VOLT:MODE LIST")
smu.write(":SOUR:LIST:VOLT {}".format(listString))
print("Foo1")
mm.write('*RST')
mm.write(':CONF:CURR:DC')
mm.write(':CURR:DC:NPLC {}'.format(nplcTime))
mm.write(':TRIG:COUN {}'.format(len(voltList)))
mm.write(':TRIG:SOUR EXT')
mm.write(':TRIG:DEL .005')
mm.write(':SAMP:SOUR TIM')
mm.write(':SAMP:TIM 0.01')
mm.write(':SAMP:COUN 1')
mm.write(':INIT')
print("Foo2")
smu.write(':SENS:FUNC ""CURR""')
smu.write(':SENS:CURR:RANG:AUTO ON')
smu.write(':SENS:CURR:APER {}'.format(aperture))
smu.write(':SENS:CURR:PROT {}'.format(maxCurr))
smu.write(':FORM:DATA ASC')
smu.write(':TRIG:SOUR AINT')
smu.write(':TRIG:TIM .1')
smu.write(':TRIG:COUN {}'.format(len(voltList)))
smu.write(":TRIG:MEAS:DEL .005")
smu.write(':OUTP ON')
smu.write(":SOUR:TOUT:STAT ON")
smu.write(":SOUR:TOUT:SIGN EXT3")
smu.write(":SOUR:DIG:EXT3:FUNC DIO")
smu.write(":SOUR:DIG:EXT3:TOUT:EDGE:POS BEF")
smu.write(':INIT (@1)')
print("Foo3")
brightCurr = mm.query(":FETC?").split(',')
print(brightCurr)
print(len(brightCurr))
measCurr = smu.query(':FETC:ARR:CURR? (@1)').split(',')
sourceVolts = smu.query(':FETC:ARR:VOLT? (@1)').split(',')
#sourceVolts = [item for item in sourceVolts for i in range(3)]
#measCurr = [item for item in measCurr for i in range(3)]
print(measCurr)
print(len(measCurr))
print(sourceVolts)
print(len(sourceVolts))
print("Foo4")
smu.write(':OUTP OFF')
VIBList = list(zip(sourceVolts,measCurr,brightCurr))
return VIBList
def IVBSweepCurr(step, maxVolts, currList):
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
smu = rm.open_resource(B2901A_address)
mm = rm.open_resource(MM_34460_address)
mm.timeout = 5000000
smu.timeout = 5000000
aperture = .04
nplcTime = .2
newSweep = 1
listString = ','.join(str(x) for x in currList)
if newSweep == 1:
smu.write(":SOUR:FUNC:MODE CURR")
smu.write(":SOUR:CURR:RANG 1e-2")
smu.write(":SOUR:CURR:MODE LIST")
smu.write(":SOUR:LIST:CURR {}".format(listString))
mm.write('*RST')
mm.write(':CONF:CURR:DC')
mm.write(':CURR:DC:NPLC {}'.format(nplcTime))
mm.write(':TRIG:COUN {}'.format(len(currList)))
mm.write(':TRIG:SOUR EXT')
mm.write(':TRIG:DEL .005')
mm.write(':SAMP:SOUR TIM')
mm.write(':SAMP:TIM 0.01')
mm.write(':SAMP:COUN 1')
mm.write(':INIT')
smu.write(':SENS:FUNC ""VOLT""')
smu.write(':SENS:VOLT:RANG:AUTO ON')
smu.write(':SENS:VOLT:APER {}'.format(aperture))
smu.write(':SENS:VOLT:PROT {}'.format(maxVolts))
smu.write(':FORM:DATA ASC')
smu.write(':TRIG:SOUR AINT')
smu.write(':TRIG:TIM .1')
smu.write(':TRIG:COUN {}'.format(len(currList)))
smu.write(":TRIG:MEAS:DEL .005")
smu.write(':OUTP ON')
smu.write(":SOUR:TOUT:STAT ON")
smu.write(":SOUR:TOUT:SIGN EXT3")
smu.write(":SOUR:DIG:EXT3:FUNC DIO")
smu.write(":SOUR:DIG:EXT3:TOUT:EDGE:POS BEF")
smu.write(':INIT (@1)')
brightCurr = mm.query(":FETC?").split(',')
print(brightCurr)
print(len(brightCurr))
measCurr = smu.query(':FETC:ARR:CURR? (@1)').split(',')
sourceVolts = smu.query(':FETC:ARR:VOLT? (@1)').split(',')
#sourceVolts = [item for item in sourceVolts for i in range(3)]
#measCurr = [item for item in measCurr for i in range(3)]
print(measCurr)
print(len(measCurr))
print(sourceVolts)
print(len(sourceVolts))
smu.write(':OUTP OFF')
VIBList = list(zip(sourceVolts,measCurr,brightCurr))
return VIBList
# Executes a linear IV sweep and returns IV output
def LinSweepSMU(Vbegin, Vend, samplePoints, stepT, maxCurr):
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
smu = rm.open_resource(B2901A_address)
totalTime = (stepT+.005)*samplePoints
smu.write('*RST')
print("SMU: {}".format(smu.query("*IDN?")))
smu.write(':SOUR:FUNC:MODE VOLT')
smu.write(':SOUR:VOLT:MODE SWE')
smu.write(':SOUR:VOLT:RANG 20')
smu.write(':SOUR:VOLT:STAR {}'.format(Vbegin))
smu.write(':SOUR:VOLT:STOP {}'.format(Vend))
smu.write(':SOUR:VOLT:POIN {}'.format(samplePoints))
smu.write(':SOUR:SWE:DIR UP')
smu.write(':SOUR:SWE:SPAC LIN')
smu.write(':SOUR:SWE:STA SING')
smu.write(':SENS:FUNC ""CURR""')
smu.write(':SENS:CURR:RANG:AUTO ON')
smu.write(':SENS:CURR:APER {}'.format(stepT))
smu.write(':SENS:CURR:PROT {}'.format(maxCurr))
smu.write(':FORM:DATA ASC')
smu.write(':TRIG:SOUR AINT')
smu.write(':TRIG:COUN {}'.format(samplePoints))
smu.write(':OUTP ON')
smu.write(':INIT (@1)')
time.sleep(totalTime)
measCurr = smu.query(':FETC:ARR:CURR? (@1)').split(',')
sourceVolts = smu.query(':FETC:ARR:VOLT? (@1)').split(',')
VIpairs = list(zip(sourceVolts,measCurr))
return VIpairs
# Closes connection to SMU:
def SMUclose():
rm = visa.ResourceManager()
for i in rm.list_resources():
if "0x0957" in i:
B2901A_address = i
for i in rm.list_resources():
if "0x2A8D" in i:
MM_34460_address = i
mm = rm.open_resource(MM_34460_address)
smu = rm.open_resource(B2901A_address)
smu.write(':OUTP OFF')
smu.close()
mm.close()
# Returns a string of the current time: "YYYYMMDD-HH-mm-ss"
def stringTime():
startTime = time.localtime()
s = str(startTime.tm_year) + str(startTime.tm_mon).zfill(2) + str(startTime.tm_mday).zfill(2) + '-' + str(
startTime.tm_hour).zfill(2) + '-' + str(startTime.tm_min).zfill(2) + '-' + str(startTime.tm_sec).zfill(2)
return s
# Creates a directory (if none exists) with today's date: "YYYYMMDD"
# then moves cwd to that directory
def makeTodayDir():
todayName = stringTime()[0:8]
if not os.path.exists(todayName):
os.mkdir(todayName)
print("Created Directory for today: {}\\{}".format(os.getcwd(),todayName))
os.chdir(todayName)
print("Changed Directory to: {}".format(os.getcwd()))
return
# Outputs IV data to a .csv
def writeMobility(fn,data):
with open(fn, 'w',newline='') as csvfile:
writer = csv.writer(csvfile)
row1 = ["Voltage (V)","Current (A)"]
writer.writerow(row1)
for row in data:
writer.writerow(row)
# Outputs IV-Brightness data to a .csv
def writeIVB(fn,data):
with open(fn, 'w',newline='') as csvfile:
writer = csv.writer(csvfile)
row1 = ["Voltage (V)","Current (A)","Brightness Current (A)"]
writer.writerow(row1)
for row in data:
writer.writerow(row)
# Outputs IV-Brightness Decay data to a .csv
def writeIVBDecay(fn,data):
with open(fn, 'w',newline='') as csvfile:
writer = csv.writer(csvfile)
row1 = ["Time (sec)","Voltage (V)","Current (A)","Brightness Current (A)"]
writer.writerow(row1)
for row in data:
writer.writerow(row)