Commit 9058343c5602e7323ae51461c67dbb88c54de3a8
1 parent
d803624996
Exists in
master
some minor fixes
Showing 10 changed files with 52 additions and 52 deletions Inline Diff
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, adress, path = os.getcwd(), samplingtime = 1, fileduration = 24*3600): | 13 | 13 | def __init__(self, instrument, channels, vtypes, address, path = os.getcwd(), samplingtime = 1, fileduration = 24*3600): | |
exec('self.instrument = instruments.%s.%s(%s, %s, "%s")'%(instrument, instrument, channels, vtypes, adress)) | 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("+", "") | |
64 | 64 | |||
string = "%f\t%f\t%s" % (epoch, mjd, meas) | 65 | 65 | string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
self.data_file.write(string) # Write in a file | 66 | 66 | self.data_file.write(string) # Write in a file | |
print(string) | 67 | 67 | print(string) | |
68 | 68 | |||
self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) | 69 | 69 | self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) | |
self.thread.start() | 70 | 70 | self.thread.start() | |
71 | 71 | |||
def stop(self): | 72 | 72 | def stop(self): | |
self.thread.cancel() | 73 | 73 | self.thread.cancel() | |
self.instrument.disconnect() | 74 | 74 | self.instrument.disconnect() | |
self.data_file.close() | 75 | 75 | self.data_file.close() | |
76 | 76 | |||
#============================================================================== | 77 | 77 | #============================================================================== | |
#============================================================================== | 78 | 78 | #============================================================================== | |
79 | 79 | |||
class mainGui(): | 80 | 80 | class mainGui(): | |
def __init__(self): | 81 | 81 | def __init__(self): | |
self.setWindow() | 82 | 82 | self.setWindow() | |
self.setSignalsSlots() | 83 | 83 | self.setSignalsSlots() | |
self.runApp() | 84 | 84 | self.runApp() | |
85 | 85 | |||
def setWindow(self): | 86 | 86 | def setWindow(self): | |
self.a = QtGui.QApplication(sys.argv) | 87 | 87 | self.a = QtGui.QApplication(sys.argv) | |
self.w = QtGui.QMainWindow() | 88 | 88 | self.w = QtGui.QMainWindow() | |
self.w.resize(640, 480) | 89 | 89 | self.w.resize(640, 480) | |
self.w.setWindowTitle('datalogger-gui') | 90 | 90 | self.w.setWindowTitle('datalogger-gui') | |
91 | 91 | |||
self.wid = QtGui.QWidget() | 92 | 92 | self.wid = QtGui.QWidget() | |
self.w.setCentralWidget(self.wid) | 93 | 93 | self.w.setCentralWidget(self.wid) | |
self.layout = QtGui.QGridLayout() | 94 | 94 | self.layout = QtGui.QGridLayout() | |
self.wid.setLayout(self.layout) | 95 | 95 | self.wid.setLayout(self.layout) | |
96 | 96 | |||
self.comboInst = QtGui.QComboBox() | 97 | 97 | self.comboInst = QtGui.QComboBox() | |
self.layout.addWidget(self.comboInst, 0, 0) | 98 | 98 | self.layout.addWidget(self.comboInst, 0, 0) | |
99 | 99 | |||
self.adress = QtGui.QLineEdit() | 100 | 100 | self.address = QtGui.QLineEdit() | |
self.adress.setMaximumWidth(120) | 101 | 101 | self.address.setMaximumWidth(120) | |
self.layout.addWidget(self.adress, 99, 0) | 102 | 102 | self.layout.addWidget(self.address, 99, 0) | |
103 | 103 | |||
self.startButton = QtGui.QPushButton() | 104 | 104 | self.startButton = QtGui.QPushButton() | |
self.startButton.setText('Start log') | 105 | 105 | self.startButton.setText('Start log') | |
self.layout.addWidget(self.startButton, 99, 1) | 106 | 106 | self.layout.addWidget(self.startButton, 99, 1) | |
self.startButton.setEnabled(False) | 107 | 107 | self.startButton.setEnabled(False) | |
108 | 108 | |||
self.stopButton = QtGui.QPushButton() | 109 | 109 | self.stopButton = QtGui.QPushButton() | |
self.stopButton.setText('Stop log') | 110 | 110 | self.stopButton.setText('Stop log') | |
self.layout.addWidget(self.stopButton, 99, 2) | 111 | 111 | self.layout.addWidget(self.stopButton, 99, 2) | |
self.stopButton.setEnabled(False) | 112 | 112 | self.stopButton.setEnabled(False) | |
113 | 113 | |||
self.textDisplay = QtGui.QLabel() | 114 | 114 | self.textDisplay = QtGui.QLabel() | |
self.textDisplay.setText('>>') | 115 | 115 | self.textDisplay.setText('>>') | |
self.layout.addWidget(self.textDisplay, 100, 2) | 116 | 116 | self.layout.addWidget(self.textDisplay, 100, 2) | |
117 | 117 | |||
self.setComboInst() | 118 | 118 | self.setComboInst() | |
self.updateSignal() | 119 | 119 | self.updateSignal() | |
120 | 120 | |||
def setComboInst(self): | 121 | 121 | def setComboInst(self): | |
for name, obj in inspect.getmembers(instruments): | 122 | 122 | for name, obj in inspect.getmembers(instruments): | |
if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | 123 | 123 | if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
self.comboInst.addItem(name) | 124 | 124 | self.comboInst.addItem(name) | |
125 | 125 | |||
def setSignalsSlots(self): | 126 | 126 | def setSignalsSlots(self): | |
self.comboInst.currentIndexChanged.connect(self.updateSignal) | 127 | 127 | self.comboInst.currentIndexChanged.connect(self.updateSignal) | |
self.startButton.clicked.connect(self.startLog) | 128 | 128 | self.startButton.clicked.connect(self.startLog) | |
self.stopButton.clicked.connect(self.stopLog) | 129 | 129 | self.stopButton.clicked.connect(self.stopLog) | |
130 | 130 | |||
def runApp(self): | 131 | 131 | def runApp(self): | |
self.w.show() | 132 | 132 | self.w.show() | |
sys.exit(self.a.exec_()) | 133 | 133 | sys.exit(self.a.exec_()) | |
134 | 134 | |||
@pyqtSlot() | 135 | 135 | @pyqtSlot() | |
def updateSignal(self): | 136 | 136 | def updateSignal(self): | |
for i in reversed(range(5, self.layout.count())): | 137 | 137 | for i in reversed(range(5, self.layout.count())): | |
self.layout.itemAt(i).widget().setParent(None) | 138 | 138 | self.layout.itemAt(i).widget().setParent(None) | |
139 | 139 | |||
defaultAdress = '' | 140 | 140 | defaultAddress = '' | |
channelsAviables = [] | 141 | 141 | channelsAviables = [] | |
vtypesAviables = [] | 142 | 142 | vtypesAviables = [] | |
143 | 143 | |||
exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) | 144 | 144 | exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) | |
exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) | 145 | 145 | exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) | |
exec('defaultAdress = instruments.%s.ADRESS'%self.comboInst.currentText()) | 146 | 146 | exec('defaultAddress = instruments.%s.ADDRESS'%self.comboInst.currentText()) | |
147 | 147 | |||
self.adress.setText(defaultAdress) | 148 | 148 | self.address.setText(defaultAddress) | |
149 | 149 | |||
self.checkBoxChannels = [None]*len(channelsAviables) | 150 | 150 | self.checkBoxChannels = [None]*len(channelsAviables) | |
self.chListVtypes = [None]*len(self.checkBoxChannels) | 151 | 151 | self.chListVtypes = [None]*len(self.checkBoxChannels) | |
152 | 152 | |||
for i in range(len(self.checkBoxChannels)): | 153 | 153 | for i in range(len(self.checkBoxChannels)): | |
self.checkBoxChannels[i] = QtGui.QCheckBox() | 154 | 154 | self.checkBoxChannels[i] = QtGui.QCheckBox() | |
self.checkBoxChannels[i].setText(channelsAviables[i]) | 155 | 155 | self.checkBoxChannels[i].setText(channelsAviables[i]) | |
self.checkBoxChannels[i].setChecked(False) | 156 | 156 | self.checkBoxChannels[i].setChecked(False) | |
self.chListVtypes[i] = QtGui.QListWidget() | 157 | 157 | self.chListVtypes[i] = QtGui.QListWidget() | |
for vtype in vtypesAviables: | 158 | 158 | for vtype in vtypesAviables: | |
self.chListVtypes[i].addItem(vtype) | 159 | 159 | self.chListVtypes[i].addItem(vtype) | |
self.chListVtypes[i].setCurrentRow(0) | 160 | 160 | self.chListVtypes[i].setCurrentRow(0) | |
self.layout.addWidget(self.checkBoxChannels[i], i, 1) | 161 | 161 | self.layout.addWidget(self.checkBoxChannels[i], i, 1) | |
self.layout.addWidget(self.chListVtypes[i], i, 2) | 162 | 162 | self.layout.addWidget(self.chListVtypes[i], i, 2) | |
self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) | 163 | 163 | self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) | |
self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) | 164 | 164 | self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) | |
165 | 165 | |||
self.adress.textChanged.connect(self.infoSignal) | 166 | 166 | self.address.textChanged.connect(self.infoSignal) | |
167 | 167 | |||
self.infoSignal() | 168 | 168 | self.infoSignal() | |
169 | 169 | |||
@pyqtSlot() | 170 | 170 | @pyqtSlot() | |
def infoSignal(self): | 171 | 171 | def infoSignal(self): | |
self.instToLog = self.comboInst.currentText() | 172 | 172 | self.instToLog = self.comboInst.currentText() | |
self.adressToLog = self.adress.text() | 173 | 173 | self.addressToLog = self.address.text() | |
self.chToLog = [] | 174 | 174 | self.chToLog = [] | |
self.vTypeToLog = [] | 175 | 175 | self.vTypeToLog = [] | |
176 | 176 | |||
for i in range(len(self.checkBoxChannels)): | 177 | 177 | for i in range(len(self.checkBoxChannels)): | |
if self.checkBoxChannels[i].isChecked(): | 178 | 178 | if self.checkBoxChannels[i].isChecked(): | |
self.chListVtypes[i].setEnabled(True) | 179 | 179 | self.chListVtypes[i].setEnabled(True) | |
self.chToLog.append(str(self.checkBoxChannels[i].text())) | 180 | 180 | self.chToLog.append(str(self.checkBoxChannels[i].text())) | |
self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) | 181 | 181 | self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) | |
else: | 182 | 182 | else: | |
self.chListVtypes[i].setEnabled(False) | 183 | 183 | self.chListVtypes[i].setEnabled(False) | |
184 | 184 | |||
allChannelsUnchecked = False | 185 | 185 | allChannelsUnchecked = False | |
for i in self.checkBoxChannels: | 186 | 186 | for i in self.checkBoxChannels: | |
allChannelsUnchecked = allChannelsUnchecked or i.isChecked() | 187 | 187 | allChannelsUnchecked = allChannelsUnchecked or i.isChecked() | |
if allChannelsUnchecked == False: | 188 | 188 | if allChannelsUnchecked == False: | |
self.startButton.setEnabled(False) | 189 | 189 | self.startButton.setEnabled(False) | |
else: | 190 | 190 | else: | |
self.startButton.setEnabled(True) | 191 | 191 | self.startButton.setEnabled(True) | |
192 | 192 | |||
self.textDisplay.setText('>> %s@%s - %s - %s'%(self.instToLog, self.adressToLog, self.chToLog, self.vTypeToLog)) | 193 | 193 | self.textDisplay.setText('>> %s@%s - %s - %s'%(self.instToLog, self.addressToLog, self.chToLog, self.vTypeToLog)) | |
194 | 194 | |||
self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.adressToLog) | 195 | 195 | self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.addressToLog) | |
196 | 196 | |||
@pyqtSlot() | 197 | 197 | @pyqtSlot() | |
def startLog(self): | 198 | 198 | def startLog(self): | |
self.startButton.setEnabled(False) | 199 | 199 | self.startButton.setEnabled(False) |
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 | |||
ADRESS = "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, adress=ADRESS): | 15 | 15 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress, 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.adress, 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 |
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 | |||
ADRESS = "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, adress): | 15 | 15 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress, 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.adress, 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 |
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 | |||
ADRESS = "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, adress): | 15 | 15 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress, 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.adress, 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 |
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 | |||
ADRESS = "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, adress): | 15 | 15 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress, 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.adress, 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 |
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 | |||
ADRESS = "/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, adress): | 15 | 15 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress)) | 26 | 26 | print('Connecting to device @%s...' %(self.address)) | |
self.FILE = os.open(self.adress, 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): |
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'] | 7 | 7 | ALL_VAL_TYPE = ['RES', 'TEMP PT100 K', 'TEMP PT100 C'] | |
ALL_CHANNELS = ['1', '2', '3', '4'] | 8 | 8 | ALL_CHANNELS = ['1', '2', '3', '4'] | |
9 | 9 | |||
ADRESS = "192.168.0.25" | 10 | 10 | ADDRESS = "192.168.0.25" | |
CONF_CHANNELS = [["AIN0", "AIN10"], ["AIN2", "AIN11"], ["AIN4", "AIN12"], ["AIN6", "AIN13"]] | 11 | 11 | CONF_CHANNELS = [["AIN0", "AIN10"], ["AIN2", "AIN11"], ["AIN4", "AIN12"], ["AIN6", "AIN13"]] | |
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, adress): | 17 | 17 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress)) | 26 | 26 | print('Connecting to device @%s...' %(self.address)) | |
self.handle = ljm.openS("T7", "ETHERNET", self.adress) | 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) + ';' | |
79 | 79 | |||
strMes = strMes[0:-1] + '\n' | 80 | 80 | strMes = strMes[0:-1] + '\n' | |
return(strMes) | 81 | 81 | return(strMes) |
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'] | |
ADRESS = "/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, adress): | 13 | 13 | def __init__(self, channels, vtypes, address): | |
self.adress = adress | 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.adress)) | 22 | 22 | print('Connecting to device @%s...' %(self.address)) | |
self.TPG = MaxiGauge(self.adress) | 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', |
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, adress, 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 |
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 = 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 |