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