-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathofetMeasureGUI.py
635 lines (534 loc) · 23.9 KB
/
ofetMeasureGUI.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
"""
Qt5 GUI for making OFET measurements with a Keithley 2636.
Author: Ross <peregrine dot warren at physics dot ox dot ac dot uk>
"""
import k2636 # Driver for keithley 2636
import sys
import fnmatch
import pandas as pd
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtWidgets import (QMainWindow, QDockWidget, QWidget, QDesktopWidget,
QApplication, QGridLayout, QPushButton, QLabel,
QDoubleSpinBox, QAction, qApp, QSizePolicy,
QTextEdit, QFileDialog, QInputDialog, QLineEdit,
QMessageBox)
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as mplToolb
import matplotlib.style as style
from matplotlib.figure import Figure
matplotlib.use("Qt5Agg")
class mainWindow(QMainWindow):
"""Create mainwindow of GUI."""
def __init__(self):
"""Initalise mainwindow."""
super().__init__()
self.initUI()
def initUI(self):
"""Make signal connections."""
# Add central widget
self.mainWidget = mplWidget()
self.setCentralWidget(self.mainWidget)
# Add other window widgets
self.keithleySettingsWindow = keithleySettingsWindow()
self.keithleyConnectionWindow = keithleyConnectionWindow()
self.keithleyErrorWindow = keithleyErrorWindow()
self.popupWarning = warningWindow()
# Dock setup
# Keithley dock widget
self.buttonWidget = keithleyButtonWidget()
self.dockWidget1 = QDockWidget('Keithley Control')
self.dockWidget1.setWidget(self.buttonWidget)
self.addDockWidget(Qt.BottomDockWidgetArea, self.dockWidget1)
# Matplotlib control widget
self.dockWidget2 = QDockWidget('Plotting controls')
self.dockWidget2.setWidget(mplToolb(self.mainWidget, self))
self.addDockWidget(Qt.BottomDockWidgetArea, self.dockWidget2)
# Menu bar setup
# Shutdown program
exitAction = QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
# Load old data
loadAction = QAction('&Load', self)
loadAction.setShortcut('Ctrl+L')
loadAction.setStatusTip('Load data to be displayed')
loadAction.triggered.connect(self.showFileOpen)
# Load old ALL data
loadALLAction = QAction('&Load ALL', self)
loadALLAction.setShortcut('Ctrl+A')
loadALLAction.setStatusTip(
'Load iv, output and transfer data to be displayed')
loadALLAction.triggered.connect(self.showFileOpenALL)
# Clear data
clearAction = QAction('Clear', self)
clearAction.setShortcut('Ctrl+C')
clearAction.setStatusTip('Clear data on graph')
clearAction.triggered.connect(self.mainWidget.clear)
# Keithley settings popup
keithleyAction = QAction('Settings', self)
keithleyAction.setShortcut('Ctrl+K')
keithleyAction.setStatusTip('Adjust scan parameters')
keithleyConAction = QAction('Connect', self)
keithleyConAction.setShortcut('Ctrl+J')
keithleyConAction.setStatusTip('Reconnect to keithley 2636')
keithleyAction.triggered.connect(self.keithleySettingsWindow.show)
keithleyConAction.triggered.connect(self.keithleyConnectionWindow.show)
keithleyError = QAction('Error Log', self)
keithleyError.setShortcut('Ctrl+E')
keithleyError.triggered.connect(self.keithleyErrorWindow.show)
# Add items to menu bars
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(loadAction)
fileMenu.addAction(loadALLAction)
fileMenu.addAction(clearAction)
fileMenu.addSeparator()
fileMenu.addAction(exitAction)
keithleyMenu = menubar.addMenu('&Keithley')
keithleyMenu.addAction(keithleyConAction)
keithleyMenu.addAction(keithleyAction)
keithleyMenu.addAction(keithleyError)
# Status bar setup
self.statusbar = self.statusBar()
# Attempt to connect to a keithley
self.testKeithleyConnection()
self.keithleyConnectionWindow.connectionSig.connect
(self.buttonWidget.showButtons)
# Window setup
self.resize(800, 800)
self.centre()
self.setWindowTitle('K2636 - OFET Measurements')
self.show()
def testKeithleyConnection(self):
"""Connect to the keithley on initialisation."""
try:
self.keithley = k2636.K2636(address='ASRL/dev/ttyUSB0',
read_term='\n', baudrate=57600)
self.statusbar.showMessage('Keithley found.')
self.buttonWidget.showButtons()
self.keithley.closeConnection()
except ConnectionError:
self.buttonWidget.hideButtons()
self.statusbar.showMessage('No keithley connection.')
def centre(self):
"""Find screen size and place in centre."""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2,
(screen.height()-size.height())/2)
def showFileOpen(self):
"""Pop up for file selection."""
filt1 = '*.csv'
fname = QFileDialog.getOpenFileName(self, 'Open file', filter=filt1)
if fname[0]:
try:
df = pd.read_csv(fname[0], '\t')
if fnmatch.fnmatch(fname[0], '*iv-sweep.csv'):
self.mainWidget.drawIV(df)
elif fnmatch.fnmatch(fname[0], '*output.csv'):
self.mainWidget.drawOutput(df)
elif fnmatch.fnmatch(fname[0], '*transfer.csv'):
self.mainWidget.drawTransfer(df)
elif fnmatch.fnmatch(fname[0], '*gate-leakage.csv'):
self.mainWidget.drawLeakage(df)
elif fnmatch.fnmatch(fname[0], '*inverter.csv'):
self.mainWidget.drawInverter(df)
else:
raise FileNotFoundError
except KeyError or FileNotFoundError:
self.popupWarning.showWindow('Unsupported file.')
def showFileOpenALL(self):
"""Pop up for file selection for ALL measurements."""
filt1 = '*.csv'
fname = QFileDialog.getOpenFileName(self, 'Open file', filter=filt1)
if fname[0]:
try:
fileN = fname[0]
if fnmatch.fnmatch(fname[0], '*iv-sweep.csv'):
fileN = fileN[:-13]
elif fnmatch.fnmatch(fname[0], '*output.csv'):
fileN = fileN[:-11]
elif fnmatch.fnmatch(fname[0], '*transfer.csv'):
fileN = fileN[:-21]
elif fnmatch.fnmatch(fname[0], '*gate-leakage.csv'):
fileN = fileN[:-17]
elif fnmatch.fnmatch(fname[0], '*inverter.csv'):
fileN = fileN[:-13]
self.mainWidget.drawAll(fileN)
except KeyError or FileNotFoundError:
self.popupWarning.showWindow('Unsupported file.')
def updateStatusbar(slf, s):
"""Put text in status bar."""
self.statusbar.showMessage(s)
class keithleyButtonWidget(QWidget):
"""Defines class with buttons controlling keithley."""
# Define signals to be emitted from widget
cancelSignal = pyqtSignal()
def __init__(self):
"""Initialise setup of widget."""
super().__init__()
self.initWidget()
def initWidget(self):
"""Initialise connections."""
# Set widget layout
grid = QGridLayout()
self.setLayout(grid)
# Push button setup
self.ivBtn = QPushButton('IV Sweep')
grid.addWidget(self.ivBtn, 1, 1)
self.ivBtn.clicked.connect(self.showSampleNameInput)
self.outputBtn = QPushButton('Output Sweep')
grid.addWidget(self.outputBtn, 1, 2)
self.outputBtn.clicked.connect(self.showSampleNameInput)
self.transferBtn = QPushButton('Transfer Sweep')
grid.addWidget(self.transferBtn, 1, 3)
self.transferBtn.clicked.connect(self.showSampleNameInput)
self.allBtn = QPushButton('ALL')
grid.addWidget(self.allBtn, 1, 4)
self.allBtn.clicked.connect(self.showSampleNameInput)
self.inverterBtn = QPushButton('Voltage Inverter')
grid.addWidget(self.inverterBtn, 2, 1)
self.inverterBtn.clicked.connect(self.inverterPopup)
self.inverterBtn.clicked.connect(self.showSampleNameInput)
def showSampleNameInput(self):
"""Popup for sample name input."""
samNam = QInputDialog()
try:
text, ok = samNam.getText(self, 'Sample Name',
'Enter sample name:',
QLineEdit.Normal,
str(self.SampleName))
except AttributeError:
text, ok = samNam.getText(self, 'Sample Name',
'Enter sample name:')
if ok:
if text != '': # to catch empty input
self.SampleName = str(text)
else:
self.SampleName = None
self.cancelSignal.emit() # doesnt link to anything yet
def inverterPopup(self):
"""Popup for inverter setup change."""
inverterWarn = QMessageBox()
inverterWarn.setText('WARNING: Make sure correct wiring' +
' for this measurement')
inverterWarn.exec()
def hideButtons(self):
"""Hide control buttons."""
self.ivBtn.setEnabled(False)
self.outputBtn.setEnabled(False)
self.transferBtn.setEnabled(False)
self.allBtn.setEnabled(False)
self.inverterBtn.setEnabled(False)
def showButtons(self):
"""Show control buttons."""
self.ivBtn.setEnabled(True)
self.outputBtn.setEnabled(True)
self.transferBtn.setEnabled(True)
self.allBtn.setEnabled(True)
self.inverterBtn.setEnabled(True)
class mplWidget(FigureCanvas):
"""Widget for matplotlib figure."""
def __init__(self, parent=None):
"""Create plotting widget."""
self.initWidget()
def initWidget(self, parent=None, width=5, height=4, dpi=100):
"""Set parameters of plotting widget."""
style.use('ggplot') # Looks the best?
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.ax1 = self.fig.add_subplot(111)
self.ax1.set_title('IV Sweep')
self.ax1.set_xlabel('Channel Voltage [V]')
self.ax1.set_ylabel('Channel Current [A]')
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
def drawIV(self, df):
"""Take a data frame and draw it."""
self.ax1 = self.fig.add_subplot(111)
self.ax1.plot(df['Channel Voltage [V]'], df['Channel Current [A]'],
'.')
self.ax1.set_title('IV Sweep')
self.ax1.set_xlabel('Channel Voltage [V]')
self.ax1.set_ylabel('Channel Current [A]')
FigureCanvas.draw(self)
def drawOutput(self, df):
"""Take a data frame and draw it."""
self.ax1 = self.fig.add_subplot(111)
self.ax1.plot(df['Channel Voltage [V]'], df['Channel Current [A]'],
'.')
self.ax1.set_title('Output curves')
self.ax1.set_xlabel('Channel Voltage [V]')
self.ax1.set_ylabel('Channel Current [A]')
FigureCanvas.draw(self)
def drawTransfer(self, df):
"""Take a data frame and draw it."""
self.ax1 = self.fig.add_subplot(111)
self.ax1.semilogy(df['Gate Voltage [V]'],
abs(df['Channel Current [A]']), '.')
self.ax1.set_title('Transfer Curve')
self.ax1.set_xlabel('Gate Voltage [V]')
self.ax1.set_ylabel('Channel Current [A]')
FigureCanvas.draw(self)
def drawLeakage(self, df):
"""Take a data frame and draw it."""
self.ax1 = self.fig.add_subplot(111)
self.ax1.plot(df['Gate Voltage [V]'], df['Gate Leakage [A]'], '.')
self.ax1.set_title('Leakage from gate to drain')
self.ax1.set_xlabel('Gate Voltage [V]')
self.ax1.set_ylabel('Gate Leakage [A]')
FigureCanvas.draw(self)
def drawAll(self, sample):
"""Take all sweeps and draw them."""
try:
df1 = pd.read_csv(str(sample + '-iv-sweep.csv'), '\t')
df2 = pd.read_csv(str(sample + '-output.csv'), '\t')
df3 = pd.read_csv(
str(sample + '-neg-pos-transfer.csv'), '\t')
df4 = pd.read_csv(
str(sample + '-pos-neg-transfer.csv'), '\t')
except FileNotFoundError:
# If it can't find some data, dont worry :)
pass
self.fig.clear()
self.ax1 = self.fig.add_subplot(221)
self.ax2 = self.fig.add_subplot(222)
self.ax3 = self.fig.add_subplot(223)
self.ax4 = self.fig.add_subplot(224)
try:
self.ax1.plot(df1['Channel Voltage [V]'],
df1['Channel Current [A]'] / 1e-6, '.')
self.ax1.set_title('I-V sweep')
self.ax1.set_xlabel('Channel Voltage [V]')
self.ax1.set_ylabel('Channel Current [$\mu$A]')
self.ax2.plot(df2['Channel Voltage [V]'],
df2['Channel Current [A]'] / 1e-6, '.')
self.ax2.set_title('Output curves')
self.ax2.set_xlabel('Channel Voltage [V]')
self.ax2.set_ylabel('Channel Current [$\mu$A]')
self.ax3.semilogy(df3['Gate Voltage [V]'],
abs(df3['Channel Current [A]']), '.')
self.ax3.set_title('Transfer Curves')
self.ax3.set_xlabel('Gate Voltage [V]')
self.ax3.set_ylabel('Channel Current [A]')
self.ax3.semilogy(df4['Gate Voltage [V]'],
abs(df4['Channel Current [A]']), '.')
self.ax3.set_title('Transfer Curves')
self.ax3.set_xlabel('Gate Voltage [V]')
self.ax3.set_ylabel('Channel Current [A]')
self.ax4.plot(df3['Gate Voltage [V]'],
df3['Gate Leakage [A]'] / 1e-9, '.')
self.ax4.set_title('Gate leakage current')
self.ax4.set_xlabel('Gate Voltage [V]')
self.ax4.set_ylabel('Gate Leakage [nA]')
except UnboundLocalError:
pass # if data isnt there, it cant be plotted
self.fig.tight_layout()
FigureCanvas.draw(self)
def drawInverter(self, df):
"""Take a data frame and draw it."""
self.ax1 = self.fig.add_subplot(111)
self.ax1.plot(df['Voltage In [V]'], df['Voltage Out [V]'],
'.')
self.ax1.set_title('Inverter')
self.ax1.set_xlabel('Voltage In [V]')
self.ax1.set_ylabel('Voltage Out [V]')
self.fig.tight_layout()
FigureCanvas.draw(self)
def clear(self):
"""Clear the plot."""
self.fig.clear()
FigureCanvas.draw(self)
class keithleySettingsWindow(QWidget):
"""Keithley settings popup."""
def __init__(self):
"""Initialise setup."""
super().__init__()
self.initWidget()
def initWidget(self):
"""Initialise connections."""
# Set widget layout
grid = QGridLayout()
self.setLayout(grid)
# Columns
col1 = QLabel('Initial Voltage')
col2 = QLabel('Final Voltage')
col3 = QLabel('Voltage Step')
col4 = QLabel('Step Time')
grid.addWidget(col1, 1, 2)
grid.addWidget(col2, 1, 3)
grid.addWidget(col3, 1, 4)
grid.addWidget(col4, 1, 5)
# Rows
row1 = QLabel('IV')
row2 = QLabel('Ouput')
row3 = QLabel('Transfer')
grid.addWidget(row1, 2, 1)
grid.addWidget(row2, 3, 1)
grid.addWidget(row3, 4, 1)
# IV Settings
ivFirstV = QDoubleSpinBox(self)
grid.addWidget(ivFirstV, 2, 2)
ivFirstV.setMinimum(-100)
ivFirstV.setValue(-5)
ivLastV = QDoubleSpinBox(self)
grid.addWidget(ivLastV, 2, 3)
ivLastV.setValue(5)
ivStepV = QDoubleSpinBox(self)
grid.addWidget(ivStepV, 2, 4)
ivStepV.setValue(0.1)
ivStepT = QDoubleSpinBox(self)
grid.addWidget(ivStepT, 2, 5)
ivStepT.setValue(0.2)
# Ouptut curve Settings
outputFirstV = QDoubleSpinBox(self)
grid.addWidget(outputFirstV, 3, 2)
outputLastV = QDoubleSpinBox(self)
grid.addWidget(outputLastV, 3, 3)
outputStepV = QDoubleSpinBox(self)
grid.addWidget(outputStepV, 3, 4)
outputStepT = QDoubleSpinBox(self)
grid.addWidget(outputStepT, 3, 5)
# transfer Settings
transferFirstV = QDoubleSpinBox(self)
grid.addWidget(transferFirstV, 4, 2)
transferLastV = QDoubleSpinBox(self)
grid.addWidget(transferLastV, 4, 3)
transferStepV = QDoubleSpinBox(self)
grid.addWidget(transferStepV, 4, 4)
transferStepT = QDoubleSpinBox(self)
grid.addWidget(transferStepT, 4, 5)
# OK button
setSettings = QPushButton('Ok')
grid.addWidget(setSettings, 5, 4)
setSettings.clicked.connect(self.setIVparams)
# Cancel button
cancelSet = QPushButton('Cancel')
grid.addWidget(cancelSet, 5, 5)
cancelSet.clicked.connect(self.close)
# Window setup
self.centre()
self.setWindowTitle('K2636 - Settings')
def centre(self):
"""Find screen size and place in centre."""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2,
(screen.height()-size.height())/2)
def setIVparams(self):
"""Store IV sweep settings in .tsp file."""
print('You are here')
class keithleyConnectionWindow(QWidget):
"""Popup for connecting to instrument."""
connectionSig = pyqtSignal()
def __init__(self):
"""Initialise setup."""
super().__init__()
self.initWidget()
def initWidget(self):
"""Initialise connections."""
# Set widget layout
grid = QGridLayout()
self.setLayout(grid)
# Connection status box
self.connStatus = QTextEdit('Push button to connect to keithley...')
self.connButton = QPushButton('Connect')
self.connButton.clicked.connect(self.reconnect2keithley)
grid.addWidget(self.connStatus, 1, 1)
grid.addWidget(self.connButton, 2, 1)
# Window setup
self.resize(300, 100)
self.centre()
self.setWindowTitle('K2636 - Connecting')
def centre(self):
"""Find screen size and place in centre."""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width()) / 2,
(screen.height()-size.height()) / 2)
def reconnect2keithley(self):
"""Reconnect to instrument."""
try:
self.keithley = k2636.K2636(address='ASRL/dev/ttyUSB0',
read_term='\n', baudrate=57600)
self.connStatus.append('Connection successful')
self.connectionSig.emit()
self.keithley.closeConnection()
except ConnectionError:
self.connStatus.append('No Keithley can be found.')
class keithleyErrorWindow(QWidget):
"""Popup for reading error messages."""
def __init__(self):
"""Initialise setup."""
super().__init__()
self.initWidget()
def initWidget(self):
"""Initialise connections."""
# Set widget layout
grid = QGridLayout()
self.setLayout(grid)
# Connection status box
self.errorStatus = QTextEdit('ERROR CODE------------------MESSAGE')
self.errorButton = QPushButton('Read error')
self.errorButton.clicked.connect(self.readError)
grid.addWidget(self.errorStatus, 1, 1)
grid.addWidget(self.errorButton, 2, 1)
# Window setup
self.resize(600, 300)
self.centre()
self.setWindowTitle('K2636 - Error Log')
def centre(self):
"""Find screen size and place in centre."""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width()) / 2,
(screen.height()-size.height()) / 2)
def readError(self):
"""Reconnect to instrument."""
self.keithley = k2636.K2636(address='ASRL/dev/ttyUSB0',
read_term='\n', baudrate=57600)
self.keithley._write('errorCode, message, severity, errorNode' +
'= errorqueue.next()')
self.keithley._write('print(errorCode, message)')
error = self.keithley._query('')
self.errorStatus.append(error)
self.keithley.closeConnection()
class warningWindow(QWidget):
"""Warning window popup."""
def __init__(self):
"""Intial setup."""
super().__init__()
self.initWidget()
def initWidget(self):
"""Initialise connections."""
# Set widget layout
grid = QGridLayout()
self.setLayout(grid)
# Connection status box
self.warning = QLabel()
self.continueButton = QPushButton('Continue')
self.continueButton.clicked.connect(self.hide)
grid.addWidget(self.warning, 1, 1)
grid.addWidget(self.continueButton, 2, 1)
# Window setup
self.resize(180, 80)
self.centre()
self.setWindowTitle('Error!')
def centre(self):
"""Find screen size and place in centre."""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width()) / 2,
(screen.height()-size.height()) / 2)
def showWindow(self, s):
"""Write error message and show window."""
self.warning.setText(s)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
GUI = mainWindow()
sys.exit(app.exec_())