Commit 348049517a1337a888e6a8f9cbf6c53324ca6faa
1 parent
8e3f9cd166
Exists in
master
replace 4 spaces by tabs
Showing 14 changed files with 1016 additions and 1016 deletions Side-by-side Diff
- datalogger-gui.py
- instruments/AG34461A.py
- instruments/AG34461A_avg.py
- instruments/AG34972A.py
- instruments/AG53230A.py
- instruments/HP53132A.py
- instruments/LS350.py
- instruments/PM100D.py
- instruments/Sym5125A.py
- instruments/T7Pro.py
- instruments/TPG261.py
- instruments/__init__.py
- instruments/abstract_instrument.py
- instruments/testDevice.py
datalogger-gui.py
... | ... | @@ -10,244 +10,244 @@ |
10 | 10 | #============================================================================== |
11 | 11 | |
12 | 12 | class acq_routine(): |
13 | - def __init__(self, instrument, channels, vtypes, address, samplingtime, path = os.getcwd(), fileduration = 24*3600): | |
14 | - exec('self.instrument = instruments.%s.%s(%s, %s, "%s")'%(instrument, instrument, channels, vtypes, address)) | |
15 | - self.path = path | |
16 | - self.samplingtime = samplingtime | |
17 | - self.fileduration = fileduration | |
13 | + def __init__(self, instrument, channels, vtypes, address, samplingtime, path = os.getcwd(), fileduration = 24*3600): | |
14 | + exec('self.instrument = instruments.%s.%s(%s, %s, "%s")'%(instrument, instrument, channels, vtypes, address)) | |
15 | + self.path = path | |
16 | + self.samplingtime = samplingtime | |
17 | + self.fileduration = fileduration | |
18 | 18 | |
19 | - def makeTree(self): | |
20 | - try: | |
21 | - year = time.strftime("%Y", time.gmtime(self.t0)) | |
22 | - month = time.strftime("%Y-%m", time.gmtime(self.t0)) | |
23 | - os.chdir(self.path + '/' + year + '/' + month) | |
24 | - except: | |
25 | - try: | |
26 | - os.chdir(self.path + '/' + year) | |
27 | - os.mkdir(month) | |
28 | - os.chdir(self.path + '/' + year + '/' + month) | |
29 | - except: | |
30 | - os.chdir(self.path) | |
31 | - os.mkdir(year) | |
32 | - os.chdir(self.path + '/' + year) | |
33 | - os.mkdir(month) | |
34 | - os.chdir(self.path + '/' + year + '/' + month) | |
19 | + def makeTree(self): | |
20 | + try: | |
21 | + year = time.strftime("%Y", time.gmtime(self.t0)) | |
22 | + month = time.strftime("%Y-%m", time.gmtime(self.t0)) | |
23 | + os.chdir(self.path + '/' + year + '/' + month) | |
24 | + except: | |
25 | + try: | |
26 | + os.chdir(self.path + '/' + year) | |
27 | + os.mkdir(month) | |
28 | + os.chdir(self.path + '/' + year + '/' + month) | |
29 | + except: | |
30 | + os.chdir(self.path) | |
31 | + os.mkdir(year) | |
32 | + os.chdir(self.path + '/' + year) | |
33 | + os.mkdir(month) | |
34 | + os.chdir(self.path + '/' + year + '/' + month) | |
35 | 35 | |
36 | - def connect(self): | |
37 | - self.instrument.connect() | |
36 | + def connect(self): | |
37 | + self.instrument.connect() | |
38 | 38 | |
39 | - self.t0 = time.time() | |
40 | - self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' | |
41 | - self.makeTree() | |
42 | - self.data_file = open(self.filename, 'wr', 0) | |
39 | + self.t0 = time.time() | |
40 | + self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' | |
41 | + self.makeTree() | |
42 | + self.data_file = open(self.filename, 'wr', 0) | |
43 | 43 | |
44 | - def start(self): | |
45 | - tic = time.time() | |
44 | + def start(self): | |
45 | + tic = time.time() | |
46 | 46 | |
47 | - if (time.time() - self.t0 >= self.fileduration) & (self.fileduration >0 ): | |
48 | - self.data_file.close() | |
47 | + if (time.time() - self.t0 >= self.fileduration) & (self.fileduration >0 ): | |
48 | + self.data_file.close() | |
49 | 49 | |
50 | - self.t0 = time.time() | |
51 | - self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' | |
52 | - self.makeTree() | |
53 | - self.data_file = open(self.filename, 'wr', 0) | |
50 | + self.t0 = time.time() | |
51 | + self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' | |
52 | + self.makeTree() | |
53 | + self.data_file = open(self.filename, 'wr', 0) | |
54 | 54 | |
55 | - #epoch time | |
56 | - epoch = time.time() | |
57 | - #MJD time | |
58 | - mjd = epoch / 86400.0 + 40587 | |
59 | - # Meas values | |
60 | - meas = self.instrument.getValue() | |
61 | - meas = meas.replace(",", "\t") | |
62 | - meas = meas.replace(";", "\t") | |
63 | - meas = meas.replace("+", "") | |
64 | - meas = meas.replace("E", "e") | |
55 | + #epoch time | |
56 | + epoch = time.time() | |
57 | + #MJD time | |
58 | + mjd = epoch / 86400.0 + 40587 | |
59 | + # Meas values | |
60 | + meas = self.instrument.getValue() | |
61 | + meas = meas.replace(",", "\t") | |
62 | + meas = meas.replace(";", "\t") | |
63 | + meas = meas.replace("+", "") | |
64 | + meas = meas.replace("E", "e") | |
65 | 65 | |
66 | - string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
67 | - self.data_file.write(string) # Write in a file | |
68 | - print(string) | |
66 | + string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
67 | + self.data_file.write(string) # Write in a file | |
68 | + print(string) | |
69 | 69 | |
70 | - self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) | |
71 | - self.thread.start() | |
70 | + self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) | |
71 | + self.thread.start() | |
72 | 72 | |
73 | - def stop(self): | |
74 | - self.thread.cancel() | |
75 | - self.instrument.disconnect() | |
76 | - self.data_file.close() | |
73 | + def stop(self): | |
74 | + self.thread.cancel() | |
75 | + self.instrument.disconnect() | |
76 | + self.data_file.close() | |
77 | 77 | |
78 | 78 | #============================================================================== |
79 | 79 | #============================================================================== |
80 | 80 | |
81 | 81 | class mainGui(): |
82 | - def __init__(self): | |
83 | - self.setWindow() | |
84 | - self.setSignalsSlots() | |
85 | - self.runApp() | |
82 | + def __init__(self): | |
83 | + self.setWindow() | |
84 | + self.setSignalsSlots() | |
85 | + self.runApp() | |
86 | 86 | |
87 | - def setWindow(self): | |
88 | - self.a = QtGui.QApplication(sys.argv) | |
89 | - self.w = QtGui.QMainWindow() | |
90 | - self.w.resize(640, 480) | |
91 | - self.w.setWindowTitle('datalogger-gui') | |
87 | + def setWindow(self): | |
88 | + self.a = QtGui.QApplication(sys.argv) | |
89 | + self.w = QtGui.QMainWindow() | |
90 | + self.w.resize(640, 480) | |
91 | + self.w.setWindowTitle('datalogger-gui') | |
92 | 92 | |
93 | - self.wid = QtGui.QWidget() | |
94 | - self.w.setCentralWidget(self.wid) | |
95 | - self.layout = QtGui.QGridLayout() | |
96 | - self.wid.setLayout(self.layout) | |
93 | + self.wid = QtGui.QWidget() | |
94 | + self.w.setCentralWidget(self.wid) | |
95 | + self.layout = QtGui.QGridLayout() | |
96 | + self.wid.setLayout(self.layout) | |
97 | 97 | |
98 | - self.comboInst = QtGui.QComboBox() | |
99 | - self.layout.addWidget(self.comboInst, 0, 0) | |
98 | + self.comboInst = QtGui.QComboBox() | |
99 | + self.layout.addWidget(self.comboInst, 0, 0) | |
100 | 100 | |
101 | - self.address = QtGui.QLineEdit() | |
102 | - self.address.setMinimumWidth(140) | |
103 | - self.address.setMaximumWidth(140) | |
104 | - self.layout.addWidget(self.address, 0, 1) | |
101 | + self.address = QtGui.QLineEdit() | |
102 | + self.address.setMinimumWidth(140) | |
103 | + self.address.setMaximumWidth(140) | |
104 | + self.layout.addWidget(self.address, 0, 1) | |
105 | 105 | |
106 | - self.samplingtime = QtGui.QDoubleSpinBox() | |
107 | - #self.samplingtime.setMinimumWidth(60) | |
108 | - #self.samplingtime.setMaximumWidth(60) | |
109 | - self.samplingtime.setMinimum(0.1) | |
110 | - self.samplingtime.setMaximum(1000) | |
111 | - self.samplingtime.setSingleStep(0.1) | |
112 | - self.samplingtime.setValue(1) | |
113 | - self.layout.addWidget(self.samplingtime, 0, 2) | |
106 | + self.samplingtime = QtGui.QDoubleSpinBox() | |
107 | + #self.samplingtime.setMinimumWidth(60) | |
108 | + #self.samplingtime.setMaximumWidth(60) | |
109 | + self.samplingtime.setMinimum(0.1) | |
110 | + self.samplingtime.setMaximum(1000) | |
111 | + self.samplingtime.setSingleStep(0.1) | |
112 | + self.samplingtime.setValue(1) | |
113 | + self.layout.addWidget(self.samplingtime, 0, 2) | |
114 | 114 | |
115 | - self.startButton = QtGui.QPushButton() | |
116 | - self.startButton.setText('Start log') | |
117 | - self.layout.addWidget(self.startButton, 99, 0) | |
118 | - self.startButton.setEnabled(False) | |
115 | + self.startButton = QtGui.QPushButton() | |
116 | + self.startButton.setText('Start log') | |
117 | + self.layout.addWidget(self.startButton, 99, 0) | |
118 | + self.startButton.setEnabled(False) | |
119 | 119 | |
120 | - self.stopButton = QtGui.QPushButton() | |
121 | - self.stopButton.setText('Stop log') | |
122 | - self.layout.addWidget(self.stopButton, 99, 1) | |
123 | - self.stopButton.setEnabled(False) | |
120 | + self.stopButton = QtGui.QPushButton() | |
121 | + self.stopButton.setText('Stop log') | |
122 | + self.layout.addWidget(self.stopButton, 99, 1) | |
123 | + self.stopButton.setEnabled(False) | |
124 | 124 | |
125 | - self.textDisplay = QtGui.QLabel() | |
126 | - self.textDisplay.setText('>>') | |
127 | - self.layout.addWidget(self.textDisplay, 99, 2) | |
125 | + self.textDisplay = QtGui.QLabel() | |
126 | + self.textDisplay.setText('>>') | |
127 | + self.layout.addWidget(self.textDisplay, 99, 2) | |
128 | 128 | |
129 | - self.setComboInst() | |
130 | - self.updateSignal() | |
129 | + self.setComboInst() | |
130 | + self.updateSignal() | |
131 | 131 | |
132 | - def setComboInst(self): | |
133 | - for name, obj in inspect.getmembers(instruments): | |
134 | - if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
135 | - self.comboInst.addItem(name) | |
132 | + def setComboInst(self): | |
133 | + for name, obj in inspect.getmembers(instruments): | |
134 | + if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
135 | + self.comboInst.addItem(name) | |
136 | 136 | |
137 | - def setSignalsSlots(self): | |
138 | - self.comboInst.currentIndexChanged.connect(self.updateSignal) | |
139 | - self.startButton.clicked.connect(self.startLog) | |
140 | - self.stopButton.clicked.connect(self.stopLog) | |
137 | + def setSignalsSlots(self): | |
138 | + self.comboInst.currentIndexChanged.connect(self.updateSignal) | |
139 | + self.startButton.clicked.connect(self.startLog) | |
140 | + self.stopButton.clicked.connect(self.stopLog) | |
141 | 141 | |
142 | - def runApp(self): | |
143 | - self.w.show() | |
144 | - self.a.aboutToQuit.connect(self.closeEvent) | |
145 | - sys.exit(self.a.exec_()) | |
142 | + def runApp(self): | |
143 | + self.w.show() | |
144 | + self.a.aboutToQuit.connect(self.closeEvent) | |
145 | + sys.exit(self.a.exec_()) | |
146 | 146 | |
147 | - def closeEvent(self): | |
148 | - try: | |
149 | - self.stopLog() | |
150 | - except: | |
151 | - pass | |
152 | - print('Done') | |
147 | + def closeEvent(self): | |
148 | + try: | |
149 | + self.stopLog() | |
150 | + except: | |
151 | + pass | |
152 | + print('Done') | |
153 | 153 | |
154 | - @pyqtSlot() | |
155 | - def updateSignal(self): | |
156 | - for i in reversed(range(5, self.layout.count())): | |
157 | - self.layout.itemAt(i).widget().setParent(None) | |
154 | + @pyqtSlot() | |
155 | + def updateSignal(self): | |
156 | + for i in reversed(range(5, self.layout.count())): | |
157 | + self.layout.itemAt(i).widget().setParent(None) | |
158 | 158 | |
159 | - defaultAddress = '' | |
160 | - channelsAviables = [] | |
161 | - vtypesAviables = [] | |
159 | + defaultAddress = '' | |
160 | + channelsAviables = [] | |
161 | + vtypesAviables = [] | |
162 | 162 | |
163 | - exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) | |
164 | - exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) | |
165 | - exec('defaultAddress = instruments.%s.ADDRESS'%self.comboInst.currentText()) | |
163 | + exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) | |
164 | + exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) | |
165 | + exec('defaultAddress = instruments.%s.ADDRESS'%self.comboInst.currentText()) | |
166 | 166 | |
167 | - self.address.setText(defaultAddress) | |
167 | + self.address.setText(defaultAddress) | |
168 | 168 | |
169 | - self.checkBoxChannels = [None]*len(channelsAviables) | |
170 | - self.chListVtypes = [None]*len(self.checkBoxChannels) | |
169 | + self.checkBoxChannels = [None]*len(channelsAviables) | |
170 | + self.chListVtypes = [None]*len(self.checkBoxChannels) | |
171 | 171 | |
172 | - for i in range(len(self.checkBoxChannels)): | |
173 | - self.checkBoxChannels[i] = QtGui.QCheckBox() | |
174 | - self.checkBoxChannels[i].setText(channelsAviables[i]) | |
175 | - self.checkBoxChannels[i].setChecked(False) | |
176 | - self.chListVtypes[i] = QtGui.QListWidget() | |
177 | - for vtype in vtypesAviables: | |
178 | - self.chListVtypes[i].addItem(vtype) | |
179 | - self.chListVtypes[i].setCurrentRow(0) | |
180 | - self.layout.addWidget(self.checkBoxChannels[i], i+3, 1) | |
181 | - self.layout.addWidget(self.chListVtypes[i], i+3, 2) | |
182 | - self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) | |
183 | - self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) | |
172 | + for i in range(len(self.checkBoxChannels)): | |
173 | + self.checkBoxChannels[i] = QtGui.QCheckBox() | |
174 | + self.checkBoxChannels[i].setText(channelsAviables[i]) | |
175 | + self.checkBoxChannels[i].setChecked(False) | |
176 | + self.chListVtypes[i] = QtGui.QListWidget() | |
177 | + for vtype in vtypesAviables: | |
178 | + self.chListVtypes[i].addItem(vtype) | |
179 | + self.chListVtypes[i].setCurrentRow(0) | |
180 | + self.layout.addWidget(self.checkBoxChannels[i], i+3, 1) | |
181 | + self.layout.addWidget(self.chListVtypes[i], i+3, 2) | |
182 | + self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) | |
183 | + self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) | |
184 | 184 | |
185 | - self.address.textChanged.connect(self.infoSignal) | |
186 | - self.samplingtime.valueChanged.connect(self.infoSignal) | |
185 | + self.address.textChanged.connect(self.infoSignal) | |
186 | + self.samplingtime.valueChanged.connect(self.infoSignal) | |
187 | 187 | |
188 | - self.infoSignal() | |
188 | + self.infoSignal() | |
189 | 189 | |
190 | - @pyqtSlot() | |
191 | - def infoSignal(self): | |
192 | - self.instToLog = self.comboInst.currentText() | |
193 | - self.addressToLog = self.address.text() | |
194 | - self.chToLog = [] | |
195 | - self.vTypeToLog = [] | |
196 | - self.ts = self.samplingtime.value() | |
190 | + @pyqtSlot() | |
191 | + def infoSignal(self): | |
192 | + self.instToLog = self.comboInst.currentText() | |
193 | + self.addressToLog = self.address.text() | |
194 | + self.chToLog = [] | |
195 | + self.vTypeToLog = [] | |
196 | + self.ts = self.samplingtime.value() | |
197 | 197 | |
198 | - for i in range(len(self.checkBoxChannels)): | |
199 | - if self.checkBoxChannels[i].isChecked(): | |
200 | - self.chListVtypes[i].setEnabled(True) | |
201 | - self.chToLog.append(str(self.checkBoxChannels[i].text())) | |
202 | - self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) | |
203 | - else: | |
204 | - self.chListVtypes[i].setEnabled(False) | |
198 | + for i in range(len(self.checkBoxChannels)): | |
199 | + if self.checkBoxChannels[i].isChecked(): | |
200 | + self.chListVtypes[i].setEnabled(True) | |
201 | + self.chToLog.append(str(self.checkBoxChannels[i].text())) | |
202 | + self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) | |
203 | + else: | |
204 | + self.chListVtypes[i].setEnabled(False) | |
205 | 205 | |
206 | - allChannelsUnchecked = False | |
207 | - for i in self.checkBoxChannels: | |
208 | - allChannelsUnchecked = allChannelsUnchecked or i.isChecked() | |
209 | - if allChannelsUnchecked == False: | |
210 | - self.startButton.setEnabled(False) | |
211 | - else: | |
212 | - self.startButton.setEnabled(True) | |
206 | + allChannelsUnchecked = False | |
207 | + for i in self.checkBoxChannels: | |
208 | + allChannelsUnchecked = allChannelsUnchecked or i.isChecked() | |
209 | + if allChannelsUnchecked == False: | |
210 | + self.startButton.setEnabled(False) | |
211 | + else: | |
212 | + self.startButton.setEnabled(True) | |
213 | 213 | |
214 | - self.textDisplay.setText('>> %s@%s - %s - %s - %d'%(self.instToLog, self.addressToLog, self.chToLog, self.vTypeToLog, self.ts)) | |
214 | + self.textDisplay.setText('>> %s@%s - %s - %s - %d'%(self.instToLog, self.addressToLog, self.chToLog, self.vTypeToLog, self.ts)) | |
215 | 215 | |
216 | - self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.addressToLog, self.ts) | |
216 | + self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.addressToLog, self.ts) | |
217 | 217 | |
218 | - @pyqtSlot() | |
219 | - def startLog(self): | |
220 | - self.startButton.setEnabled(False) | |
221 | - self.stopButton.setEnabled(True) | |
222 | - self.address.setEnabled(False) | |
223 | - self.samplingtime.setReadOnly(True) | |
224 | - self.comboInst.setEnabled(False) | |
225 | - for i in self.checkBoxChannels: | |
226 | - i.setEnabled(False) | |
227 | - for i in self.chListVtypes: | |
228 | - i.setEnabled(False) | |
229 | - self.myLog.connect() | |
230 | - self.myLog.start() | |
218 | + @pyqtSlot() | |
219 | + def startLog(self): | |
220 | + self.startButton.setEnabled(False) | |
221 | + self.stopButton.setEnabled(True) | |
222 | + self.address.setEnabled(False) | |
223 | + self.samplingtime.setReadOnly(True) | |
224 | + self.comboInst.setEnabled(False) | |
225 | + for i in self.checkBoxChannels: | |
226 | + i.setEnabled(False) | |
227 | + for i in self.chListVtypes: | |
228 | + i.setEnabled(False) | |
229 | + self.myLog.connect() | |
230 | + self.myLog.start() | |
231 | 231 | |
232 | - @pyqtSlot() | |
233 | - def stopLog(self): | |
234 | - self.startButton.setEnabled(True) | |
235 | - self.stopButton.setEnabled(False) | |
236 | - self.address.setEnabled(True) | |
237 | - self.samplingtime.setReadOnly(False) | |
238 | - self.comboInst.setEnabled(True) | |
239 | - for i in range(len(self.checkBoxChannels)): | |
240 | - if self.checkBoxChannels[i].isChecked(): | |
241 | - self.checkBoxChannels[i].setEnabled(True) | |
242 | - self.chListVtypes[i].setEnabled(True) | |
243 | - else: | |
244 | - self.checkBoxChannels[i].setEnabled(True) | |
245 | - self.chListVtypes[i].setEnabled(False) | |
246 | - self.myLog.stop() | |
232 | + @pyqtSlot() | |
233 | + def stopLog(self): | |
234 | + self.startButton.setEnabled(True) | |
235 | + self.stopButton.setEnabled(False) | |
236 | + self.address.setEnabled(True) | |
237 | + self.samplingtime.setReadOnly(False) | |
238 | + self.comboInst.setEnabled(True) | |
239 | + for i in range(len(self.checkBoxChannels)): | |
240 | + if self.checkBoxChannels[i].isChecked(): | |
241 | + self.checkBoxChannels[i].setEnabled(True) | |
242 | + self.chListVtypes[i].setEnabled(True) | |
243 | + else: | |
244 | + self.checkBoxChannels[i].setEnabled(True) | |
245 | + self.chListVtypes[i].setEnabled(False) | |
246 | + self.myLog.stop() | |
247 | 247 | |
248 | 248 | #============================================================================== |
249 | 249 | #============================================================================== |
250 | 250 | |
251 | 251 | if __name__ == "__main__": |
252 | - mainGui() | |
252 | + mainGui() |
instruments/AG34461A.py
... | ... | @@ -12,62 +12,62 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class AG34461A(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.port = 5025 | |
18 | - self.channels = channels | |
19 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.port = 5025 | |
18 | + self.channels = channels | |
19 | + self.vtypes = vtypes | |
20 | 20 | |
21 | - def model(self): | |
22 | - #self.send("*IDN?") | |
23 | - #return self.read() | |
24 | - return "AG34461A" | |
21 | + def model(self): | |
22 | + #self.send("*IDN?") | |
23 | + #return self.read() | |
24 | + return "AG34461A" | |
25 | 25 | |
26 | - def connect(self): | |
27 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | - self.sock = socket.socket(socket.AF_INET, | |
29 | - socket.SOCK_STREAM, | |
30 | - socket.IPPROTO_TCP) | |
31 | - self.sock.settimeout(10.0) # Don't hang around forever | |
32 | - self.sock.connect((self.address, self.port)) | |
33 | - self.send("SYST:BEEP") | |
34 | - print(' --> Ok') | |
35 | - print(self.model()) | |
36 | - self.configure() | |
26 | + def connect(self): | |
27 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | + self.sock = socket.socket(socket.AF_INET, | |
29 | + socket.SOCK_STREAM, | |
30 | + socket.IPPROTO_TCP) | |
31 | + self.sock.settimeout(10.0) # Don't hang around forever | |
32 | + self.sock.connect((self.address, self.port)) | |
33 | + self.send("SYST:BEEP") | |
34 | + print(' --> Ok') | |
35 | + print(self.model()) | |
36 | + self.configure() | |
37 | 37 | |
38 | - def configure(self): | |
39 | - for ch in self.channels: | |
40 | - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
38 | + def configure(self): | |
39 | + for ch in self.channels: | |
40 | + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
41 | 41 | |
42 | - def getValue(self): | |
43 | - mes = '' | |
44 | - for ch in self.channels: | |
45 | - self.send("READ?") | |
46 | - mesTemp = self.read() | |
47 | - mes = mes + '\t' + mesTemp | |
48 | - return mes | |
42 | + def getValue(self): | |
43 | + mes = '' | |
44 | + for ch in self.channels: | |
45 | + self.send("READ?") | |
46 | + mesTemp = self.read() | |
47 | + mes = mes + '\t' + mesTemp | |
48 | + return mes | |
49 | 49 | |
50 | - def read(self): | |
51 | - ans = '' | |
52 | - nb_data_list = [] | |
53 | - nb_data = '' | |
54 | - try: | |
55 | - while ans != '\n': | |
56 | - ans = self.sock.recv(1) | |
57 | - nb_data_list.append(ans) # Return the number of data | |
58 | - list_size = len(nb_data_list) | |
59 | - for j in range (0, list_size): | |
60 | - nb_data = nb_data+nb_data_list[j] | |
61 | - return nb_data | |
62 | - except socket.timeout: | |
63 | - print "Socket timeout error when reading." | |
64 | - raise | |
50 | + def read(self): | |
51 | + ans = '' | |
52 | + nb_data_list = [] | |
53 | + nb_data = '' | |
54 | + try: | |
55 | + while ans != '\n': | |
56 | + ans = self.sock.recv(1) | |
57 | + nb_data_list.append(ans) # Return the number of data | |
58 | + list_size = len(nb_data_list) | |
59 | + for j in range (0, list_size): | |
60 | + nb_data = nb_data+nb_data_list[j] | |
61 | + return nb_data | |
62 | + except socket.timeout: | |
63 | + print "Socket timeout error when reading." | |
64 | + raise | |
65 | 65 | |
66 | - def disconnect(self): | |
67 | - self.send('*RST') | |
68 | - self.send("SYST:BEEP") | |
69 | - self.sock.close() | |
66 | + def disconnect(self): | |
67 | + self.send('*RST') | |
68 | + self.send("SYST:BEEP") | |
69 | + self.sock.close() | |
70 | 70 | |
71 | - def send(self, command): | |
72 | - self.sock.send("%s\n"%command) | |
71 | + def send(self, command): | |
72 | + self.sock.send("%s\n"%command) |
instruments/AG34461A_avg.py
... | ... | @@ -13,74 +13,74 @@ |
13 | 13 | #============================================================================== |
14 | 14 | |
15 | 15 | class AG34461A_avg(abstract_instrument): |
16 | - def __init__(self, channels, vtypes, address): | |
17 | - self.address = address | |
18 | - self.port = 5025 | |
19 | - self.channels = channels | |
20 | - self.vtypes = vtypes | |
16 | + def __init__(self, channels, vtypes, address): | |
17 | + self.address = address | |
18 | + self.port = 5025 | |
19 | + self.channels = channels | |
20 | + self.vtypes = vtypes | |
21 | 21 | |
22 | - def model(self): | |
23 | - #self.send("*IDN?") | |
24 | - #return self.read() | |
25 | - return "AG34461A_avg" | |
22 | + def model(self): | |
23 | + #self.send("*IDN?") | |
24 | + #return self.read() | |
25 | + return "AG34461A_avg" | |
26 | 26 | |
27 | - def connect(self): | |
28 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
29 | - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
30 | - self.sock.settimeout(10.0) # Don't hang around forever | |
31 | - self.sock.connect((self.address, self.port)) | |
32 | - self.send("SYST:BEEP") | |
33 | - print(' --> Ok') | |
34 | - print(self.model()) | |
35 | - self.configure() | |
27 | + def connect(self): | |
28 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
29 | + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
30 | + self.sock.settimeout(10.0) # Don't hang around forever | |
31 | + self.sock.connect((self.address, self.port)) | |
32 | + self.send("SYST:BEEP") | |
33 | + print(' --> Ok') | |
34 | + print(self.model()) | |
35 | + self.configure() | |
36 | 36 | |
37 | - def configure(self): | |
38 | - self.send("*RST") | |
39 | - for ch in self.channels: | |
40 | - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
41 | - #self.send("CONF:VOLT:DC 1") | |
42 | - self.send("VOLT:DC:NPLC 10") | |
43 | - self.send("SAMP:COUN 5") | |
44 | - self.send("TRIG:COUN 1") | |
45 | - self.send("TRIG:DEL 0") | |
46 | - self.send("SENS:ZERO:AUTO OFF") | |
47 | - self.send("TRIG:SOUR TIM") | |
48 | - self.send("TRIG:TIM 0.2") | |
49 | - self.send("INIT") | |
37 | + def configure(self): | |
38 | + self.send("*RST") | |
39 | + for ch in self.channels: | |
40 | + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
41 | + #self.send("CONF:VOLT:DC 1") | |
42 | + self.send("VOLT:DC:NPLC 10") | |
43 | + self.send("SAMP:COUN 5") | |
44 | + self.send("TRIG:COUN 1") | |
45 | + self.send("TRIG:DEL 0") | |
46 | + self.send("SENS:ZERO:AUTO OFF") | |
47 | + self.send("TRIG:SOUR TIM") | |
48 | + self.send("TRIG:TIM 0.2") | |
49 | + self.send("INIT") | |
50 | 50 | |
51 | - def getValue(self): | |
52 | - mes = '' | |
53 | - for ch in self.channels: | |
54 | - self.send("FETC?") | |
55 | - mesTemp = self.read() | |
56 | - #print(mesTemp) | |
57 | - mesTemp = map(float, mesTemp.split(',')) | |
58 | - mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp)) | |
59 | - self.send("INIT") | |
60 | - mes = mes + '\n' | |
61 | - return mes | |
51 | + def getValue(self): | |
52 | + mes = '' | |
53 | + for ch in self.channels: | |
54 | + self.send("FETC?") | |
55 | + mesTemp = self.read() | |
56 | + #print(mesTemp) | |
57 | + mesTemp = map(float, mesTemp.split(',')) | |
58 | + mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp)) | |
59 | + self.send("INIT") | |
60 | + mes = mes + '\n' | |
61 | + return mes | |
62 | 62 | |
63 | - def read(self): | |
64 | - ans = '' | |
65 | - nb_data_list = [] | |
66 | - nb_data = '' | |
67 | - try: | |
68 | - while ans != '\n': | |
69 | - ans = self.sock.recv(1) | |
70 | - nb_data_list.append(ans) # Return the number of data | |
71 | - list_size = len(nb_data_list) | |
72 | - for j in range (0, list_size): | |
73 | - nb_data = nb_data+nb_data_list[j] | |
74 | - return nb_data | |
75 | - except socket.timeout: | |
76 | - print "Socket timeout error when reading." | |
77 | - raise | |
63 | + def read(self): | |
64 | + ans = '' | |
65 | + nb_data_list = [] | |
66 | + nb_data = '' | |
67 | + try: | |
68 | + while ans != '\n': | |
69 | + ans = self.sock.recv(1) | |
70 | + nb_data_list.append(ans) # Return the number of data | |
71 | + list_size = len(nb_data_list) | |
72 | + for j in range (0, list_size): | |
73 | + nb_data = nb_data+nb_data_list[j] | |
74 | + return nb_data | |
75 | + except socket.timeout: | |
76 | + print "Socket timeout error when reading." | |
77 | + raise | |
78 | 78 | |
79 | - def disconnect(self): | |
80 | - self.send('*RST') | |
81 | - self.send("SYST:BEEP") | |
82 | - self.sock.close() | |
79 | + def disconnect(self): | |
80 | + self.send('*RST') | |
81 | + self.send("SYST:BEEP") | |
82 | + self.sock.close() | |
83 | 83 | |
84 | - def send(self, command): | |
85 | - self.sock.send("%s\n"%command) | |
84 | + def send(self, command): | |
85 | + self.sock.send("%s\n"%command) |
instruments/AG34972A.py
... | ... | @@ -12,63 +12,63 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class AG34972A(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.port = 5025 | |
18 | - self.channels = channels | |
19 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.port = 5025 | |
18 | + self.channels = channels | |
19 | + self.vtypes = vtypes | |
20 | 20 | |
21 | - def model(self): | |
22 | - #self.send("*IDN?") | |
23 | - #return self.read() | |
24 | - return "AG34972A" | |
21 | + def model(self): | |
22 | + #self.send("*IDN?") | |
23 | + #return self.read() | |
24 | + return "AG34972A" | |
25 | 25 | |
26 | - def connect(self): | |
27 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | - self.sock = socket.socket(socket.AF_INET, | |
29 | - socket.SOCK_STREAM, | |
30 | - socket.IPPROTO_TCP) | |
31 | - self.sock.settimeout(2.0) # Don't hang around forever | |
32 | - self.sock.connect((self.address, self.port)) | |
33 | - self.send("SYST:BEEP") | |
34 | - print(' --> Ok') | |
35 | - print(self.model()) | |
36 | - self.configure() | |
26 | + def connect(self): | |
27 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | + self.sock = socket.socket(socket.AF_INET, | |
29 | + socket.SOCK_STREAM, | |
30 | + socket.IPPROTO_TCP) | |
31 | + self.sock.settimeout(2.0) # Don't hang around forever | |
32 | + self.sock.connect((self.address, self.port)) | |
33 | + self.send("SYST:BEEP") | |
34 | + print(' --> Ok') | |
35 | + print(self.model()) | |
36 | + self.configure() | |
37 | 37 | |
38 | - def configure(self): | |
39 | - self.strCh = '' | |
40 | - for ch in self.channels: | |
41 | - self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) | |
42 | - self.strCh = self.strCh + ch + ',' | |
43 | - self.strCh = self.strCh[0:-1] | |
44 | - self.send("ROUT:SCAN (@%s)"%self.strCh) | |
45 | - self.send("TRIG:COUN 1") | |
38 | + def configure(self): | |
39 | + self.strCh = '' | |
40 | + for ch in self.channels: | |
41 | + self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) | |
42 | + self.strCh = self.strCh + ch + ',' | |
43 | + self.strCh = self.strCh[0:-1] | |
44 | + self.send("ROUT:SCAN (@%s)"%self.strCh) | |
45 | + self.send("TRIG:COUN 1") | |
46 | 46 | |
47 | - def getValue(self): | |
48 | - self.send("INIT") | |
49 | - self.send("FETC?") | |
50 | - return self.read() | |
47 | + def getValue(self): | |
48 | + self.send("INIT") | |
49 | + self.send("FETC?") | |
50 | + return self.read() | |
51 | 51 | |
52 | - def read(self): | |
53 | - ans = '' | |
54 | - nb_data_list = [] | |
55 | - nb_data = '' | |
56 | - try: | |
57 | - while ans != '\n': | |
58 | - ans = self.sock.recv(1) | |
59 | - nb_data_list.append(ans) # Return the number of data | |
60 | - list_size = len(nb_data_list) | |
61 | - for j in range (0, list_size): | |
62 | - nb_data = nb_data+nb_data_list[j] | |
63 | - return nb_data | |
64 | - except socket.timeout: | |
65 | - print "Socket timeout error when reading." | |
66 | - raise | |
52 | + def read(self): | |
53 | + ans = '' | |
54 | + nb_data_list = [] | |
55 | + nb_data = '' | |
56 | + try: | |
57 | + while ans != '\n': | |
58 | + ans = self.sock.recv(1) | |
59 | + nb_data_list.append(ans) # Return the number of data | |
60 | + list_size = len(nb_data_list) | |
61 | + for j in range (0, list_size): | |
62 | + nb_data = nb_data+nb_data_list[j] | |
63 | + return nb_data | |
64 | + except socket.timeout: | |
65 | + print "Socket timeout error when reading." | |
66 | + raise | |
67 | 67 | |
68 | - def disconnect(self): | |
69 | - self.send('*RST') | |
70 | - self.sock.close() | |
68 | + def disconnect(self): | |
69 | + self.send('*RST') | |
70 | + self.sock.close() | |
71 | 71 | |
72 | - def send(self, command): | |
73 | - self.sock.send("%s\n"%command) | |
72 | + def send(self, command): | |
73 | + self.sock.send("%s\n"%command) |
instruments/AG53230A.py
... | ... | @@ -12,74 +12,74 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class AG53230A(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.port = 5025 | |
18 | - self.channels = channels | |
19 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.port = 5025 | |
18 | + self.channels = channels | |
19 | + self.vtypes = vtypes | |
20 | 20 | |
21 | - def model(self): | |
22 | - #self.send("*IDN?") | |
23 | - #return self.read() | |
24 | - return "AG53230A" | |
21 | + def model(self): | |
22 | + #self.send("*IDN?") | |
23 | + #return self.read() | |
24 | + return "AG53230A" | |
25 | 25 | |
26 | - def connect(self): | |
27 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | - self.sock = socket.socket(socket.AF_INET, | |
29 | - socket.SOCK_STREAM, | |
30 | - socket.IPPROTO_TCP) | |
31 | - self.sock.settimeout(10.0) # Don't hang around forever | |
32 | - self.sock.connect((self.address, self.port)) | |
33 | - self.send("SYST:BEEP") | |
34 | - print(' --> Ok') | |
35 | - print(self.model()) | |
36 | - self.configure() | |
26 | + def connect(self): | |
27 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | + self.sock = socket.socket(socket.AF_INET, | |
29 | + socket.SOCK_STREAM, | |
30 | + socket.IPPROTO_TCP) | |
31 | + self.sock.settimeout(10.0) # Don't hang around forever | |
32 | + self.sock.connect((self.address, self.port)) | |
33 | + self.send("SYST:BEEP") | |
34 | + print(' --> Ok') | |
35 | + print(self.model()) | |
36 | + self.configure() | |
37 | 37 | |
38 | - def configure(self): | |
39 | - self.send('*RST') | |
40 | - self.send('DISP:DIG:MASK:AUTO OFF') | |
41 | - self.send('INP1:IMP 50') | |
42 | - self.send('INP1:COUP AC') | |
43 | - self.send('SYST:TIM INF') | |
44 | - self.send('SENS:ROSC:SOUR EXT') | |
45 | - self.send('SENS:ROSC:EXT:FREQ 10E6') | |
46 | - for ch in self.channels: | |
47 | - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
48 | - self.send('SAMP:COUN 1E6') | |
49 | - self.send('SENS:FREQ:MODE CONT') | |
50 | - self.send('SENS:FREQ:GATE:SOUR TIME') | |
51 | - self.send('1') | |
52 | - self.send('TRIG:SOUR IMM') | |
38 | + def configure(self): | |
39 | + self.send('*RST') | |
40 | + self.send('DISP:DIG:MASK:AUTO OFF') | |
41 | + self.send('INP1:IMP 50') | |
42 | + self.send('INP1:COUP AC') | |
43 | + self.send('SYST:TIM INF') | |
44 | + self.send('SENS:ROSC:SOUR EXT') | |
45 | + self.send('SENS:ROSC:EXT:FREQ 10E6') | |
46 | + for ch in self.channels: | |
47 | + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) | |
48 | + self.send('SAMP:COUN 1E6') | |
49 | + self.send('SENS:FREQ:MODE CONT') | |
50 | + self.send('SENS:FREQ:GATE:SOUR TIME') | |
51 | + self.send('1') | |
52 | + self.send('TRIG:SOUR IMM') | |
53 | 53 | |
54 | - def getValue(self): | |
55 | - mes = '' | |
56 | - for ch in self.channels: | |
57 | - self.send("DATA:REM?") | |
58 | - mesTemp = self.read() | |
59 | - mes = mes + '\t' + mesTemp | |
60 | - return mes | |
54 | + def getValue(self): | |
55 | + mes = '' | |
56 | + for ch in self.channels: | |
57 | + self.send("DATA:REM?") | |
58 | + mesTemp = self.read() | |
59 | + mes = mes + '\t' + mesTemp | |
60 | + return mes | |
61 | 61 | |
62 | - def read(self): | |
63 | - ans = '' | |
64 | - nb_data_list = [] | |
65 | - nb_data = '' | |
66 | - try: | |
67 | - while ans != '\n': | |
68 | - ans = self.sock.recv(1) | |
69 | - nb_data_list.append(ans) # Return the number of data | |
70 | - list_size = len(nb_data_list) | |
71 | - for j in range (0, list_size): | |
72 | - nb_data = nb_data+nb_data_list[j] | |
73 | - return nb_data | |
74 | - except socket.timeout: | |
75 | - print "Socket timeout error when reading." | |
76 | - raise | |
62 | + def read(self): | |
63 | + ans = '' | |
64 | + nb_data_list = [] | |
65 | + nb_data = '' | |
66 | + try: | |
67 | + while ans != '\n': | |
68 | + ans = self.sock.recv(1) | |
69 | + nb_data_list.append(ans) # Return the number of data | |
70 | + list_size = len(nb_data_list) | |
71 | + for j in range (0, list_size): | |
72 | + nb_data = nb_data+nb_data_list[j] | |
73 | + return nb_data | |
74 | + except socket.timeout: | |
75 | + print "Socket timeout error when reading." | |
76 | + raise | |
77 | 77 | |
78 | - def disconnect(self): | |
79 | - self.send('*RST') | |
80 | - self.send("SYST:BEEP") | |
81 | - self.sock.close() | |
78 | + def disconnect(self): | |
79 | + self.send('*RST') | |
80 | + self.send("SYST:BEEP") | |
81 | + self.sock.close() | |
82 | 82 | |
83 | - def send(self, command): | |
84 | - self.sock.send("%s\n"%command) | |
83 | + def send(self, command): | |
84 | + self.sock.send("%s\n"%command) |
instruments/HP53132A.py
... | ... | @@ -12,100 +12,100 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class HP53132A(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.port = 1234 | |
18 | - self.gpib_addr = 12 | |
19 | - self.channels = channels | |
20 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.port = 1234 | |
18 | + self.gpib_addr = 12 | |
19 | + self.channels = channels | |
20 | + self.vtypes = vtypes | |
21 | 21 | |
22 | - def model(self): | |
23 | - #self.send("*IDN?") | |
24 | - #return self.read() | |
25 | - return "HP53132A" | |
22 | + def model(self): | |
23 | + #self.send("*IDN?") | |
24 | + #return self.read() | |
25 | + return "HP53132A" | |
26 | 26 | |
27 | - def connect(self): | |
28 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
29 | - self.sock = socket.socket(socket.AF_INET, | |
30 | - socket.SOCK_STREAM, | |
31 | - socket.IPPROTO_TCP) | |
32 | - self.sock.settimeout(10.0) # Don't hang around forever | |
33 | - self.sock.connect((self.address, self.port)) | |
34 | - self.init_prologix() | |
35 | - print(' --> Ok') | |
36 | - print(self.model()) | |
37 | - self.configure() | |
27 | + def connect(self): | |
28 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
29 | + self.sock = socket.socket(socket.AF_INET, | |
30 | + socket.SOCK_STREAM, | |
31 | + socket.IPPROTO_TCP) | |
32 | + self.sock.settimeout(10.0) # Don't hang around forever | |
33 | + self.sock.connect((self.address, self.port)) | |
34 | + self.init_prologix() | |
35 | + print(' --> Ok') | |
36 | + print(self.model()) | |
37 | + self.configure() | |
38 | 38 | |
39 | - def configure(self): | |
40 | - #self.strCh = '' | |
41 | - #for ch in self.channels: | |
42 | - # self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) | |
43 | - # self.strCh = self.strCh + '(@%s),'%ch | |
44 | - #self.strCh = self.strCh[0:-1] | |
45 | - #self.send('FORMAT ASCII') | |
39 | + def configure(self): | |
40 | + #self.strCh = '' | |
41 | + #for ch in self.channels: | |
42 | + # self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) | |
43 | + # self.strCh = self.strCh + '(@%s),'%ch | |
44 | + #self.strCh = self.strCh[0:-1] | |
45 | + #self.send('FORMAT ASCII') | |
46 | 46 | |
47 | - #self.send('ROUT:SCAN (@%s)'%self.strCh) | |
48 | - #self.send('TRIG:COUN 1') | |
49 | - self.send('*RST') | |
50 | - #self.send('*CLS') | |
51 | - #self.send('*SRE 0') | |
52 | - #self.send('*ESE 0') | |
47 | + #self.send('ROUT:SCAN (@%s)'%self.strCh) | |
48 | + #self.send('TRIG:COUN 1') | |
49 | + self.send('*RST') | |
50 | + #self.send('*CLS') | |
51 | + #self.send('*SRE 0') | |
52 | + #self.send('*ESE 0') | |
53 | 53 | |
54 | - self.send(':FUNC "FREQ 1"') | |
55 | - self.send(':FREQ:ARM:STAR:SOUR IMM') | |
56 | - self.send(':FREQ:ARM:STOP:SOUR TIM') | |
57 | - self.send(':FREQ:ARM:STOP:TIM 1') | |
58 | - self.send(':ROSC:SOUR EXT') | |
59 | - self.send(':ROSC:EXT:CHECK OFF') | |
60 | - #self.send(':STAT:PRES') | |
61 | - self.send(':INIT:CONT ON') | |
54 | + self.send(':FUNC "FREQ 1"') | |
55 | + self.send(':FREQ:ARM:STAR:SOUR IMM') | |
56 | + self.send(':FREQ:ARM:STOP:SOUR TIM') | |
57 | + self.send(':FREQ:ARM:STOP:TIM 1') | |
58 | + self.send(':ROSC:SOUR EXT') | |
59 | + self.send(':ROSC:EXT:CHECK OFF') | |
60 | + #self.send(':STAT:PRES') | |
61 | + self.send(':INIT:CONT ON') | |
62 | 62 | |
63 | - def getValue(self): | |
64 | - self.send('FETC?') | |
65 | - #self.send('READ:FREQ?') | |
66 | - return self.read() | |
63 | + def getValue(self): | |
64 | + self.send('FETC?') | |
65 | + #self.send('READ:FREQ?') | |
66 | + return self.read() | |
67 | 67 | |
68 | - def read(self): | |
69 | - self.send("++read eoi") | |
70 | - ans = '' | |
71 | - nb_data_list = [] | |
72 | - nb_data = '' | |
73 | - try: | |
74 | - while ans != '\n': | |
75 | - ans = self.sock.recv(1) | |
76 | - nb_data_list.append(ans) # Return the number of data | |
77 | - list_size = len(nb_data_list) | |
78 | - for j in range (0, list_size): | |
79 | - nb_data = nb_data+nb_data_list[j] | |
80 | - return nb_data | |
81 | - except socket.timeout: | |
82 | - print "Socket timeout error when reading." | |
83 | - raise | |
68 | + def read(self): | |
69 | + self.send("++read eoi") | |
70 | + ans = '' | |
71 | + nb_data_list = [] | |
72 | + nb_data = '' | |
73 | + try: | |
74 | + while ans != '\n': | |
75 | + ans = self.sock.recv(1) | |
76 | + nb_data_list.append(ans) # Return the number of data | |
77 | + list_size = len(nb_data_list) | |
78 | + for j in range (0, list_size): | |
79 | + nb_data = nb_data+nb_data_list[j] | |
80 | + return nb_data | |
81 | + except socket.timeout: | |
82 | + print "Socket timeout error when reading." | |
83 | + raise | |
84 | 84 | |
85 | - def disconnect(self): | |
86 | - self.send('*RST') | |
87 | - self.sock.close() | |
85 | + def disconnect(self): | |
86 | + self.send('*RST') | |
87 | + self.sock.close() | |
88 | 88 | |
89 | - def send(self, command): | |
90 | - self.sock.send("%s\n"%command) | |
89 | + def send(self, command): | |
90 | + self.sock.send("%s\n"%command) | |
91 | 91 | |
92 | - def init_prologix(self): | |
93 | - try: | |
94 | - self.sock.send("++mode 1\n") # Set mode as CONTROLLER | |
95 | - self.sock.send('++addr ' + str(self.gpib_addr) + '\n') # Set the GPIB address | |
96 | - self.sock.send('++eos 3\n') # Set end-of-send character to nothing | |
97 | - self.sock.send("++eoi 1\n") # Assert EOI with last byte to indicate end | |
98 | - self.sock.send("++read_tmo_ms 2750\n") # Set read timeout | |
99 | - self.sock.send("++auto 0\n") # Turn off read-after-write to avoid | |
100 | - # "Query Unterminated" errors | |
92 | + def init_prologix(self): | |
93 | + try: | |
94 | + self.sock.send("++mode 1\n") # Set mode as CONTROLLER | |
95 | + self.sock.send('++addr ' + str(self.gpib_addr) + '\n') # Set the GPIB address | |
96 | + self.sock.send('++eos 3\n') # Set end-of-send character to nothing | |
97 | + self.sock.send("++eoi 1\n") # Assert EOI with last byte to indicate end | |
98 | + self.sock.send("++read_tmo_ms 2750\n") # Set read timeout | |
99 | + self.sock.send("++auto 0\n") # Turn off read-after-write to avoid | |
100 | + # "Query Unterminated" errors | |
101 | 101 | |
102 | - except self.socket.timeout: | |
103 | - print "Socket timeout" | |
104 | - raise | |
105 | - except self.socket.error as er: | |
106 | - print "Socket error: " + str(er) | |
107 | - raise | |
108 | - except Exception as er: | |
109 | - print "Unexpected error: " + str(er) | |
110 | - raise | |
102 | + except self.socket.timeout: | |
103 | + print "Socket timeout" | |
104 | + raise | |
105 | + except self.socket.error as er: | |
106 | + print "Socket error: " + str(er) | |
107 | + raise | |
108 | + except Exception as er: | |
109 | + print "Unexpected error: " + str(er) | |
110 | + raise |
instruments/LS350.py
... | ... | @@ -12,60 +12,60 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class LS350(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.port = 7777 | |
18 | - self.channels = channels | |
19 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.port = 7777 | |
18 | + self.channels = channels | |
19 | + self.vtypes = vtypes | |
20 | 20 | |
21 | - def model(self): | |
22 | - #self.send("*IDN?") | |
23 | - #return self.read() | |
24 | - return "LS350" | |
21 | + def model(self): | |
22 | + #self.send("*IDN?") | |
23 | + #return self.read() | |
24 | + return "LS350" | |
25 | 25 | |
26 | - def connect(self): | |
27 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | - self.sock = socket.socket(socket.AF_INET, | |
29 | - socket.SOCK_STREAM, | |
30 | - socket.IPPROTO_TCP) | |
31 | - self.sock.settimeout(10.0) # Don't hang around forever | |
32 | - self.sock.connect((self.address, self.port)) | |
33 | - print(' --> Ok') | |
34 | - print(self.model()) | |
35 | - self.configure() | |
26 | + def connect(self): | |
27 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
28 | + self.sock = socket.socket(socket.AF_INET, | |
29 | + socket.SOCK_STREAM, | |
30 | + socket.IPPROTO_TCP) | |
31 | + self.sock.settimeout(10.0) # Don't hang around forever | |
32 | + self.sock.connect((self.address, self.port)) | |
33 | + print(' --> Ok') | |
34 | + print(self.model()) | |
35 | + self.configure() | |
36 | 36 | |
37 | - def configure(self): | |
38 | - self.strCh = '' | |
39 | - for ch in self.channels: | |
40 | - self.strCh = self.strCh + '%s %s;'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch) | |
41 | - self.strCh = self.strCh[0:-1] | |
42 | - print(self.strCh) | |
37 | + def configure(self): | |
38 | + self.strCh = '' | |
39 | + for ch in self.channels: | |
40 | + self.strCh = self.strCh + '%s %s;'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch) | |
41 | + self.strCh = self.strCh[0:-1] | |
42 | + print(self.strCh) | |
43 | 43 | |
44 | - def getValue(self): | |
45 | - self.send(self.strCh) | |
46 | - return self.read() | |
44 | + def getValue(self): | |
45 | + self.send(self.strCh) | |
46 | + return self.read() | |
47 | 47 | |
48 | - def read(self): | |
49 | - self.send("++read eoi") | |
50 | - ans = '' | |
51 | - nb_data_list = [] | |
52 | - nb_data = '' | |
53 | - try: | |
54 | - while ans != '\n': | |
55 | - ans = self.sock.recv(1) | |
56 | - nb_data_list.append(ans) # Return the number of data | |
57 | - list_size = len(nb_data_list) | |
58 | - for j in range (0, list_size): | |
59 | - nb_data = nb_data+nb_data_list[j] | |
60 | - return nb_data | |
61 | - except socket.timeout: | |
62 | - print "Socket timeout error when reading." | |
63 | - raise | |
48 | + def read(self): | |
49 | + self.send("++read eoi") | |
50 | + ans = '' | |
51 | + nb_data_list = [] | |
52 | + nb_data = '' | |
53 | + try: | |
54 | + while ans != '\n': | |
55 | + ans = self.sock.recv(1) | |
56 | + nb_data_list.append(ans) # Return the number of data | |
57 | + list_size = len(nb_data_list) | |
58 | + for j in range (0, list_size): | |
59 | + nb_data = nb_data+nb_data_list[j] | |
60 | + return nb_data | |
61 | + except socket.timeout: | |
62 | + print "Socket timeout error when reading." | |
63 | + raise | |
64 | 64 | |
65 | - def disconnect(self): | |
66 | - self.send('MODE0') | |
67 | - self.sock.close() | |
65 | + def disconnect(self): | |
66 | + self.send('MODE0') | |
67 | + self.sock.close() | |
68 | 68 | |
69 | - def send(self, command): | |
70 | - self.sock.send("%s\n"%command) | |
69 | + def send(self, command): | |
70 | + self.sock.send("%s\n"%command) |
instruments/PM100D.py
... | ... | @@ -12,36 +12,36 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class PM100D(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.channels = channels | |
18 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.channels = channels | |
18 | + self.vtypes = vtypes | |
19 | 19 | |
20 | - def model(self): | |
21 | - #self.send("*IDN?") | |
22 | - #return self.read() | |
23 | - return "PM100D" | |
20 | + def model(self): | |
21 | + #self.send("*IDN?") | |
22 | + #return self.read() | |
23 | + return "PM100D" | |
24 | 24 | |
25 | - def connect(self): | |
26 | - print('Connecting to device @%s...' %(self.address)) | |
27 | - self.FILE = os.open(self.address, os.O_RDWR) | |
28 | - print(' --> Ok') | |
29 | - print(self.model()) | |
30 | - self.configure() | |
25 | + def connect(self): | |
26 | + print('Connecting to device @%s...' %(self.address)) | |
27 | + self.FILE = os.open(self.address, os.O_RDWR) | |
28 | + print(' --> Ok') | |
29 | + print(self.model()) | |
30 | + self.configure() | |
31 | 31 | |
32 | - def configure(self): | |
33 | - pass | |
32 | + def configure(self): | |
33 | + pass | |
34 | 34 | |
35 | - def getValue(self): | |
36 | - self.send("READ?") | |
37 | - return self.read() | |
35 | + def getValue(self): | |
36 | + self.send("READ?") | |
37 | + return self.read() | |
38 | 38 | |
39 | - def read(self): | |
40 | - return os.read(self.FILE, 300) | |
39 | + def read(self): | |
40 | + return os.read(self.FILE, 300) | |
41 | 41 | |
42 | - def disconnect(self): | |
43 | - self.send('*RST') | |
42 | + def disconnect(self): | |
43 | + self.send('*RST') | |
44 | 44 | |
45 | - def send(self, command): | |
46 | - os.write(self.FILE, command) | |
45 | + def send(self, command): | |
46 | + os.write(self.FILE, command) |
instruments/Sym5125A.py
... | ... | @@ -12,38 +12,38 @@ |
12 | 12 | #============================================================================== |
13 | 13 | |
14 | 14 | class Sym5125A(abstract_instrument): |
15 | - def __init__(self, channels, vtypes, address): | |
16 | - self.address = address | |
17 | - self.channels = channels | |
18 | - self.vtypes = vtypes | |
15 | + def __init__(self, channels, vtypes, address): | |
16 | + self.address = address | |
17 | + self.channels = channels | |
18 | + self.vtypes = vtypes | |
19 | 19 | |
20 | - def model(self): | |
21 | - #self.send("*IDN?") | |
22 | - #return self.read() | |
23 | - return "Sym5125A" | |
20 | + def model(self): | |
21 | + #self.send("*IDN?") | |
22 | + #return self.read() | |
23 | + return "Sym5125A" | |
24 | 24 | |
25 | - def connect(self): | |
26 | - print('Connecting to device @%s...' %(self.address)) | |
27 | - self.tn = telnetlib.Telnet(self.address, '1298') | |
28 | - #time.sleep(1) | |
29 | - print(' --> Ok') | |
30 | - print(self.model()) | |
31 | - self.configure() | |
25 | + def connect(self): | |
26 | + print('Connecting to device @%s...' %(self.address)) | |
27 | + self.tn = telnetlib.Telnet(self.address, '1298') | |
28 | + #time.sleep(1) | |
29 | + print(' --> Ok') | |
30 | + print(self.model()) | |
31 | + self.configure() | |
32 | 32 | |
33 | - def configure(self): | |
34 | - pass | |
33 | + def configure(self): | |
34 | + pass | |
35 | 35 | |
36 | - def getValue(self): | |
37 | - for i in range(1000): | |
38 | - mes = self.tn.read_until('\n').replace('\r\n','') | |
39 | - return mes + '\n' | |
36 | + def getValue(self): | |
37 | + for i in range(1000): | |
38 | + mes = self.tn.read_until('\n').replace('\r\n','') | |
39 | + return mes + '\n' | |
40 | 40 | |
41 | - def read(self): | |
42 | - pass | |
41 | + def read(self): | |
42 | + pass | |
43 | 43 | |
44 | - def disconnect(self): | |
45 | - self.tn.close() | |
44 | + def disconnect(self): | |
45 | + self.tn.close() | |
46 | 46 | |
47 | - def send(self, command): | |
48 | - pass | |
47 | + def send(self, command): | |
48 | + pass |
instruments/T7Pro.py
... | ... | @@ -14,81 +14,81 @@ |
14 | 14 | #============================================================================== |
15 | 15 | |
16 | 16 | class T7Pro(abstract_instrument): |
17 | - def __init__(self, channels, vtypes, address): | |
18 | - self.address = address | |
19 | - self.channels = channels | |
20 | - self.vtypes = vtypes | |
17 | + def __init__(self, channels, vtypes, address): | |
18 | + self.address = address | |
19 | + self.channels = channels | |
20 | + self.vtypes = vtypes | |
21 | 21 | |
22 | - def model(self): | |
23 | - return 'T7Pro' | |
22 | + def model(self): | |
23 | + return 'T7Pro' | |
24 | 24 | |
25 | - def connect(self): | |
26 | - print('Connecting to device @%s...' %(self.address)) | |
27 | - self.handle = ljm.openS("T7", "ETHERNET", self.address) | |
28 | - print(' --> Ok') | |
29 | - print(self.model()) | |
30 | - self.configure() | |
25 | + def connect(self): | |
26 | + print('Connecting to device @%s...' %(self.address)) | |
27 | + self.handle = ljm.openS("T7", "ETHERNET", self.address) | |
28 | + print(' --> Ok') | |
29 | + print(self.model()) | |
30 | + self.configure() | |
31 | 31 | |
32 | - def configure(self): | |
33 | - names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | |
34 | - "AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | |
35 | - "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | |
36 | - "AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | |
37 | - "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | |
38 | - "AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | |
39 | - "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | |
40 | - "AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX", | |
41 | - #"AIN8_NEGATIVE_CH", "AIN8_RANGE", "AIN8_RESOLUTION_INDEX", | |
42 | - #"AIN9_NEGATIVE_CH", "AIN9_RANGE", "AIN9_RESOLUTION_INDEX", | |
43 | - "AIN10_NEGATIVE_CH", "AIN10_RANGE", "AIN10_RESOLUTION_INDEX", | |
44 | - "AIN11_NEGATIVE_CH", "AIN11_RANGE", "AIN11_RESOLUTION_INDEX", | |
45 | - "AIN12_NEGATIVE_CH", "AIN12_RANGE", "AIN12_RESOLUTION_INDEX", | |
46 | - "AIN13_NEGATIVE_CH", "AIN13_RANGE", "AIN13_RESOLUTION_INDEX" | |
47 | - ] | |
48 | - l_names = len(names) | |
49 | - aValues = [1, 1, 12,#0 | |
50 | - 199, 1, 12,#1 | |
51 | - 3, 1, 12,#2 | |
52 | - 199, 1, 12,#3 | |
53 | - 5, 1, 12,#4 | |
54 | - 199, 1, 12,#5 | |
55 | - 7, 1, 12,#6 | |
56 | - 199, 1, 12,#7 | |
57 | - #199, 1, 12,#8 | |
58 | - #199, 1, 12,#9 | |
59 | - 199, 1, 12,#10 | |
60 | - 199, 1, 12,#11 | |
61 | - 199, 1, 12,#12 | |
62 | - 199, 1, 12#13 | |
63 | - ] | |
32 | + def configure(self): | |
33 | + names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | |
34 | + "AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | |
35 | + "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | |
36 | + "AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | |
37 | + "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | |
38 | + "AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | |
39 | + "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | |
40 | + "AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX", | |
41 | + #"AIN8_NEGATIVE_CH", "AIN8_RANGE", "AIN8_RESOLUTION_INDEX", | |
42 | + #"AIN9_NEGATIVE_CH", "AIN9_RANGE", "AIN9_RESOLUTION_INDEX", | |
43 | + "AIN10_NEGATIVE_CH", "AIN10_RANGE", "AIN10_RESOLUTION_INDEX", | |
44 | + "AIN11_NEGATIVE_CH", "AIN11_RANGE", "AIN11_RESOLUTION_INDEX", | |
45 | + "AIN12_NEGATIVE_CH", "AIN12_RANGE", "AIN12_RESOLUTION_INDEX", | |
46 | + "AIN13_NEGATIVE_CH", "AIN13_RANGE", "AIN13_RESOLUTION_INDEX" | |
47 | + ] | |
48 | + l_names = len(names) | |
49 | + aValues = [1, 1, 12,#0 | |
50 | + 199, 1, 12,#1 | |
51 | + 3, 1, 12,#2 | |
52 | + 199, 1, 12,#3 | |
53 | + 5, 1, 12,#4 | |
54 | + 199, 1, 12,#5 | |
55 | + 7, 1, 12,#6 | |
56 | + 199, 1, 12,#7 | |
57 | + #199, 1, 12,#8 | |
58 | + #199, 1, 12,#9 | |
59 | + 199, 1, 12,#10 | |
60 | + 199, 1, 12,#11 | |
61 | + 199, 1, 12,#12 | |
62 | + 199, 1, 12#13 | |
63 | + ] | |
64 | 64 | |
65 | - ljm.eWriteNames(self.handle, l_names, names, aValues) | |
65 | + ljm.eWriteNames(self.handle, l_names, names, aValues) | |
66 | 66 | |
67 | - def getValue(self): | |
68 | - strMes = '' | |
69 | - for ch in self.channels: | |
70 | - if self.vtypes[self.channels.index(ch)] == 'RES': | |
71 | - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
72 | - strMes = strMes + str(VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1]) + ';' | |
73 | - elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 K': | |
74 | - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
75 | - strMes = strMes + str(((VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1])/100.-1)/0.003850+273.15) + ';' | |
76 | - elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 C': | |
77 | - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
78 | - strMes = strMes + str(((VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1])/100.-1)/0.003850) + ';' | |
79 | - elif self.vtypes[self.channels.index(ch)] == 'TEMP AIR K': | |
80 | - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
81 | - strMes = strMes + str(raw[0]) + ';' | |
67 | + def getValue(self): | |
68 | + strMes = '' | |
69 | + for ch in self.channels: | |
70 | + if self.vtypes[self.channels.index(ch)] == 'RES': | |
71 | + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
72 | + strMes = strMes + str(VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1]) + ';' | |
73 | + elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 K': | |
74 | + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
75 | + strMes = strMes + str(((VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1])/100.-1)/0.003850+273.15) + ';' | |
76 | + elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 C': | |
77 | + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
78 | + strMes = strMes + str(((VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1])/100.-1)/0.003850) + ';' | |
79 | + elif self.vtypes[self.channels.index(ch)] == 'TEMP AIR K': | |
80 | + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) | |
81 | + strMes = strMes + str(raw[0]) + ';' | |
82 | 82 | |
83 | - strMes = strMes[0:-1] + '\n' | |
84 | - return(strMes) | |
83 | + strMes = strMes[0:-1] + '\n' | |
84 | + return(strMes) | |
85 | 85 | |
86 | - def read(self, names): | |
87 | - return ljm.eReadNames(self.handle, len(names), names) | |
86 | + def read(self, names): | |
87 | + return ljm.eReadNames(self.handle, len(names), names) | |
88 | 88 | |
89 | - def disconnect(self): | |
90 | - ljm.close(self.handle) | |
89 | + def disconnect(self): | |
90 | + ljm.close(self.handle) | |
91 | 91 | |
92 | - def send(self, command): | |
93 | - pass | |
92 | + def send(self, command): | |
93 | + pass |
instruments/TPG261.py
... | ... | @@ -10,36 +10,36 @@ |
10 | 10 | #============================================================================== |
11 | 11 | |
12 | 12 | class TPG261(abstract_instrument): |
13 | - def __init__(self, channels, vtypes, address): | |
14 | - self.address = address | |
15 | - self.channels = channels | |
16 | - self.vtypes = vtypes | |
13 | + def __init__(self, channels, vtypes, address): | |
14 | + self.address = address | |
15 | + self.channels = channels | |
16 | + self.vtypes = vtypes | |
17 | 17 | |
18 | - def model(self): | |
19 | - return "PfeifferTPG261" | |
18 | + def model(self): | |
19 | + return "PfeifferTPG261" | |
20 | 20 | |
21 | - def connect(self): | |
22 | - print('Connecting to device @%s...' %(self.address)) | |
23 | - self.TPG = MaxiGauge(self.address) | |
24 | - print(' --> Ok') | |
25 | - print(self.model()) | |
26 | - self.configure() | |
21 | + def connect(self): | |
22 | + print('Connecting to device @%s...' %(self.address)) | |
23 | + self.TPG = MaxiGauge(self.address) | |
24 | + print(' --> Ok') | |
25 | + print(self.model()) | |
26 | + self.configure() | |
27 | 27 | |
28 | - def configure(self): | |
29 | - pass | |
28 | + def configure(self): | |
29 | + pass | |
30 | 30 | |
31 | - def getValue(self): | |
32 | - self.read() | |
33 | - return "%s\n"%self.ps[0].pressure | |
31 | + def getValue(self): | |
32 | + self.read() | |
33 | + return "%s\n"%self.ps[0].pressure | |
34 | 34 | |
35 | - def read(self): | |
36 | - self.ps = self.TPG.pressures() | |
35 | + def read(self): | |
36 | + self.ps = self.TPG.pressures() | |
37 | 37 | |
38 | - def disconnect(self): | |
39 | - self.TPG.disconnect() | |
38 | + def disconnect(self): | |
39 | + self.TPG.disconnect() | |
40 | 40 | |
41 | - def send(self, command): | |
42 | - pass | |
41 | + def send(self, command): | |
42 | + pass | |
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | 65 | |
... | ... | @@ -47,135 +47,135 @@ |
47 | 47 | # from Philipp Klaus, philipp.l.klaus AT web.de PfeifferVacuum.py |
48 | 48 | |
49 | 49 | class MaxiGauge (object): |
50 | - def __init__(self, serialPort, baud=9600, debug=False): | |
51 | - self.debug=debug | |
52 | - try: | |
53 | - self.connection = serial.Serial(serialPort, baudrate=baud, timeout=0.2) | |
54 | - except serial.serialutil.SerialException as se: | |
55 | - raise MaxiGaugeError(se) | |
56 | - #self.send(C['ETX']) ### We might reset the connection first, but it doesn't really matter: | |
50 | + def __init__(self, serialPort, baud=9600, debug=False): | |
51 | + self.debug=debug | |
52 | + try: | |
53 | + self.connection = serial.Serial(serialPort, baudrate=baud, timeout=0.2) | |
54 | + except serial.serialutil.SerialException as se: | |
55 | + raise MaxiGaugeError(se) | |
56 | + #self.send(C['ETX']) ### We might reset the connection first, but it doesn't really matter: | |
57 | 57 | |
58 | - def checkDevice(self): | |
59 | - message = "The Display Contrast is currently set to %d (out of 20).\n" % self.displayContrast() | |
60 | - message += "Keys since MaxiGauge was switched on: %s (out of 1,2,3,4,5).\n" % ", ".join( map (str, self.pressedKeys()) ) | |
61 | - return message | |
58 | + def checkDevice(self): | |
59 | + message = "The Display Contrast is currently set to %d (out of 20).\n" % self.displayContrast() | |
60 | + message += "Keys since MaxiGauge was switched on: %s (out of 1,2,3,4,5).\n" % ", ".join( map (str, self.pressedKeys()) ) | |
61 | + return message | |
62 | 62 | |
63 | - def pressedKeys(self): | |
64 | - keys = int(self.send('TKB',1)[0]) | |
65 | - pressedKeys = [] | |
66 | - for i in [4,3,2,1,0]: # It's got 5 keys | |
67 | - if keys/2**i == 1: | |
68 | - pressedKeys.append(i+1) | |
69 | - keys = keys%2**i | |
70 | - pressedKeys.reverse() | |
71 | - return pressedKeys | |
63 | + def pressedKeys(self): | |
64 | + keys = int(self.send('TKB',1)[0]) | |
65 | + pressedKeys = [] | |
66 | + for i in [4,3,2,1,0]: # It's got 5 keys | |
67 | + if keys/2**i == 1: | |
68 | + pressedKeys.append(i+1) | |
69 | + keys = keys%2**i | |
70 | + pressedKeys.reverse() | |
71 | + return pressedKeys | |
72 | 72 | |
73 | - def displayContrast(self,newContrast=-1): | |
74 | - if newContrast == -1: return int(self.send('DCC',1)[0]) | |
75 | - else: return int(self.send('DCC,%d' % (newContrast,) ,1)[0]) | |
73 | + def displayContrast(self,newContrast=-1): | |
74 | + if newContrast == -1: return int(self.send('DCC',1)[0]) | |
75 | + else: return int(self.send('DCC,%d' % (newContrast,) ,1)[0]) | |
76 | 76 | |
77 | - def pressures(self): | |
78 | - return [self.pressure(i+1) for i in range(1)] | |
77 | + def pressures(self): | |
78 | + return [self.pressure(i+1) for i in range(1)] | |
79 | 79 | |
80 | - def pressure(self, sensor): | |
81 | - if sensor < 1 or sensor >6: raise MaxiGaugeError('Sensor can only be between 1 and 6. You choose ' + str(sensor)) | |
82 | - reading = self.send('PR%d' % sensor, 1) ## reading will have the form x,x.xxxEsx <CR><LF> (see p.88) | |
83 | - try: | |
84 | - r = reading[0].split(',') | |
85 | - status = int(r[0]) | |
86 | - pressure = float(r[-1]) | |
87 | - except: | |
88 | - raise MaxiGaugeError("Problem interpreting the returned line:\n%s" % reading) | |
89 | - return PressureReading(sensor, status, pressure) | |
80 | + def pressure(self, sensor): | |
81 | + if sensor < 1 or sensor >6: raise MaxiGaugeError('Sensor can only be between 1 and 6. You choose ' + str(sensor)) | |
82 | + reading = self.send('PR%d' % sensor, 1) ## reading will have the form x,x.xxxEsx <CR><LF> (see p.88) | |
83 | + try: | |
84 | + r = reading[0].split(',') | |
85 | + status = int(r[0]) | |
86 | + pressure = float(r[-1]) | |
87 | + except: | |
88 | + raise MaxiGaugeError("Problem interpreting the returned line:\n%s" % reading) | |
89 | + return PressureReading(sensor, status, pressure) | |
90 | 90 | |
91 | - def debugMessage(self, message): | |
92 | - if self.debug: print(repr(message)) | |
91 | + def debugMessage(self, message): | |
92 | + if self.debug: print(repr(message)) | |
93 | 93 | |
94 | - def send(self, mnemonic, numEnquiries = 0): | |
95 | - self.connection.flushInput() | |
96 | - self.write(mnemonic+LINE_TERMINATION) | |
97 | - #if mnemonic != C['ETX']: self.read() | |
98 | - #self.read() | |
99 | - self.getACQorNAK() | |
100 | - response = [] | |
101 | - for i in range(numEnquiries): | |
102 | - self.enquire() | |
103 | - response.append(self.read()) | |
104 | - return response | |
94 | + def send(self, mnemonic, numEnquiries = 0): | |
95 | + self.connection.flushInput() | |
96 | + self.write(mnemonic+LINE_TERMINATION) | |
97 | + #if mnemonic != C['ETX']: self.read() | |
98 | + #self.read() | |
99 | + self.getACQorNAK() | |
100 | + response = [] | |
101 | + for i in range(numEnquiries): | |
102 | + self.enquire() | |
103 | + response.append(self.read()) | |
104 | + return response | |
105 | 105 | |
106 | - def write(self,what): | |
107 | - self.debugMessage(what) | |
108 | - self.connection.write(what) | |
106 | + def write(self,what): | |
107 | + self.debugMessage(what) | |
108 | + self.connection.write(what) | |
109 | 109 | |
110 | - def enquire(self): | |
111 | - self.write(C['ENQ']) | |
110 | + def enquire(self): | |
111 | + self.write(C['ENQ']) | |
112 | 112 | |
113 | - def read(self): | |
114 | - data = "" | |
115 | - while True: | |
116 | - x = self.connection.read() | |
117 | - self.debugMessage(x) | |
118 | - data += x | |
119 | - if len(data)>1 and data[-2:]==LINE_TERMINATION: | |
120 | - break | |
121 | - return data[:-len(LINE_TERMINATION)] | |
113 | + def read(self): | |
114 | + data = "" | |
115 | + while True: | |
116 | + x = self.connection.read() | |
117 | + self.debugMessage(x) | |
118 | + data += x | |
119 | + if len(data)>1 and data[-2:]==LINE_TERMINATION: | |
120 | + break | |
121 | + return data[:-len(LINE_TERMINATION)] | |
122 | 122 | |
123 | - def getACQorNAK(self): | |
124 | - returncode = self.connection.readline() | |
125 | - self.debugMessage(returncode) | |
126 | - ## The following is usually expected but our MaxiGauge controller sometimes forgets this parameter... That seems to be a bug with the DCC command. | |
127 | - #if len(returncode)<3: raise MaxiGaugeError('Only received a line termination from MaxiGauge. Was expecting ACQ or NAK.') | |
128 | - if len(returncode)<3: self.debugMessage('Only received a line termination from MaxiGauge. Was expecting ACQ or NAK.') | |
129 | - if len(returncode)>2 and returncode[-3] == C['NAK']: | |
130 | - self.enquire() | |
131 | - returnedError = self.read() | |
132 | - error = str(returnedError).split(',' , 1) | |
133 | - print repr(error) | |
134 | - errmsg = { 'System Error': ERR_CODES[0][int(error[0])] , 'Gauge Error': ERR_CODES[1][int(error[1])] } | |
135 | - raise MaxiGaugeNAK(errmsg) | |
136 | - #if len(returncode)>2 and returncode[-3] != C['ACQ']: raise MaxiGaugeError('Expecting ACQ or NAK from MaxiGauge but neither were sent.') | |
137 | - if len(returncode)>2 and returncode[-3] != C['ACQ']: self.debugMessage('Expecting ACQ or NAK from MaxiGauge but neither were sent.') | |
138 | - # if no exception raised so far, the interface is just fine: | |
139 | - return returncode[:-(len(LINE_TERMINATION)+1)] | |
123 | + def getACQorNAK(self): | |
124 | + returncode = self.connection.readline() | |
125 | + self.debugMessage(returncode) | |
126 | + ## The following is usually expected but our MaxiGauge controller sometimes forgets this parameter... That seems to be a bug with the DCC command. | |
127 | + #if len(returncode)<3: raise MaxiGaugeError('Only received a line termination from MaxiGauge. Was expecting ACQ or NAK.') | |
128 | + if len(returncode)<3: self.debugMessage('Only received a line termination from MaxiGauge. Was expecting ACQ or NAK.') | |
129 | + if len(returncode)>2 and returncode[-3] == C['NAK']: | |
130 | + self.enquire() | |
131 | + returnedError = self.read() | |
132 | + error = str(returnedError).split(',' , 1) | |
133 | + print repr(error) | |
134 | + errmsg = { 'System Error': ERR_CODES[0][int(error[0])] , 'Gauge Error': ERR_CODES[1][int(error[1])] } | |
135 | + raise MaxiGaugeNAK(errmsg) | |
136 | + #if len(returncode)>2 and returncode[-3] != C['ACQ']: raise MaxiGaugeError('Expecting ACQ or NAK from MaxiGauge but neither were sent.') | |
137 | + if len(returncode)>2 and returncode[-3] != C['ACQ']: self.debugMessage('Expecting ACQ or NAK from MaxiGauge but neither were sent.') | |
138 | + # if no exception raised so far, the interface is just fine: | |
139 | + return returncode[:-(len(LINE_TERMINATION)+1)] | |
140 | 140 | |
141 | - def disconnect(self): | |
142 | - #self.send(C['ETX']) | |
143 | - if hasattr(self, 'connection') and self.connection: self.connection.close() | |
141 | + def disconnect(self): | |
142 | + #self.send(C['ETX']) | |
143 | + if hasattr(self, 'connection') and self.connection: self.connection.close() | |
144 | 144 | |
145 | - def __del__(self): | |
146 | - self.disconnect() | |
145 | + def __del__(self): | |
146 | + self.disconnect() | |
147 | 147 | |
148 | 148 | class PressureReading(object): |
149 | - def __init__(self, id, status, pressure): | |
150 | - if int(id) not in range(1,7): raise MaxiGaugeError('Pressure Gauge ID must be between 1-6') | |
151 | - self.id = int(id) | |
152 | - if int(status) not in PRESSURE_READING_STATUS.keys(): raise MaxiGaugeError('The Pressure Status must be in the range %s' % PRESSURE_READING_STATUS.keys()) | |
153 | - self.status = int(status) | |
154 | - self.pressure = float(pressure) | |
149 | + def __init__(self, id, status, pressure): | |
150 | + if int(id) not in range(1,7): raise MaxiGaugeError('Pressure Gauge ID must be between 1-6') | |
151 | + self.id = int(id) | |
152 | + if int(status) not in PRESSURE_READING_STATUS.keys(): raise MaxiGaugeError('The Pressure Status must be in the range %s' % PRESSURE_READING_STATUS.keys()) | |
153 | + self.status = int(status) | |
154 | + self.pressure = float(pressure) | |
155 | 155 | |
156 | - def statusMsg(self): | |
157 | - return PRESSURE_READING_STATUS[self.status] | |
156 | + def statusMsg(self): | |
157 | + return PRESSURE_READING_STATUS[self.status] | |
158 | 158 | |
159 | - def __repr__(self): | |
160 | - return "Gauge #%d: Status %d (%s), Pressure: %f mbar\n" % (self.id, self.status, self.statusMsg(), self.pressure) | |
159 | + def __repr__(self): | |
160 | + return "Gauge #%d: Status %d (%s), Pressure: %f mbar\n" % (self.id, self.status, self.statusMsg(), self.pressure) | |
161 | 161 | |
162 | 162 | |
163 | 163 | ### ------ now we define the exceptions that could occur ------ |
164 | 164 | |
165 | 165 | class MaxiGaugeError(Exception): |
166 | - pass | |
166 | + pass | |
167 | 167 | |
168 | 168 | class MaxiGaugeNAK(MaxiGaugeError): |
169 | - pass | |
169 | + pass | |
170 | 170 | |
171 | 171 | ### ------- Control Symbols as defined on p. 81 of the english |
172 | -### manual for the Pfeiffer Vacuum TPG256A ----------- | |
172 | +### manual for the Pfeiffer Vacuum TPG256A ----------- | |
173 | 173 | C = { |
174 | 174 | 'ETX': "\x03", # End of Text (Ctrl-C) Reset the interface |
175 | - 'CR': "\x0D", # Carriage Return Go to the beginning of line | |
176 | - 'LF': "\x0A", # Line Feed Advance by one line | |
177 | - 'ENQ': "\x05", # Enquiry Request for data transmission | |
178 | - 'ACQ': "\x06", # Acknowledge Positive report signal | |
175 | + 'CR': "\x0D", # Carriage Return Go to the beginning of line | |
176 | + 'LF': "\x0A", # Line Feed Advance by one line | |
177 | + 'ENQ': "\x05", # Enquiry Request for data transmission | |
178 | + 'ACQ': "\x06", # Acknowledge Positive report signal | |
179 | 179 | 'NAK': "\x15", # Negative Acknowledge Negative report signal |
180 | 180 | 'ESC': "\x1b", # Escape |
181 | 181 | } |
182 | 182 | |
183 | 183 | |
... | ... | @@ -184,74 +184,74 @@ |
184 | 184 | |
185 | 185 | ### Mnemonics as defined on p. 85 |
186 | 186 | M = [ |
187 | - 'BAU', # Baud rate Baud rate 95 | |
188 | - 'CAx', # Calibration factor Sensor x Calibration factor sensor x (1 ... 6) 92 | |
189 | - 'CID', # Measurement point names Measurement point names 88 | |
190 | - 'DCB', # Display control Bargraph Bargraph 89 | |
191 | - 'DCC', # Display control Contrast Display control contrast 90 | |
192 | - 'DCD', # Display control Digits Display digits 88 | |
193 | - 'DCS', # Display control Screensave Display control screensave 90 | |
194 | - 'DGS', # Degas Degas 93 | |
195 | - 'ERR', # Error Status Error status 97 | |
196 | - 'FIL', # Filter time constant Filter time constant 92 | |
197 | - 'FSR', # Full scale range of linear sensors Full scale range of linear sensors 93 | |
198 | - 'LOC', # Parameter setup lock Parameter setup lock 91 | |
199 | - 'NAD', # Node (device) address for RS485 Node (device) address for RS485 96 | |
200 | - 'OFC', # Offset correction Offset correction 93 | |
201 | - 'OFC', # Offset correction Offset correction 93 | |
202 | - 'PNR', # Program number Program number 98 | |
203 | - 'PRx', # Status, Pressure sensor x (1 ... 6) Status, Pressure sensor x (1 ... 6) 88 | |
204 | - 'PUC', # Underrange Ctrl Underrange control 91 | |
205 | - 'RSX', # Interface Interface 94 | |
206 | - 'SAV', # Save default Save default 94 | |
207 | - 'SCx', # Sensor control Sensor control 87 | |
208 | - 'SEN', # Sensor on/off Sensor on/off 86 | |
209 | - 'SPx', # Set Point Control Source for Relay xThreshold value setting, Allocation 90 | |
210 | - 'SPS', # Set Point Status A,B,C,D,E,F Set point status 91 | |
211 | - 'TAI', # Test program A/D Identify Test A/D converter identification inputs 100 | |
212 | - 'TAS', # Test program A/D Sensor Test A/D converter measurement value inputs 100 | |
213 | - 'TDI', # Display test Display test 98 | |
214 | - 'TEE', # EEPROM test EEPROM test 100 | |
215 | - 'TEP', # EPROM test EPROM test 99 | |
216 | - 'TID', # Sensor identification Sensor identification 101 | |
217 | - 'TKB', # Keyboard test Keyboard test 99 | |
218 | - 'TRA', # RAM test RAM test 99 | |
219 | - 'UNI', # Unit of measurement (Display) Unit of measurement (pressure) 89 | |
220 | - 'WDT', # Watchdog and System Error Control Watchdog and system error control 101 | |
187 | + 'BAU', # Baud rate Baud rate 95 | |
188 | + 'CAx', # Calibration factor Sensor x Calibration factor sensor x (1 ... 6) 92 | |
189 | + 'CID', # Measurement point names Measurement point names 88 | |
190 | + 'DCB', # Display control Bargraph Bargraph 89 | |
191 | + 'DCC', # Display control Contrast Display control contrast 90 | |
192 | + 'DCD', # Display control Digits Display digits 88 | |
193 | + 'DCS', # Display control Screensave Display control screensave 90 | |
194 | + 'DGS', # Degas Degas 93 | |
195 | + 'ERR', # Error Status Error status 97 | |
196 | + 'FIL', # Filter time constant Filter time constant 92 | |
197 | + 'FSR', # Full scale range of linear sensors Full scale range of linear sensors 93 | |
198 | + 'LOC', # Parameter setup lock Parameter setup lock 91 | |
199 | + 'NAD', # Node (device) address for RS485 Node (device) address for RS485 96 | |
200 | + 'OFC', # Offset correction Offset correction 93 | |
201 | + 'OFC', # Offset correction Offset correction 93 | |
202 | + 'PNR', # Program number Program number 98 | |
203 | + 'PRx', # Status, Pressure sensor x (1 ... 6) Status, Pressure sensor x (1 ... 6) 88 | |
204 | + 'PUC', # Underrange Ctrl Underrange control 91 | |
205 | + 'RSX', # Interface Interface 94 | |
206 | + 'SAV', # Save default Save default 94 | |
207 | + 'SCx', # Sensor control Sensor control 87 | |
208 | + 'SEN', # Sensor on/off Sensor on/off 86 | |
209 | + 'SPx', # Set Point Control Source for Relay xThreshold value setting, Allocation 90 | |
210 | + 'SPS', # Set Point Status A,B,C,D,E,F Set point status 91 | |
211 | + 'TAI', # Test program A/D Identify Test A/D converter identification inputs 100 | |
212 | + 'TAS', # Test program A/D Sensor Test A/D converter measurement value inputs 100 | |
213 | + 'TDI', # Display test Display test 98 | |
214 | + 'TEE', # EEPROM test EEPROM test 100 | |
215 | + 'TEP', # EPROM test EPROM test 99 | |
216 | + 'TID', # Sensor identification Sensor identification 101 | |
217 | + 'TKB', # Keyboard test Keyboard test 99 | |
218 | + 'TRA', # RAM test RAM test 99 | |
219 | + 'UNI', # Unit of measurement (Display) Unit of measurement (pressure) 89 | |
220 | + 'WDT', # Watchdog and System Error Control Watchdog and system error control 101 | |
221 | 221 | ] |
222 | 222 | |
223 | 223 | |
224 | 224 | ### Error codes as defined on p. 97 |
225 | 225 | ERR_CODES = [ |
226 | 226 | { |
227 | - 0: 'No error', | |
228 | - 1: 'Watchdog has responded', | |
229 | - 2: 'Task fail error', | |
230 | - 4: 'IDCX idle error', | |
231 | - 8: 'Stack overflow error', | |
232 | - 16: 'EPROM error', | |
233 | - 32: 'RAM error', | |
234 | - 64: 'EEPROM error', | |
235 | - 128: 'Key error', | |
236 | - 4096: 'Syntax error', | |
237 | - 8192: 'Inadmissible parameter', | |
238 | - 16384: 'No hardware', | |
239 | - 32768: 'Fatal error' | |
227 | + 0: 'No error', | |
228 | + 1: 'Watchdog has responded', | |
229 | + 2: 'Task fail error', | |
230 | + 4: 'IDCX idle error', | |
231 | + 8: 'Stack overflow error', | |
232 | + 16: 'EPROM error', | |
233 | + 32: 'RAM error', | |
234 | + 64: 'EEPROM error', | |
235 | + 128: 'Key error', | |
236 | + 4096: 'Syntax error', | |
237 | + 8192: 'Inadmissible parameter', | |
238 | + 16384: 'No hardware', | |
239 | + 32768: 'Fatal error' | |
240 | 240 | } , |
241 | 241 | { |
242 | - 0: 'No error', | |
243 | - 1: 'Sensor 1: Measurement error', | |
244 | - 2: 'Sensor 2: Measurement error', | |
245 | - 4: 'Sensor 3: Measurement error', | |
246 | - 8: 'Sensor 4: Measurement error', | |
247 | - 16: 'Sensor 5: Measurement error', | |
248 | - 32: 'Sensor 6: Measurement error', | |
249 | - 512: 'Sensor 1: Identification error', | |
250 | - 1024: 'Sensor 2: Identification error', | |
251 | - 2048: 'Sensor 3: Identification error', | |
252 | - 4096: 'Sensor 4: Identification error', | |
253 | - 8192: 'Sensor 5: Identification error', | |
254 | - 16384: 'Sensor 6: Identification error', | |
242 | + 0: 'No error', | |
243 | + 1: 'Sensor 1: Measurement error', | |
244 | + 2: 'Sensor 2: Measurement error', | |
245 | + 4: 'Sensor 3: Measurement error', | |
246 | + 8: 'Sensor 4: Measurement error', | |
247 | + 16: 'Sensor 5: Measurement error', | |
248 | + 32: 'Sensor 6: Measurement error', | |
249 | + 512: 'Sensor 1: Identification error', | |
250 | + 1024: 'Sensor 2: Identification error', | |
251 | + 2048: 'Sensor 3: Identification error', | |
252 | + 4096: 'Sensor 4: Identification error', | |
253 | + 8192: 'Sensor 5: Identification error', | |
254 | + 16384: 'Sensor 6: Identification error', | |
255 | 255 | } |
256 | 256 | ] |
257 | 257 |
instruments/__init__.py
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | from os.path import dirname |
3 | 3 | |
4 | 4 | for module in listdir(dirname(__file__)): |
5 | - if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | |
6 | - continue | |
7 | - __import__(module[:-3], locals(), globals()) | |
5 | + if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | |
6 | + continue | |
7 | + __import__(module[:-3], locals(), globals()) | |
8 | 8 | |
9 | 9 | del module, listdir, dirname |
instruments/abstract_instrument.py
1 | 1 | import abc |
2 | 2 | |
3 | 3 | class abstract_instrument(object): |
4 | - __metaclass__ = abc.ABCMeta | |
4 | + __metaclass__ = abc.ABCMeta | |
5 | 5 | |
6 | - @abc.abstractmethod | |
7 | - def __init__(self, address, vtype, channel): | |
8 | - """Build the class""" | |
9 | - return | |
6 | + @abc.abstractmethod | |
7 | + def __init__(self, address, vtype, channel): | |
8 | + """Build the class""" | |
9 | + return | |
10 | 10 | |
11 | - @abc.abstractmethod | |
12 | - def model(self): | |
13 | - """return the instrument model""" | |
14 | - return | |
11 | + @abc.abstractmethod | |
12 | + def model(self): | |
13 | + """return the instrument model""" | |
14 | + return | |
15 | 15 | |
16 | - @abc.abstractmethod | |
17 | - def connect(self): | |
18 | - """Create a connection with the instrument""" | |
19 | - return | |
16 | + @abc.abstractmethod | |
17 | + def connect(self): | |
18 | + """Create a connection with the instrument""" | |
19 | + return | |
20 | 20 | |
21 | - @abc.abstractmethod | |
22 | - def disconnect(self): | |
23 | - """Disconnect the instrument""" | |
24 | - return | |
21 | + @abc.abstractmethod | |
22 | + def disconnect(self): | |
23 | + """Disconnect the instrument""" | |
24 | + return | |
25 | 25 | |
26 | - @abc.abstractmethod | |
27 | - def configure(self): | |
28 | - """Configure the instrument""" | |
29 | - return | |
26 | + @abc.abstractmethod | |
27 | + def configure(self): | |
28 | + """Configure the instrument""" | |
29 | + return | |
30 | 30 | |
31 | - @abc.abstractmethod | |
32 | - def read(self): | |
33 | - """read the buffer""" | |
34 | - return | |
31 | + @abc.abstractmethod | |
32 | + def read(self): | |
33 | + """read the buffer""" | |
34 | + return | |
35 | 35 | |
36 | - @abc.abstractmethod | |
37 | - def send(self): | |
38 | - """send a command""" | |
39 | - return | |
36 | + @abc.abstractmethod | |
37 | + def send(self): | |
38 | + """send a command""" | |
39 | + return | |
40 | 40 | |
41 | - @abc.abstractmethod | |
42 | - def getValue(self): | |
43 | - """return the value of measurment""" | |
44 | - return | |
41 | + @abc.abstractmethod | |
42 | + def getValue(self): | |
43 | + """return the value of measurment""" | |
44 | + return |
instruments/testDevice.py
... | ... | @@ -10,41 +10,41 @@ |
10 | 10 | #============================================================================== |
11 | 11 | |
12 | 12 | class testDevice(abstract_instrument): |
13 | - def __init__(self, channels, vtype, address): | |
14 | - self.address = address | |
15 | - self.port = 9999 | |
16 | - self.channels = channels | |
17 | - self.vtype = vtype | |
13 | + def __init__(self, channels, vtype, address): | |
14 | + self.address = address | |
15 | + self.port = 9999 | |
16 | + self.channels = channels | |
17 | + self.vtype = vtype | |
18 | 18 | |
19 | - def model(self): | |
20 | - return 'test_device' | |
19 | + def model(self): | |
20 | + return 'test_device' | |
21 | 21 | |
22 | - def connect(self): | |
23 | - print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
24 | - time.sleep(1) | |
25 | - print(' --> Ok') | |
26 | - self.configure() | |
22 | + def connect(self): | |
23 | + print('Connecting to device @%s:%s...' %(self.address, self.port)) | |
24 | + time.sleep(1) | |
25 | + print(' --> Ok') | |
26 | + self.configure() | |
27 | 27 | |
28 | - print(self.model()) | |
28 | + print(self.model()) | |
29 | 29 | |
30 | - def getValue(self): | |
31 | - mes = "" | |
32 | - for ch in self.channels: | |
33 | - mes = mes + str(numpy.random.rand()) + '\t' | |
34 | - return mes + '\n' | |
30 | + def getValue(self): | |
31 | + mes = "" | |
32 | + for ch in self.channels: | |
33 | + mes = mes + str(numpy.random.rand()) + '\t' | |
34 | + return mes + '\n' | |
35 | 35 | |
36 | - def read(self): | |
37 | - print('reading') | |
38 | - return 1 | |
36 | + def read(self): | |
37 | + print('reading') | |
38 | + return 1 | |
39 | 39 | |
40 | - def disconnect(self): | |
41 | - print('disconnect') | |
40 | + def disconnect(self): | |
41 | + print('disconnect') | |
42 | 42 | |
43 | - def send(self, command): | |
44 | - print('send %s'%command) | |
43 | + def send(self, command): | |
44 | + print('send %s'%command) | |
45 | 45 | |
46 | - def configure(self): | |
47 | - print(self.channels) | |
48 | - print(self.vtype) | |
49 | - print('configured') | |
46 | + def configure(self): | |
47 | + print(self.channels) | |
48 | + print(self.vtype) | |
49 | + print('configured') |