Uh oh!
There was an error while loading. Please reload this page.
forked from pyIonControl/IonControl
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadSpectrum.pyw
More file actions
Latest commit
133 lines (114 loc) · 5.35 KB
/
Copy pathReadSpectrum.pyw
File metadata and controls
133 lines (114 loc) · 5.35 KB
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
# *****************************************************************
# IonControl: Copyright 2016 Sandia Corporation
# This Software is released under the GPL license detailed
# in the file "license.txt" in the top-level IonControl directory
# *****************************************************************
fromtraceimportTraceui
fromtraceimportpens
importlogging
frommyloggingimportLoggingSetup#@UnusedImport
fromPyQt5importQtCore, QtGui
importPyQt5.uic
try:
importvisa#@UnresolvedImport
exceptImportError:
logging.getLogger(__name__).error("Visa not present")
frommodulesimportDataDirectory
frompersistimportconfigshelve
fromreadInstrumentimportRead_E5100B
fromreadInstrumentimportRead_N9010A
fromreadInstrumentimportRead_N9342CN
instrumentmap= {
'N9342CN' : Read_N9342CN.N9342CN,
'N9344C' : Read_N9342CN.N9342CN,
'E5100B' : Read_E5100B.E5100B,
'N9010A' : Read_N9010A.N9010A
}
ReadSpectrumForm, ReadSpectrumBase=PyQt5.uic.loadUiType('ReadSpectrum.ui')
classReadSpectrum( ReadSpectrumForm ):
def__init__(self,config):
self.Instruments=dict()
self.TraceList=list()
self.config=config
defsetupUi(self, MainWindow):
ReadSpectrumForm.setupUi(self, MainWindow)
MainWindow.connect(self.actionRead_Instrument, QtCore.SIGNAL('triggered ()'), self.onReadInstrument )
MainWindow.connect(self.actionScan_Instruments, QtCore.SIGNAL('triggered ()'), self.onScanInstruments )
MainWindow.connect(self.comboBoxInstruments, QtCore.SIGNAL('currentIndexChanged(int)'), self.onInstrumentSelect)
QtCore.QTimer.singleShot(10,self.onScanInstruments)
self.penicons=pens.penicons().penicons()
self.traceui=Traceui.Traceui(self.penicons)
self.traceui.setupUi(self.traceui)
self.dockWidget.setWidget( self.traceui )
if'project'inconfig:
self.Project.setText(config['project'])
if'filename'inconfig:
self.Filename.setText(config['filename'])
if'plotnew'inconfig:
self.checkBoxPlotNew.setChecked(config['plotnew'])
deffindDevices(self):
self.statusbar.showMessage("Scanning for connected Instruments...")
self.comboBoxInstruments.clear()
rm=visa.ResourceManager()
instrumentlist=rm.list_resources()
forinstininstrumentlist:
if (str.find(inst,"COM")!=0):
try:
rm=visa.ResourceManager()
name=self.rm.open_resource( inst ).query("*IDN?").split(",")
self.Instruments.update( {inst : name} )
self.comboBoxInstruments.addItem(name[0]+" "+name[1],inst)
exceptvisa.VisaIOErroraserr:
print( "Ignore:", inst, err )
ifself.comboBoxInstruments.count()>0:
self.onInstrumentSelect(0)
self.statusbar.showMessage("Scan Instruments finished, "+str(self.comboBoxInstruments.count())+" found.")
defonScanInstruments(self):
self.findDevices()
defonInstrumentSelect(self,index):
#print self.Instruments
address=self.comboBoxInstruments.itemData(index)
ifaddressinself.Instruments:
name=self.Instruments[address]
#print "Instrument",name,address,"selected"
self.Instrument=instrumentmap[name[1]](address)
defonReadInstrument(self):
self.statusbar.clearMessage()
try:
self.plot=Traceui.PlottedTrace( self.Instrument.readTrace(), self._graphicsView, pens.penList )
self.StartFrequency.setText(self.plot.trace.varstr('Start'))
self.StopFrequency.setText(self.plot.trace.varstr('Stop'))
self.FrequencyStep.setText(self.plot.trace.varstr('Step'))
self.ResolutionBandwidth.setText(self.plot.trace.varstr('ResolutionBandwidth'))
self.VideoBandwidth.setText(self.plot.trace.varstr('VideoBandwidth'))
self.Instrument.t.description["comment"] =str(self.Comment.text())
self.onSaveTrace()
ifself.checkBoxPlotNew.isChecked():
self.plot.plot(-1)
self.traceui.addTrace(self.plot)
exceptExceptionasex:
self.statusbar.showMessage(str(ex))
defonSaveTrace(self):
try:
project=self.Project.text()
filename=self.Filename.text()
if (project.length()>0andfilename.length()>0):
path=DataDirectory.DataDirectory(str(project))
self.plot.trace.filename , components=path.sequencefile(str(filename))
self.plot.trace.name=components[1]
self.plot.trace.saveTrace(self.trace.filename)
self.statusbar.showMessage("Wrote file: "+self.plot.trace.filename)
print(self.plot.trace.name)
config['project'] =project
config['filename'] =filename
exceptExceptionasex:
self.statusbar.showMessage(str(ex))
if__name__=="__main__":
importsys
app=QtWidgets.QApplication(sys.argv)
MainWindow=QtWidgets.QMainWindow()
withconfigshelve.configshelve("ReadSpectrum") asconfig:
ui=ReadSpectrum(config)
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())