def setCode(self, channel, code): if channel < 1 or channel > 4: raise DeviceException('channel should be in [0, 3].') if code < 0 or code > 0xFFFFF: raise DeviceException('code should be in [0x0, 0xFFFFF].') tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect((self.ip, 5000)) command = 'DA={};RW=1;ADDR=0x01;VAL={};'.format(channel, hex(code)) tcpCliSock.send(bytearray(command, 'UTF-8')) tcpCliSock.close()
def setAcquireLength(self, length='AUTO', awaitOperator=True): if length == 'AUTO': self.scpi.ACQuire.POINts.AUTomatic.write('ON') else: raise DeviceException('Invalid length:{}'.format(length)) if awaitOperator: self.awaitOperation()
def setOutputStatuses(self, outputStatuses): if len(outputStatuses) != self.getChannelNumber(): raise DeviceException("statuses should have length of {}".format(self.getChannelNumber())) outputCodeString = ['{}'.format(1 if v else 0) for v in outputStatuses] outputCode = ', '.join(outputCodeString) self.scpi.APP.OUT.write(outputCode) self.outputStatuses = [True if v else False for v in outputStatuses]
def setDataFormat(self, format, awaitOperator=True): if format == 'REAL': self.scpi.FORMat.write('REAL') self.scpi.FORMat.BORDer.write('LSBF') else: raise DeviceException('Invalid Format:{}'.format(format)) if awaitOperator: self.awaitOperation()
def setCurrents(self, currents): if len(currents) is not self.channelCount: raise DeviceException('Length of voltages do not match the channel number.') currents = [self.__trimCurrent(c, currents[c]) for c in range(0, self.channelCount)] outputCodeString = ['{}'.format(v) for v in currents] outputCode = ', '.join(outputCodeString) self.scpi.APP.CURR.write(outputCode) self.currentLimitSetpoints = currents
def setVoltages(self, voltages): if len(voltages) is not self.channelCount: raise DeviceException('Length of voltages do not match the channel number.') voltages = [self.__trimVoltage(c, voltages[c]) for c in range(0, self.channelCount)] outputCodeString = ['{}'.format(v) for v in voltages] outputCode = ', '.join(outputCodeString) self.scpi.APP.VOLT.write(outputCode) self.voltageSetpoints = voltages
def setTriggerMode(self, triggerMode, awaitOperator=True): cmd = self.scpi.TRIGger.A.MODE if triggerMode == 'AUTO': cmd.write('AUTO') elif triggerMode == 'NORMAL': cmd.write('NORM') else: raise DeviceException('Invalid triggerMode:{}'.format(triggerMode)) if awaitOperator: self.awaitOperation()
def setCoupling(self, channel, coupling, awaitOperator=True): cmd = self.scpi.__getattr__('CHAN{}'.format(channel)).COUPling if coupling == 'DC': cmd.write('DCLimit') elif coupling == 'AC': cmd.write('ACLimit') elif coupling == 'GND': cmd.write('GND') else: raise DeviceException('Invalid coupling:{}'.format(coupling)) if awaitOperator: self.awaitOperation()
def setMeasureQuantity(self, mq, range=0, autoRange=True, aperture=0.001): if mq is MeasureQuantity.VoltageDC: self.scpi.CONF.VOLT.DC.write('AUTO' if autoRange else range) self.scpi.VOLT.APER.write(aperture) elif mq is MeasureQuantity.CurrentDC: self.scpi.CONF.CURR.DC.write('AUTO' if autoRange else range) self.scpi.CURR.APER.write(aperture) elif mq is MeasureQuantity.Resistance: self.scpi.CONF.RES.write('AUTO' if autoRange else range) self.scpi.RES.APER.write(aperture) else: raise DeviceException( 'MeasureQuantity {} can not be recognized.'.format(mq))
def setTriggerCriteria(self, *args, awaitOperator=True): triggerType = args[0] if triggerType == 'RAISE': self.scpi.TRIGger.A.TYPE.write('EDGE') self.scpi.TRIGger.A.EDGE.SLOPe.write('POS') self.scpi.TRIGger.A.LEVel.write(args[1]) elif triggerType == 'FALL': self.scpi.TRIGger.A.TYPE.write('EDGE') self.scpi.TRIGger.A.EDGE.SLOPe.write('NEG') self.scpi.TRIGger.A.LEVel.write(args[1]) else: raise DeviceException('Invalid triggerType:{}'.format(args)) if awaitOperator: self.awaitOperation()
def readCode(self, channel): if channel < 1 or channel > 4: raise DeviceException('channel should be in [1, 4].') tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect((self.ip, 5000)) command = 'DA={};RW=0;ADDR=0x01;VAL=0xFFFFF;'.format(channel) tcpCliSock.send(bytearray(command, 'UTF-8')) buffer = '' while True: c = tcpCliSock.recv(1) if c == b'\n': break buffer += chr(c[0]) tcpCliSock.close() code = int(buffer, 16) return code
def setTriggerSource(self, triggerSource, awaitOperator=True): cmd = self.scpi.TRIGger.A.SOURce if triggerSource == 'MANUAL': cmd.write('EXTernanalog') return if isinstance( triggerSource, int ) and triggerSource >= 1 and triggerSource <= self.channelCount: cmd.write('CH{}'.format(triggerSource)) return if triggerSource.startswith('CH'): try: ch = int(triggerSource[2:]) if ch >= 1 and ch <= self.channelCount: cmd.write('CH{}'.format(ch)) return except: pass raise DeviceException( 'Invalid triggerSource: {}'.format(triggerSource)) if awaitOperator: self.awaitOperation()
def setVoltage(self, channel, voltage): if voltage < -7 or voltage > 7: raise DeviceException('voltage should be in [-7, 7].') self.setCode(channel, int(voltage / 7 * 0x80000) + 0x80000)
def __checkChannel(self, channel): if channel < 0 or channel >= self.channelCount: raise DeviceException("channel can only be a Int in [0, {})".format(self.channelCount))