diff --git a/datalogger-gui.py b/datalogger-gui.py index 0a53ea9..163c831 100755 --- a/datalogger-gui.py +++ b/datalogger-gui.py @@ -10,243 +10,243 @@ from PyQt4.QtCore import pyqtSlot #============================================================================== class acq_routine(): - 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)) - self.path = path - self.samplingtime = samplingtime - self.fileduration = fileduration - - def makeTree(self): - try: - year = time.strftime("%Y", time.gmtime(self.t0)) - month = time.strftime("%Y-%m", time.gmtime(self.t0)) - os.chdir(self.path + '/' + year + '/' + month) - except: - try: - os.chdir(self.path + '/' + year) - os.mkdir(month) - os.chdir(self.path + '/' + year + '/' + month) - except: - os.chdir(self.path) - os.mkdir(year) - os.chdir(self.path + '/' + year) - os.mkdir(month) - os.chdir(self.path + '/' + year + '/' + month) - - def connect(self): - self.instrument.connect() - - self.t0 = time.time() - self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' - self.makeTree() - self.data_file = open(self.filename, 'wr', 0) - - def start(self): - tic = time.time() - - if (time.time() - self.t0 >= self.fileduration) & (self.fileduration >0 ): - self.data_file.close() - - self.t0 = time.time() - self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' - self.makeTree() - self.data_file = open(self.filename, 'wr', 0) - - #epoch time - epoch = time.time() - #MJD time - mjd = epoch / 86400.0 + 40587 - # Meas values - meas = self.instrument.getValue() - meas = meas.replace(",", "\t") - meas = meas.replace(";", "\t") - meas = meas.replace("+", "") - meas = meas.replace("E", "e") - - string = "%f\t%f\t%s" % (epoch, mjd, meas) - self.data_file.write(string) # Write in a file - print(string) - - self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) - self.thread.start() - - def stop(self): - self.thread.cancel() - self.instrument.disconnect() - self.data_file.close() + 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)) + self.path = path + self.samplingtime = samplingtime + self.fileduration = fileduration + + def makeTree(self): + try: + year = time.strftime("%Y", time.gmtime(self.t0)) + month = time.strftime("%Y-%m", time.gmtime(self.t0)) + os.chdir(self.path + '/' + year + '/' + month) + except: + try: + os.chdir(self.path + '/' + year) + os.mkdir(month) + os.chdir(self.path + '/' + year + '/' + month) + except: + os.chdir(self.path) + os.mkdir(year) + os.chdir(self.path + '/' + year) + os.mkdir(month) + os.chdir(self.path + '/' + year + '/' + month) + + def connect(self): + self.instrument.connect() + + self.t0 = time.time() + self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' + self.makeTree() + self.data_file = open(self.filename, 'wr', 0) + + def start(self): + tic = time.time() + + if (time.time() - self.t0 >= self.fileduration) & (self.fileduration >0 ): + self.data_file.close() + + self.t0 = time.time() + self.filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(self.t0)) + '-' + self.instrument.model() + '.dat' + self.makeTree() + self.data_file = open(self.filename, 'wr', 0) + + #epoch time + epoch = time.time() + #MJD time + mjd = epoch / 86400.0 + 40587 + # Meas values + meas = self.instrument.getValue() + meas = meas.replace(",", "\t") + meas = meas.replace(";", "\t") + meas = meas.replace("+", "") + meas = meas.replace("E", "e") + + string = "%f\t%f\t%s" % (epoch, mjd, meas) + self.data_file.write(string) # Write in a file + print(string) + + self.thread = threading.Timer(self.samplingtime - (time.time() - tic), self.start) + self.thread.start() + + def stop(self): + self.thread.cancel() + self.instrument.disconnect() + self.data_file.close() #============================================================================== #============================================================================== class mainGui(): - def __init__(self): - self.setWindow() - self.setSignalsSlots() - self.runApp() - - def setWindow(self): - self.a = QtGui.QApplication(sys.argv) - self.w = QtGui.QMainWindow() - self.w.resize(640, 480) - self.w.setWindowTitle('datalogger-gui') - - self.wid = QtGui.QWidget() - self.w.setCentralWidget(self.wid) - self.layout = QtGui.QGridLayout() - self.wid.setLayout(self.layout) - - self.comboInst = QtGui.QComboBox() - self.layout.addWidget(self.comboInst, 0, 0) - - self.address = QtGui.QLineEdit() - self.address.setMinimumWidth(140) - self.address.setMaximumWidth(140) - self.layout.addWidget(self.address, 0, 1) - - self.samplingtime = QtGui.QDoubleSpinBox() - #self.samplingtime.setMinimumWidth(60) - #self.samplingtime.setMaximumWidth(60) - self.samplingtime.setMinimum(0.1) - self.samplingtime.setMaximum(1000) - self.samplingtime.setSingleStep(0.1) - self.samplingtime.setValue(1) - self.layout.addWidget(self.samplingtime, 0, 2) - - self.startButton = QtGui.QPushButton() - self.startButton.setText('Start log') - self.layout.addWidget(self.startButton, 99, 0) - self.startButton.setEnabled(False) - - self.stopButton = QtGui.QPushButton() - self.stopButton.setText('Stop log') - self.layout.addWidget(self.stopButton, 99, 1) - self.stopButton.setEnabled(False) - - self.textDisplay = QtGui.QLabel() - self.textDisplay.setText('>>') - self.layout.addWidget(self.textDisplay, 99, 2) - - self.setComboInst() - self.updateSignal() - - def setComboInst(self): - for name, obj in inspect.getmembers(instruments): - if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: - self.comboInst.addItem(name) - - def setSignalsSlots(self): - self.comboInst.currentIndexChanged.connect(self.updateSignal) - self.startButton.clicked.connect(self.startLog) - self.stopButton.clicked.connect(self.stopLog) - - def runApp(self): - self.w.show() - self.a.aboutToQuit.connect(self.closeEvent) - sys.exit(self.a.exec_()) - - def closeEvent(self): - try: - self.stopLog() - except: - pass - print('Done') - - @pyqtSlot() - def updateSignal(self): - for i in reversed(range(5, self.layout.count())): - self.layout.itemAt(i).widget().setParent(None) - - defaultAddress = '' - channelsAviables = [] - vtypesAviables = [] - - exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) - exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) - exec('defaultAddress = instruments.%s.ADDRESS'%self.comboInst.currentText()) - - self.address.setText(defaultAddress) - - self.checkBoxChannels = [None]*len(channelsAviables) - self.chListVtypes = [None]*len(self.checkBoxChannels) - - for i in range(len(self.checkBoxChannels)): - self.checkBoxChannels[i] = QtGui.QCheckBox() - self.checkBoxChannels[i].setText(channelsAviables[i]) - self.checkBoxChannels[i].setChecked(False) - self.chListVtypes[i] = QtGui.QListWidget() - for vtype in vtypesAviables: - self.chListVtypes[i].addItem(vtype) - self.chListVtypes[i].setCurrentRow(0) - self.layout.addWidget(self.checkBoxChannels[i], i+3, 1) - self.layout.addWidget(self.chListVtypes[i], i+3, 2) - self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) - self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) - - self.address.textChanged.connect(self.infoSignal) - self.samplingtime.valueChanged.connect(self.infoSignal) - - self.infoSignal() - - @pyqtSlot() - def infoSignal(self): - self.instToLog = self.comboInst.currentText() - self.addressToLog = self.address.text() - self.chToLog = [] - self.vTypeToLog = [] - self.ts = self.samplingtime.value() - - for i in range(len(self.checkBoxChannels)): - if self.checkBoxChannels[i].isChecked(): - self.chListVtypes[i].setEnabled(True) - self.chToLog.append(str(self.checkBoxChannels[i].text())) - self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) - else: - self.chListVtypes[i].setEnabled(False) - - allChannelsUnchecked = False - for i in self.checkBoxChannels: - allChannelsUnchecked = allChannelsUnchecked or i.isChecked() - if allChannelsUnchecked == False: - self.startButton.setEnabled(False) - else: - self.startButton.setEnabled(True) - - self.textDisplay.setText('>> %s@%s - %s - %s - %d'%(self.instToLog, self.addressToLog, self.chToLog, self.vTypeToLog, self.ts)) - - self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.addressToLog, self.ts) - - @pyqtSlot() - def startLog(self): - self.startButton.setEnabled(False) - self.stopButton.setEnabled(True) - self.address.setEnabled(False) - self.samplingtime.setReadOnly(True) - self.comboInst.setEnabled(False) - for i in self.checkBoxChannels: - i.setEnabled(False) - for i in self.chListVtypes: - i.setEnabled(False) - self.myLog.connect() - self.myLog.start() - - @pyqtSlot() - def stopLog(self): - self.startButton.setEnabled(True) - self.stopButton.setEnabled(False) - self.address.setEnabled(True) - self.samplingtime.setReadOnly(False) - self.comboInst.setEnabled(True) - for i in range(len(self.checkBoxChannels)): - if self.checkBoxChannels[i].isChecked(): - self.checkBoxChannels[i].setEnabled(True) - self.chListVtypes[i].setEnabled(True) - else: - self.checkBoxChannels[i].setEnabled(True) - self.chListVtypes[i].setEnabled(False) - self.myLog.stop() + def __init__(self): + self.setWindow() + self.setSignalsSlots() + self.runApp() + + def setWindow(self): + self.a = QtGui.QApplication(sys.argv) + self.w = QtGui.QMainWindow() + self.w.resize(640, 480) + self.w.setWindowTitle('datalogger-gui') + + self.wid = QtGui.QWidget() + self.w.setCentralWidget(self.wid) + self.layout = QtGui.QGridLayout() + self.wid.setLayout(self.layout) + + self.comboInst = QtGui.QComboBox() + self.layout.addWidget(self.comboInst, 0, 0) + + self.address = QtGui.QLineEdit() + self.address.setMinimumWidth(140) + self.address.setMaximumWidth(140) + self.layout.addWidget(self.address, 0, 1) + + self.samplingtime = QtGui.QDoubleSpinBox() + #self.samplingtime.setMinimumWidth(60) + #self.samplingtime.setMaximumWidth(60) + self.samplingtime.setMinimum(0.1) + self.samplingtime.setMaximum(1000) + self.samplingtime.setSingleStep(0.1) + self.samplingtime.setValue(1) + self.layout.addWidget(self.samplingtime, 0, 2) + + self.startButton = QtGui.QPushButton() + self.startButton.setText('Start log') + self.layout.addWidget(self.startButton, 99, 0) + self.startButton.setEnabled(False) + + self.stopButton = QtGui.QPushButton() + self.stopButton.setText('Stop log') + self.layout.addWidget(self.stopButton, 99, 1) + self.stopButton.setEnabled(False) + + self.textDisplay = QtGui.QLabel() + self.textDisplay.setText('>>') + self.layout.addWidget(self.textDisplay, 99, 2) + + self.setComboInst() + self.updateSignal() + + def setComboInst(self): + for name, obj in inspect.getmembers(instruments): + if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: + self.comboInst.addItem(name) + + def setSignalsSlots(self): + self.comboInst.currentIndexChanged.connect(self.updateSignal) + self.startButton.clicked.connect(self.startLog) + self.stopButton.clicked.connect(self.stopLog) + + def runApp(self): + self.w.show() + self.a.aboutToQuit.connect(self.closeEvent) + sys.exit(self.a.exec_()) + + def closeEvent(self): + try: + self.stopLog() + except: + pass + print('Done') + + @pyqtSlot() + def updateSignal(self): + for i in reversed(range(5, self.layout.count())): + self.layout.itemAt(i).widget().setParent(None) + + defaultAddress = '' + channelsAviables = [] + vtypesAviables = [] + + exec('channelsAviables = instruments.%s.ALL_CHANNELS'%self.comboInst.currentText()) + exec('vtypesAviables = instruments.%s.ALL_VAL_TYPE'%self.comboInst.currentText()) + exec('defaultAddress = instruments.%s.ADDRESS'%self.comboInst.currentText()) + + self.address.setText(defaultAddress) + + self.checkBoxChannels = [None]*len(channelsAviables) + self.chListVtypes = [None]*len(self.checkBoxChannels) + + for i in range(len(self.checkBoxChannels)): + self.checkBoxChannels[i] = QtGui.QCheckBox() + self.checkBoxChannels[i].setText(channelsAviables[i]) + self.checkBoxChannels[i].setChecked(False) + self.chListVtypes[i] = QtGui.QListWidget() + for vtype in vtypesAviables: + self.chListVtypes[i].addItem(vtype) + self.chListVtypes[i].setCurrentRow(0) + self.layout.addWidget(self.checkBoxChannels[i], i+3, 1) + self.layout.addWidget(self.chListVtypes[i], i+3, 2) + self.checkBoxChannels[i].stateChanged.connect(self.infoSignal) + self.chListVtypes[i].currentItemChanged.connect(self.infoSignal) + + self.address.textChanged.connect(self.infoSignal) + self.samplingtime.valueChanged.connect(self.infoSignal) + + self.infoSignal() + + @pyqtSlot() + def infoSignal(self): + self.instToLog = self.comboInst.currentText() + self.addressToLog = self.address.text() + self.chToLog = [] + self.vTypeToLog = [] + self.ts = self.samplingtime.value() + + for i in range(len(self.checkBoxChannels)): + if self.checkBoxChannels[i].isChecked(): + self.chListVtypes[i].setEnabled(True) + self.chToLog.append(str(self.checkBoxChannels[i].text())) + self.vTypeToLog.append(str(self.chListVtypes[i].currentItem().text())) + else: + self.chListVtypes[i].setEnabled(False) + + allChannelsUnchecked = False + for i in self.checkBoxChannels: + allChannelsUnchecked = allChannelsUnchecked or i.isChecked() + if allChannelsUnchecked == False: + self.startButton.setEnabled(False) + else: + self.startButton.setEnabled(True) + + self.textDisplay.setText('>> %s@%s - %s - %s - %d'%(self.instToLog, self.addressToLog, self.chToLog, self.vTypeToLog, self.ts)) + + self.myLog = acq_routine(self.instToLog, self.chToLog, self.vTypeToLog, self.addressToLog, self.ts) + + @pyqtSlot() + def startLog(self): + self.startButton.setEnabled(False) + self.stopButton.setEnabled(True) + self.address.setEnabled(False) + self.samplingtime.setReadOnly(True) + self.comboInst.setEnabled(False) + for i in self.checkBoxChannels: + i.setEnabled(False) + for i in self.chListVtypes: + i.setEnabled(False) + self.myLog.connect() + self.myLog.start() + + @pyqtSlot() + def stopLog(self): + self.startButton.setEnabled(True) + self.stopButton.setEnabled(False) + self.address.setEnabled(True) + self.samplingtime.setReadOnly(False) + self.comboInst.setEnabled(True) + for i in range(len(self.checkBoxChannels)): + if self.checkBoxChannels[i].isChecked(): + self.checkBoxChannels[i].setEnabled(True) + self.chListVtypes[i].setEnabled(True) + else: + self.checkBoxChannels[i].setEnabled(True) + self.chListVtypes[i].setEnabled(False) + self.myLog.stop() #============================================================================== #============================================================================== if __name__ == "__main__": - mainGui() + mainGui() diff --git a/instruments/AG34461A.py b/instruments/AG34461A.py index 727e7f8..a09c5e4 100644 --- a/instruments/AG34461A.py +++ b/instruments/AG34461A.py @@ -12,61 +12,61 @@ CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', #============================================================================== class AG34461A(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 5025 - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 5025 + self.channels = channels + self.vtypes = vtypes - def model(self): - #self.send("*IDN?") - #return self.read() - return "AG34461A" + def model(self): + #self.send("*IDN?") + #return self.read() + return "AG34461A" - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM, - socket.IPPROTO_TCP) - self.sock.settimeout(10.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - self.send("SYST:BEEP") - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + self.send("SYST:BEEP") + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - for ch in self.channels: - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) + def configure(self): + for ch in self.channels: + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) - def getValue(self): - mes = '' - for ch in self.channels: - self.send("READ?") - mesTemp = self.read() - mes = mes + '\t' + mesTemp - return mes + def getValue(self): + mes = '' + for ch in self.channels: + self.send("READ?") + mesTemp = self.read() + mes = mes + '\t' + mesTemp + return mes - def read(self): - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise - def disconnect(self): - self.send('*RST') - self.send("SYST:BEEP") - self.sock.close() + def disconnect(self): + self.send('*RST') + self.send("SYST:BEEP") + self.sock.close() - def send(self, command): - self.sock.send("%s\n"%command) + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/AG34461A_avg.py b/instruments/AG34461A_avg.py index 5c80b1a..38a155e 100644 --- a/instruments/AG34461A_avg.py +++ b/instruments/AG34461A_avg.py @@ -13,73 +13,73 @@ CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', #============================================================================== class AG34461A_avg(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 5025 - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 5025 + self.channels = channels + self.vtypes = vtypes - def model(self): - #self.send("*IDN?") - #return self.read() - return "AG34461A_avg" + def model(self): + #self.send("*IDN?") + #return self.read() + return "AG34461A_avg" - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.settimeout(10.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - self.send("SYST:BEEP") - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + self.send("SYST:BEEP") + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - self.send("*RST") - for ch in self.channels: - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) - #self.send("CONF:VOLT:DC 1") - self.send("VOLT:DC:NPLC 10") - self.send("SAMP:COUN 5") - self.send("TRIG:COUN 1") - self.send("TRIG:DEL 0") - self.send("SENS:ZERO:AUTO OFF") - self.send("TRIG:SOUR TIM") - self.send("TRIG:TIM 0.2") - self.send("INIT") + def configure(self): + self.send("*RST") + for ch in self.channels: + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) + #self.send("CONF:VOLT:DC 1") + self.send("VOLT:DC:NPLC 10") + self.send("SAMP:COUN 5") + self.send("TRIG:COUN 1") + self.send("TRIG:DEL 0") + self.send("SENS:ZERO:AUTO OFF") + self.send("TRIG:SOUR TIM") + self.send("TRIG:TIM 0.2") + self.send("INIT") - def getValue(self): - mes = '' - for ch in self.channels: - self.send("FETC?") - mesTemp = self.read() - #print(mesTemp) - mesTemp = map(float, mesTemp.split(',')) - mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp)) - self.send("INIT") - mes = mes + '\n' - return mes + def getValue(self): + mes = '' + for ch in self.channels: + self.send("FETC?") + mesTemp = self.read() + #print(mesTemp) + mesTemp = map(float, mesTemp.split(',')) + mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp)) + self.send("INIT") + mes = mes + '\n' + return mes - def read(self): - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise - def disconnect(self): - self.send('*RST') - self.send("SYST:BEEP") - self.sock.close() + def disconnect(self): + self.send('*RST') + self.send("SYST:BEEP") + self.sock.close() - def send(self, command): - self.sock.send("%s\n"%command) + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/AG34972A.py b/instruments/AG34972A.py index a5e9f0b..efce4b4 100644 --- a/instruments/AG34972A.py +++ b/instruments/AG34972A.py @@ -12,62 +12,62 @@ CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', #============================================================================== class AG34972A(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 5025 - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 5025 + self.channels = channels + self.vtypes = vtypes - def model(self): - #self.send("*IDN?") - #return self.read() - return "AG34972A" + def model(self): + #self.send("*IDN?") + #return self.read() + return "AG34972A" - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM, - socket.IPPROTO_TCP) - self.sock.settimeout(2.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - self.send("SYST:BEEP") - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(2.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + self.send("SYST:BEEP") + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - self.strCh = '' - for ch in self.channels: - self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) - self.strCh = self.strCh + ch + ',' - self.strCh = self.strCh[0:-1] - self.send("ROUT:SCAN (@%s)"%self.strCh) - self.send("TRIG:COUN 1") + def configure(self): + self.strCh = '' + for ch in self.channels: + self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) + self.strCh = self.strCh + ch + ',' + self.strCh = self.strCh[0:-1] + self.send("ROUT:SCAN (@%s)"%self.strCh) + self.send("TRIG:COUN 1") - def getValue(self): - self.send("INIT") - self.send("FETC?") - return self.read() + def getValue(self): + self.send("INIT") + self.send("FETC?") + return self.read() - def read(self): - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise - def disconnect(self): - self.send('*RST') - self.sock.close() + def disconnect(self): + self.send('*RST') + self.sock.close() - def send(self, command): - self.sock.send("%s\n"%command) + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/AG53230A.py b/instruments/AG53230A.py index 401857b..d3c686e 100644 --- a/instruments/AG53230A.py +++ b/instruments/AG53230A.py @@ -12,73 +12,73 @@ CONF_VAL_TYPE = ['CONF:FREQ'] #============================================================================== class AG53230A(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 5025 - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 5025 + self.channels = channels + self.vtypes = vtypes - def model(self): - #self.send("*IDN?") - #return self.read() - return "AG53230A" + def model(self): + #self.send("*IDN?") + #return self.read() + return "AG53230A" - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM, - socket.IPPROTO_TCP) - self.sock.settimeout(10.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - self.send("SYST:BEEP") - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + self.send("SYST:BEEP") + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - self.send('*RST') - self.send('DISP:DIG:MASK:AUTO OFF') - self.send('INP1:IMP 50') - self.send('INP1:COUP AC') - self.send('SYST:TIM INF') - self.send('SENS:ROSC:SOUR EXT') - self.send('SENS:ROSC:EXT:FREQ 10E6') - for ch in self.channels: - self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) - self.send('SAMP:COUN 1E6') - self.send('SENS:FREQ:MODE CONT') - self.send('SENS:FREQ:GATE:SOUR TIME') - self.send('1') - self.send('TRIG:SOUR IMM') + def configure(self): + self.send('*RST') + self.send('DISP:DIG:MASK:AUTO OFF') + self.send('INP1:IMP 50') + self.send('INP1:COUP AC') + self.send('SYST:TIM INF') + self.send('SENS:ROSC:SOUR EXT') + self.send('SENS:ROSC:EXT:FREQ 10E6') + for ch in self.channels: + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) + self.send('SAMP:COUN 1E6') + self.send('SENS:FREQ:MODE CONT') + self.send('SENS:FREQ:GATE:SOUR TIME') + self.send('1') + self.send('TRIG:SOUR IMM') - def getValue(self): - mes = '' - for ch in self.channels: - self.send("DATA:REM?") - mesTemp = self.read() - mes = mes + '\t' + mesTemp - return mes + def getValue(self): + mes = '' + for ch in self.channels: + self.send("DATA:REM?") + mesTemp = self.read() + mes = mes + '\t' + mesTemp + return mes - def read(self): - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise - def disconnect(self): - self.send('*RST') - self.send("SYST:BEEP") - self.sock.close() + def disconnect(self): + self.send('*RST') + self.send("SYST:BEEP") + self.sock.close() - def send(self, command): - self.sock.send("%s\n"%command) + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/HP53132A.py b/instruments/HP53132A.py index 54fe137..1031767 100644 --- a/instruments/HP53132A.py +++ b/instruments/HP53132A.py @@ -12,99 +12,99 @@ CONF_VAL_TYPE = ['CONF:FREQ'] #, 'CONF:PERIOD'] #============================================================================== class HP53132A(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 1234 - self.gpib_addr = 12 - self.channels = channels - self.vtypes = vtypes - - def model(self): - #self.send("*IDN?") - #return self.read() - return "HP53132A" - - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM, - socket.IPPROTO_TCP) - self.sock.settimeout(10.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - self.init_prologix() - print(' --> Ok') - print(self.model()) - self.configure() - - def configure(self): - #self.strCh = '' - #for ch in self.channels: - # self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) - # self.strCh = self.strCh + '(@%s),'%ch - #self.strCh = self.strCh[0:-1] - #self.send('FORMAT ASCII') - - #self.send('ROUT:SCAN (@%s)'%self.strCh) - #self.send('TRIG:COUN 1') - self.send('*RST') - #self.send('*CLS') - #self.send('*SRE 0') - #self.send('*ESE 0') - - self.send(':FUNC "FREQ 1"') - self.send(':FREQ:ARM:STAR:SOUR IMM') - self.send(':FREQ:ARM:STOP:SOUR TIM') - self.send(':FREQ:ARM:STOP:TIM 1') - self.send(':ROSC:SOUR EXT') - self.send(':ROSC:EXT:CHECK OFF') - #self.send(':STAT:PRES') - self.send(':INIT:CONT ON') - - def getValue(self): - self.send('FETC?') - #self.send('READ:FREQ?') - return self.read() - - def read(self): - self.send("++read eoi") - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise - - def disconnect(self): - self.send('*RST') - self.sock.close() - - def send(self, command): - self.sock.send("%s\n"%command) - - def init_prologix(self): - try: - self.sock.send("++mode 1\n") # Set mode as CONTROLLER - 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 - 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 - self.sock.send("++auto 0\n") # Turn off read-after-write to avoid - # "Query Unterminated" errors - - except self.socket.timeout: - print "Socket timeout" - raise - except self.socket.error as er: - print "Socket error: " + str(er) - raise - except Exception as er: - print "Unexpected error: " + str(er) - raise + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 1234 + self.gpib_addr = 12 + self.channels = channels + self.vtypes = vtypes + + def model(self): + #self.send("*IDN?") + #return self.read() + return "HP53132A" + + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + self.init_prologix() + print(' --> Ok') + print(self.model()) + self.configure() + + def configure(self): + #self.strCh = '' + #for ch in self.channels: + # self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) + # self.strCh = self.strCh + '(@%s),'%ch + #self.strCh = self.strCh[0:-1] + #self.send('FORMAT ASCII') + + #self.send('ROUT:SCAN (@%s)'%self.strCh) + #self.send('TRIG:COUN 1') + self.send('*RST') + #self.send('*CLS') + #self.send('*SRE 0') + #self.send('*ESE 0') + + self.send(':FUNC "FREQ 1"') + self.send(':FREQ:ARM:STAR:SOUR IMM') + self.send(':FREQ:ARM:STOP:SOUR TIM') + self.send(':FREQ:ARM:STOP:TIM 1') + self.send(':ROSC:SOUR EXT') + self.send(':ROSC:EXT:CHECK OFF') + #self.send(':STAT:PRES') + self.send(':INIT:CONT ON') + + def getValue(self): + self.send('FETC?') + #self.send('READ:FREQ?') + return self.read() + + def read(self): + self.send("++read eoi") + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise + + def disconnect(self): + self.send('*RST') + self.sock.close() + + def send(self, command): + self.sock.send("%s\n"%command) + + def init_prologix(self): + try: + self.sock.send("++mode 1\n") # Set mode as CONTROLLER + 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 + 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 + self.sock.send("++auto 0\n") # Turn off read-after-write to avoid + # "Query Unterminated" errors + + except self.socket.timeout: + print "Socket timeout" + raise + except self.socket.error as er: + print "Socket error: " + str(er) + raise + except Exception as er: + print "Unexpected error: " + str(er) + raise diff --git a/instruments/LS350.py b/instruments/LS350.py index 4e4f8c1..9a71437 100644 --- a/instruments/LS350.py +++ b/instruments/LS350.py @@ -12,59 +12,59 @@ CONF_VAL_TYPE = ['krdg?', 'srdg?'] #============================================================================== class LS350(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.port = 7777 - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.port = 7777 + self.channels = channels + self.vtypes = vtypes - def model(self): - #self.send("*IDN?") - #return self.read() - return "LS350" + def model(self): + #self.send("*IDN?") + #return self.read() + return "LS350" - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - self.sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM, - socket.IPPROTO_TCP) - self.sock.settimeout(10.0) # Don't hang around forever - self.sock.connect((self.address, self.port)) - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.address, self.port)) + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - self.strCh = '' - 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) - self.strCh = self.strCh[0:-1] - print(self.strCh) + def configure(self): + self.strCh = '' + 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) + self.strCh = self.strCh[0:-1] + print(self.strCh) - def getValue(self): - self.send(self.strCh) - return self.read() + def getValue(self): + self.send(self.strCh) + return self.read() - def read(self): - self.send("++read eoi") - ans = '' - nb_data_list = [] - nb_data = '' - try: - while ans != '\n': - ans = self.sock.recv(1) - nb_data_list.append(ans) # Return the number of data - list_size = len(nb_data_list) - for j in range (0, list_size): - nb_data = nb_data+nb_data_list[j] - return nb_data - except socket.timeout: - print "Socket timeout error when reading." - raise + def read(self): + self.send("++read eoi") + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise - def disconnect(self): - self.send('MODE0') - self.sock.close() + def disconnect(self): + self.send('MODE0') + self.sock.close() - def send(self, command): - self.sock.send("%s\n"%command) + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/PM100D.py b/instruments/PM100D.py index d30dc71..de1eab5 100644 --- a/instruments/PM100D.py +++ b/instruments/PM100D.py @@ -12,35 +12,35 @@ CONF_VAL_TYPE = ['PWR'] #============================================================================== class PM100D(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.channels = channels - self.vtypes = vtypes - - def model(self): - #self.send("*IDN?") - #return self.read() - return "PM100D" - - def connect(self): - print('Connecting to device @%s...' %(self.address)) - self.FILE = os.open(self.address, os.O_RDWR) - print(' --> Ok') - print(self.model()) - self.configure() - - def configure(self): - pass - - def getValue(self): - self.send("READ?") - return self.read() - - def read(self): - return os.read(self.FILE, 300) - - def disconnect(self): - self.send('*RST') - - def send(self, command): - os.write(self.FILE, command) + def __init__(self, channels, vtypes, address): + self.address = address + self.channels = channels + self.vtypes = vtypes + + def model(self): + #self.send("*IDN?") + #return self.read() + return "PM100D" + + def connect(self): + print('Connecting to device @%s...' %(self.address)) + self.FILE = os.open(self.address, os.O_RDWR) + print(' --> Ok') + print(self.model()) + self.configure() + + def configure(self): + pass + + def getValue(self): + self.send("READ?") + return self.read() + + def read(self): + return os.read(self.FILE, 300) + + def disconnect(self): + self.send('*RST') + + def send(self, command): + os.write(self.FILE, command) diff --git a/instruments/Sym5125A.py b/instruments/Sym5125A.py index 62bc349..e934fdd 100644 --- a/instruments/Sym5125A.py +++ b/instruments/Sym5125A.py @@ -12,37 +12,37 @@ CONF_VAL_TYPE = ['phase'] #============================================================================== class Sym5125A(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.channels = channels - self.vtypes = vtypes - - def model(self): - #self.send("*IDN?") - #return self.read() - return "Sym5125A" - - def connect(self): - print('Connecting to device @%s...' %(self.address)) - self.tn = telnetlib.Telnet(self.address, '1298') - #time.sleep(1) - print(' --> Ok') - print(self.model()) - self.configure() - - def configure(self): - pass - - def getValue(self): - for i in range(1000): - mes = self.tn.read_until('\n').replace('\r\n','') - return mes + '\n' - - def read(self): - pass - - def disconnect(self): - self.tn.close() - - def send(self, command): - pass + def __init__(self, channels, vtypes, address): + self.address = address + self.channels = channels + self.vtypes = vtypes + + def model(self): + #self.send("*IDN?") + #return self.read() + return "Sym5125A" + + def connect(self): + print('Connecting to device @%s...' %(self.address)) + self.tn = telnetlib.Telnet(self.address, '1298') + #time.sleep(1) + print(' --> Ok') + print(self.model()) + self.configure() + + def configure(self): + pass + + def getValue(self): + for i in range(1000): + mes = self.tn.read_until('\n').replace('\r\n','') + return mes + '\n' + + def read(self): + pass + + def disconnect(self): + self.tn.close() + + def send(self, command): + pass diff --git a/instruments/T7Pro.py b/instruments/T7Pro.py index 9f04174..71b5bb6 100644 --- a/instruments/T7Pro.py +++ b/instruments/T7Pro.py @@ -14,80 +14,80 @@ VISHAY_CHANNELS = [1000., 1000., 1079., 10000.] #============================================================================== class T7Pro(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.channels = channels + self.vtypes = vtypes - def model(self): - return 'T7Pro' + def model(self): + return 'T7Pro' - def connect(self): - print('Connecting to device @%s...' %(self.address)) - self.handle = ljm.openS("T7", "ETHERNET", self.address) - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s...' %(self.address)) + self.handle = ljm.openS("T7", "ETHERNET", self.address) + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", - "AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", - "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", - "AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", - "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", - "AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", - "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", - "AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX", - #"AIN8_NEGATIVE_CH", "AIN8_RANGE", "AIN8_RESOLUTION_INDEX", - #"AIN9_NEGATIVE_CH", "AIN9_RANGE", "AIN9_RESOLUTION_INDEX", - "AIN10_NEGATIVE_CH", "AIN10_RANGE", "AIN10_RESOLUTION_INDEX", - "AIN11_NEGATIVE_CH", "AIN11_RANGE", "AIN11_RESOLUTION_INDEX", - "AIN12_NEGATIVE_CH", "AIN12_RANGE", "AIN12_RESOLUTION_INDEX", - "AIN13_NEGATIVE_CH", "AIN13_RANGE", "AIN13_RESOLUTION_INDEX" - ] - l_names = len(names) - aValues = [1, 1, 12,#0 - 199, 1, 12,#1 - 3, 1, 12,#2 - 199, 1, 12,#3 - 5, 1, 12,#4 - 199, 1, 12,#5 - 7, 1, 12,#6 - 199, 1, 12,#7 - #199, 1, 12,#8 - #199, 1, 12,#9 - 199, 1, 12,#10 - 199, 1, 12,#11 - 199, 1, 12,#12 - 199, 1, 12#13 - ] + def configure(self): + names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", + "AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", + "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", + "AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", + "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", + "AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", + "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", + "AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX", + #"AIN8_NEGATIVE_CH", "AIN8_RANGE", "AIN8_RESOLUTION_INDEX", + #"AIN9_NEGATIVE_CH", "AIN9_RANGE", "AIN9_RESOLUTION_INDEX", + "AIN10_NEGATIVE_CH", "AIN10_RANGE", "AIN10_RESOLUTION_INDEX", + "AIN11_NEGATIVE_CH", "AIN11_RANGE", "AIN11_RESOLUTION_INDEX", + "AIN12_NEGATIVE_CH", "AIN12_RANGE", "AIN12_RESOLUTION_INDEX", + "AIN13_NEGATIVE_CH", "AIN13_RANGE", "AIN13_RESOLUTION_INDEX" + ] + l_names = len(names) + aValues = [1, 1, 12,#0 + 199, 1, 12,#1 + 3, 1, 12,#2 + 199, 1, 12,#3 + 5, 1, 12,#4 + 199, 1, 12,#5 + 7, 1, 12,#6 + 199, 1, 12,#7 + #199, 1, 12,#8 + #199, 1, 12,#9 + 199, 1, 12,#10 + 199, 1, 12,#11 + 199, 1, 12,#12 + 199, 1, 12#13 + ] - ljm.eWriteNames(self.handle, l_names, names, aValues) + ljm.eWriteNames(self.handle, l_names, names, aValues) - def getValue(self): - strMes = '' - for ch in self.channels: - if self.vtypes[self.channels.index(ch)] == 'RES': - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) - strMes = strMes + str(VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1]) + ';' - elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 K': - 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) + ';' - elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 C': - 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) + ';' - elif self.vtypes[self.channels.index(ch)] == 'TEMP AIR K': - raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) - strMes = strMes + str(raw[0]) + ';' + def getValue(self): + strMes = '' + for ch in self.channels: + if self.vtypes[self.channels.index(ch)] == 'RES': + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) + strMes = strMes + str(VISHAY_CHANNELS[ALL_CHANNELS.index(ch)]*raw[0]/raw[1]) + ';' + elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 K': + 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) + ';' + elif self.vtypes[self.channels.index(ch)] == 'TEMP PT100 C': + 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) + ';' + elif self.vtypes[self.channels.index(ch)] == 'TEMP AIR K': + raw = self.read(CONF_CHANNELS[ALL_CHANNELS.index(ch)]) + strMes = strMes + str(raw[0]) + ';' - strMes = strMes[0:-1] + '\n' - return(strMes) + strMes = strMes[0:-1] + '\n' + return(strMes) - def read(self, names): - return ljm.eReadNames(self.handle, len(names), names) + def read(self, names): + return ljm.eReadNames(self.handle, len(names), names) - def disconnect(self): - ljm.close(self.handle) + def disconnect(self): + ljm.close(self.handle) - def send(self, command): - pass + def send(self, command): + pass diff --git a/instruments/TPG261.py b/instruments/TPG261.py index 75368b8..2d38363 100644 --- a/instruments/TPG261.py +++ b/instruments/TPG261.py @@ -10,36 +10,36 @@ ADDRESS = "/dev/ttyS0" #============================================================================== class TPG261(abstract_instrument): - def __init__(self, channels, vtypes, address): - self.address = address - self.channels = channels - self.vtypes = vtypes + def __init__(self, channels, vtypes, address): + self.address = address + self.channels = channels + self.vtypes = vtypes - def model(self): - return "PfeifferTPG261" + def model(self): + return "PfeifferTPG261" - def connect(self): - print('Connecting to device @%s...' %(self.address)) - self.TPG = MaxiGauge(self.address) - print(' --> Ok') - print(self.model()) - self.configure() + def connect(self): + print('Connecting to device @%s...' %(self.address)) + self.TPG = MaxiGauge(self.address) + print(' --> Ok') + print(self.model()) + self.configure() - def configure(self): - pass + def configure(self): + pass - def getValue(self): - self.read() - return "%s\n"%self.ps[0].pressure + def getValue(self): + self.read() + return "%s\n"%self.ps[0].pressure - def read(self): - self.ps = self.TPG.pressures() + def read(self): + self.ps = self.TPG.pressures() - def disconnect(self): - self.TPG.disconnect() + def disconnect(self): + self.TPG.disconnect() - def send(self, command): - pass + def send(self, command): + pass @@ -47,135 +47,135 @@ class TPG261(abstract_instrument): # from Philipp Klaus, philipp.l.klaus AT web.de PfeifferVacuum.py class MaxiGauge (object): - def __init__(self, serialPort, baud=9600, debug=False): - self.debug=debug - try: - self.connection = serial.Serial(serialPort, baudrate=baud, timeout=0.2) - except serial.serialutil.SerialException as se: - raise MaxiGaugeError(se) - #self.send(C['ETX']) ### We might reset the connection first, but it doesn't really matter: - - def checkDevice(self): - 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()) ) - return message - - def pressedKeys(self): - keys = int(self.send('TKB',1)[0]) - pressedKeys = [] - for i in [4,3,2,1,0]: # It's got 5 keys - if keys/2**i == 1: - pressedKeys.append(i+1) - keys = keys%2**i - pressedKeys.reverse() - return pressedKeys - - def displayContrast(self,newContrast=-1): - if newContrast == -1: return int(self.send('DCC',1)[0]) - else: return int(self.send('DCC,%d' % (newContrast,) ,1)[0]) - - def pressures(self): - return [self.pressure(i+1) for i in range(1)] - - def pressure(self, sensor): - 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 (see p.88) - try: - r = reading[0].split(',') - status = int(r[0]) - pressure = float(r[-1]) - except: - raise MaxiGaugeError("Problem interpreting the returned line:\n%s" % reading) - return PressureReading(sensor, status, pressure) - - def debugMessage(self, message): - if self.debug: print(repr(message)) - - def send(self, mnemonic, numEnquiries = 0): - self.connection.flushInput() - self.write(mnemonic+LINE_TERMINATION) - #if mnemonic != C['ETX']: self.read() - #self.read() - self.getACQorNAK() - response = [] - for i in range(numEnquiries): - self.enquire() - response.append(self.read()) - return response - - def write(self,what): - self.debugMessage(what) - self.connection.write(what) - - def enquire(self): - self.write(C['ENQ']) - - def read(self): - data = "" - while True: - x = self.connection.read() - self.debugMessage(x) - data += x - if len(data)>1 and data[-2:]==LINE_TERMINATION: - break - return data[:-len(LINE_TERMINATION)] - - def getACQorNAK(self): - returncode = self.connection.readline() - 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. - #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.') - if len(returncode)>2 and returncode[-3] == C['NAK']: - self.enquire() - returnedError = self.read() - error = str(returnedError).split(',' , 1) - print repr(error) - errmsg = { 'System Error': ERR_CODES[0][int(error[0])] , 'Gauge Error': ERR_CODES[1][int(error[1])] } - raise MaxiGaugeNAK(errmsg) - #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.') - # if no exception raised so far, the interface is just fine: - return returncode[:-(len(LINE_TERMINATION)+1)] - - def disconnect(self): - #self.send(C['ETX']) - if hasattr(self, 'connection') and self.connection: self.connection.close() - - def __del__(self): - self.disconnect() + def __init__(self, serialPort, baud=9600, debug=False): + self.debug=debug + try: + self.connection = serial.Serial(serialPort, baudrate=baud, timeout=0.2) + except serial.serialutil.SerialException as se: + raise MaxiGaugeError(se) + #self.send(C['ETX']) ### We might reset the connection first, but it doesn't really matter: + + def checkDevice(self): + 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()) ) + return message + + def pressedKeys(self): + keys = int(self.send('TKB',1)[0]) + pressedKeys = [] + for i in [4,3,2,1,0]: # It's got 5 keys + if keys/2**i == 1: + pressedKeys.append(i+1) + keys = keys%2**i + pressedKeys.reverse() + return pressedKeys + + def displayContrast(self,newContrast=-1): + if newContrast == -1: return int(self.send('DCC',1)[0]) + else: return int(self.send('DCC,%d' % (newContrast,) ,1)[0]) + + def pressures(self): + return [self.pressure(i+1) for i in range(1)] + + def pressure(self, sensor): + 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 (see p.88) + try: + r = reading[0].split(',') + status = int(r[0]) + pressure = float(r[-1]) + except: + raise MaxiGaugeError("Problem interpreting the returned line:\n%s" % reading) + return PressureReading(sensor, status, pressure) + + def debugMessage(self, message): + if self.debug: print(repr(message)) + + def send(self, mnemonic, numEnquiries = 0): + self.connection.flushInput() + self.write(mnemonic+LINE_TERMINATION) + #if mnemonic != C['ETX']: self.read() + #self.read() + self.getACQorNAK() + response = [] + for i in range(numEnquiries): + self.enquire() + response.append(self.read()) + return response + + def write(self,what): + self.debugMessage(what) + self.connection.write(what) + + def enquire(self): + self.write(C['ENQ']) + + def read(self): + data = "" + while True: + x = self.connection.read() + self.debugMessage(x) + data += x + if len(data)>1 and data[-2:]==LINE_TERMINATION: + break + return data[:-len(LINE_TERMINATION)] + + def getACQorNAK(self): + returncode = self.connection.readline() + 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. + #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.') + if len(returncode)>2 and returncode[-3] == C['NAK']: + self.enquire() + returnedError = self.read() + error = str(returnedError).split(',' , 1) + print repr(error) + errmsg = { 'System Error': ERR_CODES[0][int(error[0])] , 'Gauge Error': ERR_CODES[1][int(error[1])] } + raise MaxiGaugeNAK(errmsg) + #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.') + # if no exception raised so far, the interface is just fine: + return returncode[:-(len(LINE_TERMINATION)+1)] + + def disconnect(self): + #self.send(C['ETX']) + if hasattr(self, 'connection') and self.connection: self.connection.close() + + def __del__(self): + self.disconnect() class PressureReading(object): - def __init__(self, id, status, pressure): - if int(id) not in range(1,7): raise MaxiGaugeError('Pressure Gauge ID must be between 1-6') - 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()) - self.status = int(status) - self.pressure = float(pressure) + def __init__(self, id, status, pressure): + if int(id) not in range(1,7): raise MaxiGaugeError('Pressure Gauge ID must be between 1-6') + 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()) + self.status = int(status) + self.pressure = float(pressure) - def statusMsg(self): - return PRESSURE_READING_STATUS[self.status] + def statusMsg(self): + return PRESSURE_READING_STATUS[self.status] - def __repr__(self): - return "Gauge #%d: Status %d (%s), Pressure: %f mbar\n" % (self.id, self.status, self.statusMsg(), self.pressure) + def __repr__(self): + return "Gauge #%d: Status %d (%s), Pressure: %f mbar\n" % (self.id, self.status, self.statusMsg(), self.pressure) ### ------ now we define the exceptions that could occur ------ class MaxiGaugeError(Exception): - pass + pass class MaxiGaugeNAK(MaxiGaugeError): - pass + pass ### ------- Control Symbols as defined on p. 81 of the english -### manual for the Pfeiffer Vacuum TPG256A ----------- +### manual for the Pfeiffer Vacuum TPG256A ----------- C = { 'ETX': "\x03", # End of Text (Ctrl-C) Reset the interface - 'CR': "\x0D", # Carriage Return Go to the beginning of line - 'LF': "\x0A", # Line Feed Advance by one line - 'ENQ': "\x05", # Enquiry Request for data transmission - 'ACQ': "\x06", # Acknowledge Positive report signal + 'CR': "\x0D", # Carriage Return Go to the beginning of line + 'LF': "\x0A", # Line Feed Advance by one line + 'ENQ': "\x05", # Enquiry Request for data transmission + 'ACQ': "\x06", # Acknowledge Positive report signal 'NAK': "\x15", # Negative Acknowledge Negative report signal 'ESC': "\x1b", # Escape } @@ -184,74 +184,74 @@ LINE_TERMINATION=C['CR']+C['LF'] # CR, LF and CRLF are all possible (p.82) ### Mnemonics as defined on p. 85 M = [ - 'BAU', # Baud rate Baud rate 95 - 'CAx', # Calibration factor Sensor x Calibration factor sensor x (1 ... 6) 92 - 'CID', # Measurement point names Measurement point names 88 - 'DCB', # Display control Bargraph Bargraph 89 - 'DCC', # Display control Contrast Display control contrast 90 - 'DCD', # Display control Digits Display digits 88 - 'DCS', # Display control Screensave Display control screensave 90 - 'DGS', # Degas Degas 93 - 'ERR', # Error Status Error status 97 - 'FIL', # Filter time constant Filter time constant 92 - 'FSR', # Full scale range of linear sensors Full scale range of linear sensors 93 - 'LOC', # Parameter setup lock Parameter setup lock 91 - 'NAD', # Node (device) address for RS485 Node (device) address for RS485 96 - 'OFC', # Offset correction Offset correction 93 - 'OFC', # Offset correction Offset correction 93 - 'PNR', # Program number Program number 98 - 'PRx', # Status, Pressure sensor x (1 ... 6) Status, Pressure sensor x (1 ... 6) 88 - 'PUC', # Underrange Ctrl Underrange control 91 - 'RSX', # Interface Interface 94 - 'SAV', # Save default Save default 94 - 'SCx', # Sensor control Sensor control 87 - 'SEN', # Sensor on/off Sensor on/off 86 - '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 - '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 - 'TDI', # Display test Display test 98 - 'TEE', # EEPROM test EEPROM test 100 - 'TEP', # EPROM test EPROM test 99 - 'TID', # Sensor identification Sensor identification 101 - 'TKB', # Keyboard test Keyboard test 99 - 'TRA', # RAM test RAM test 99 - 'UNI', # Unit of measurement (Display) Unit of measurement (pressure) 89 - 'WDT', # Watchdog and System Error Control Watchdog and system error control 101 + 'BAU', # Baud rate Baud rate 95 + 'CAx', # Calibration factor Sensor x Calibration factor sensor x (1 ... 6) 92 + 'CID', # Measurement point names Measurement point names 88 + 'DCB', # Display control Bargraph Bargraph 89 + 'DCC', # Display control Contrast Display control contrast 90 + 'DCD', # Display control Digits Display digits 88 + 'DCS', # Display control Screensave Display control screensave 90 + 'DGS', # Degas Degas 93 + 'ERR', # Error Status Error status 97 + 'FIL', # Filter time constant Filter time constant 92 + 'FSR', # Full scale range of linear sensors Full scale range of linear sensors 93 + 'LOC', # Parameter setup lock Parameter setup lock 91 + 'NAD', # Node (device) address for RS485 Node (device) address for RS485 96 + 'OFC', # Offset correction Offset correction 93 + 'OFC', # Offset correction Offset correction 93 + 'PNR', # Program number Program number 98 + 'PRx', # Status, Pressure sensor x (1 ... 6) Status, Pressure sensor x (1 ... 6) 88 + 'PUC', # Underrange Ctrl Underrange control 91 + 'RSX', # Interface Interface 94 + 'SAV', # Save default Save default 94 + 'SCx', # Sensor control Sensor control 87 + 'SEN', # Sensor on/off Sensor on/off 86 + '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 + '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 + 'TDI', # Display test Display test 98 + 'TEE', # EEPROM test EEPROM test 100 + 'TEP', # EPROM test EPROM test 99 + 'TID', # Sensor identification Sensor identification 101 + 'TKB', # Keyboard test Keyboard test 99 + 'TRA', # RAM test RAM test 99 + 'UNI', # Unit of measurement (Display) Unit of measurement (pressure) 89 + 'WDT', # Watchdog and System Error Control Watchdog and system error control 101 ] ### Error codes as defined on p. 97 ERR_CODES = [ { - 0: 'No error', - 1: 'Watchdog has responded', - 2: 'Task fail error', - 4: 'IDCX idle error', - 8: 'Stack overflow error', - 16: 'EPROM error', - 32: 'RAM error', - 64: 'EEPROM error', - 128: 'Key error', - 4096: 'Syntax error', - 8192: 'Inadmissible parameter', - 16384: 'No hardware', - 32768: 'Fatal error' + 0: 'No error', + 1: 'Watchdog has responded', + 2: 'Task fail error', + 4: 'IDCX idle error', + 8: 'Stack overflow error', + 16: 'EPROM error', + 32: 'RAM error', + 64: 'EEPROM error', + 128: 'Key error', + 4096: 'Syntax error', + 8192: 'Inadmissible parameter', + 16384: 'No hardware', + 32768: 'Fatal error' } , { - 0: 'No error', - 1: 'Sensor 1: Measurement error', - 2: 'Sensor 2: Measurement error', - 4: 'Sensor 3: Measurement error', - 8: 'Sensor 4: Measurement error', - 16: 'Sensor 5: Measurement error', - 32: 'Sensor 6: Measurement error', - 512: 'Sensor 1: Identification error', - 1024: 'Sensor 2: Identification error', - 2048: 'Sensor 3: Identification error', - 4096: 'Sensor 4: Identification error', - 8192: 'Sensor 5: Identification error', - 16384: 'Sensor 6: Identification error', + 0: 'No error', + 1: 'Sensor 1: Measurement error', + 2: 'Sensor 2: Measurement error', + 4: 'Sensor 3: Measurement error', + 8: 'Sensor 4: Measurement error', + 16: 'Sensor 5: Measurement error', + 32: 'Sensor 6: Measurement error', + 512: 'Sensor 1: Identification error', + 1024: 'Sensor 2: Identification error', + 2048: 'Sensor 3: Identification error', + 4096: 'Sensor 4: Identification error', + 8192: 'Sensor 5: Identification error', + 16384: 'Sensor 6: Identification error', } ] diff --git a/instruments/__init__.py b/instruments/__init__.py index fbbc134..1f78f0b 100644 --- a/instruments/__init__.py +++ b/instruments/__init__.py @@ -2,8 +2,8 @@ from os import listdir from os.path import dirname for module in listdir(dirname(__file__)): - if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': - continue - __import__(module[:-3], locals(), globals()) + if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': + continue + __import__(module[:-3], locals(), globals()) del module, listdir, dirname \ No newline at end of file diff --git a/instruments/abstract_instrument.py b/instruments/abstract_instrument.py index 47bafb6..ce74188 100644 --- a/instruments/abstract_instrument.py +++ b/instruments/abstract_instrument.py @@ -1,44 +1,44 @@ import abc class abstract_instrument(object): - __metaclass__ = abc.ABCMeta - - @abc.abstractmethod - def __init__(self, address, vtype, channel): - """Build the class""" - return - - @abc.abstractmethod - def model(self): - """return the instrument model""" - return - - @abc.abstractmethod - def connect(self): - """Create a connection with the instrument""" - return - - @abc.abstractmethod - def disconnect(self): - """Disconnect the instrument""" - return - - @abc.abstractmethod - def configure(self): - """Configure the instrument""" - return - - @abc.abstractmethod - def read(self): - """read the buffer""" - return - - @abc.abstractmethod - def send(self): - """send a command""" - return - - @abc.abstractmethod - def getValue(self): - """return the value of measurment""" - return + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def __init__(self, address, vtype, channel): + """Build the class""" + return + + @abc.abstractmethod + def model(self): + """return the instrument model""" + return + + @abc.abstractmethod + def connect(self): + """Create a connection with the instrument""" + return + + @abc.abstractmethod + def disconnect(self): + """Disconnect the instrument""" + return + + @abc.abstractmethod + def configure(self): + """Configure the instrument""" + return + + @abc.abstractmethod + def read(self): + """read the buffer""" + return + + @abc.abstractmethod + def send(self): + """send a command""" + return + + @abc.abstractmethod + def getValue(self): + """return the value of measurment""" + return diff --git a/instruments/testDevice.py b/instruments/testDevice.py index 3e4cbc2..42af2db 100644 --- a/instruments/testDevice.py +++ b/instruments/testDevice.py @@ -10,40 +10,40 @@ ADDRESS = "123.456.789.123" #============================================================================== class testDevice(abstract_instrument): - def __init__(self, channels, vtype, address): - self.address = address - self.port = 9999 - self.channels = channels - self.vtype = vtype - - def model(self): - return 'test_device' - - def connect(self): - print('Connecting to device @%s:%s...' %(self.address, self.port)) - time.sleep(1) - print(' --> Ok') - self.configure() - - print(self.model()) - - def getValue(self): - mes = "" - for ch in self.channels: - mes = mes + str(numpy.random.rand()) + '\t' - return mes + '\n' - - def read(self): - print('reading') - return 1 - - def disconnect(self): - print('disconnect') - - def send(self, command): - print('send %s'%command) - - def configure(self): - print(self.channels) - print(self.vtype) - print('configured') + def __init__(self, channels, vtype, address): + self.address = address + self.port = 9999 + self.channels = channels + self.vtype = vtype + + def model(self): + return 'test_device' + + def connect(self): + print('Connecting to device @%s:%s...' %(self.address, self.port)) + time.sleep(1) + print(' --> Ok') + self.configure() + + print(self.model()) + + def getValue(self): + mes = "" + for ch in self.channels: + mes = mes + str(numpy.random.rand()) + '\t' + return mes + '\n' + + def read(self): + print('reading') + return 1 + + def disconnect(self): + print('disconnect') + + def send(self, command): + print('send %s'%command) + + def configure(self): + print(self.channels) + print(self.vtype) + print('configured')