def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sCmd = 'SNAP?1,2'
         sAns = self.askAndLog(sCmd).strip()
         lData = sAns.split(',')
         # return complex values
         return complex(float(lData[0].strip()), float(lData[1].strip()))
     elif name == 'R':
         #convert resistance to Kelvin
         R_volt = VISA_Driver.performGetValue(self, quant, options=options)
         Amp = 0.01  # 0.01 V
         R_std = 10e6  # standard resistance in Ohm
         R1 = R_volt / (Amp / R_std)  # R: resistance of thermometer
         if R1 > 3590:
             Temp = 377 * ((1 / (R1 - 1500)) + 8.22e-6)**0.86296
         else:
             Temp = 4031 * ((1 / (R1 - 997.7)) + 4.54e-5)**1.15512
         return Temp
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # check type of quantity
        if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data', 'Ch4 - Data'):
            # traces, get channel
            channel = int(quant.name[2])
            # check if channel is on
            if self.getValue('Ch%d - Enabled' % channel):
                # get waveform descriptor data
#                sDesc = self.askAndLog('C%d:WF? DESC;' % channel)
                self.write('C%d:WF? DESC;' % channel, bCheckError=False)
                sDesc = self.read(ignore_termination=True)
                # start by finding byte count, skip 9 bytes after
                indx = sDesc.find('#9')
                sDesc = sDesc[indx+2+9:]
                # strip out relevant info
                iFirst = struct.unpack('>i', sDesc[124:128])[0]
                iLast = struct.unpack('>i', sDesc[128:132])[0]
                Voffs = struct.unpack('>f', sDesc[160:164])[0]
                Vgain = struct.unpack('>f', sDesc[156:160])[0]
                dt = struct.unpack('>f', sDesc[176:180])[0]
                nPts = struct.unpack('>i', sDesc[116:120])[0]
    #            print (iFirst, iLast, Voffs, Vgain, dt, nPts)
                #
                # do a second call to get data, convert to numpy array
                self.write('C%d:WF? DAT1;' % channel, bCheckError=False)
                sData = self.read(ignore_termination=True)
                head = 16
                vData = np.fromstring(sData[(head + iFirst*2):(head + (iLast+1)*2)], 
                                      dtype='>h', count=nPts)
                value = InstrumentQuantity.getTraceDict(vData*Vgain + Voffs, dt=dt)
            else:
                # not enabled, return empty array
                value = InstrumentQuantity.getTraceDict([])
        elif quant.name == 'Trig source':
            # trig source, treat seperately
            sAns = self.askAndLog('TRSE?').strip()
            i1 = sAns.find(',SR,') + 4
            i2 = sAns.find(',HT')
            # convert response to a number
            value = quant.getValueFromCmdString(sAns[i1:i2])
        elif quant.name == 'Trig level':
            # trig options, get local trig source value
            sTrig = self.getCmdStringFromValue('Trig source')
            sAns = self.askAndLog('%s:TRLV?' % sTrig).strip()
            i1 = sAns.find('V')
            value = float(sAns[:i1])
        elif quant.name == 'Trig slope':
            # trig options, get local trig source value
            sTrig = self.getCmdStringFromValue('Trig source')
            # update visa commands
            quant.set_cmd = '%s:TRSL' % sTrig
            # run standard VISA case with updated commands
            value = VISA_Driver.performGetValue(self, quant, options)
        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        if quant.name in ('Frequency'):
            value = VISA_Driver.performGetValue(
                self, quant,
                options) / 1e2  # Return value is pad with 0 in the end.
        elif quant.name in ('Level', 'Output', 'REF_10M', 'REF_1.6G'):
            value = VISA_Driver.performGetValue(
                self, quant, options
            )  # value will be converted according to combo_defs, if there exists.
        else:
            value = quant.getValue()

        return value
Example #4
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     if (quant.datatype == quant.DOUBLE):
         value = self.askAndLog(quant.set_cmd+"?")
         value = value.replace(" ", "")
         for i,c in enumerate(value):
             if not c in "0123456789.-eE":
                 break
         number=float(value[:i])
         unit=value[i:]
         
         factor = 1
         cfactor = unit[:1]
         if (cfactor == "G"):
             factor = 1e9
         elif (cfactor == "M"):
             factor = 1e6
         elif (cfactor == "k"):
             factor = 1e3
         elif (cfactor == "m"):
             factor = 1e-3
         elif (cfactor == "u"):
             factor = 1e-6
         elif (cfactor == "n"):
             factor = 1e-9
         elif (cfactor == "p"):
             factor = 1e-12
         v = float(number)*factor
         return v
     else:
         value = VISA_Driver.performGetValue(self, quant, options)
         return value
Example #5
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sCmd = 'SNAP?1,2'
         sAns = self.askAndLog(sCmd).strip()
         lData =  sAns.split(',')
         
         #Sometimes, we receive the value twice 
         #(0.12e-3,4.56e-70.12e-3,4.56e-7 instead of 0.12e-3,4.56e-7)
         #This is a simple fix:
         if len(lData) > 2:
             lData =  sAns[:int(len(sAns)/2)].split(',')
         #Also, sometimes we receive an additional "-" at the end of a value
         #(0.12e-3,4.56e-7- instead of 0.12e-3,4.56e-7)
         #Hence, another simple fix:
         if lData[1][-1] == "-":
             lData[1] = ldata[1][:-1]
         
         # return complex values
         return complex(float(lData[0].strip()), float(lData[1].strip()))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #6
0
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # check type of quantity
        if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data', 'Ch4 - Data'):
            # traces, get channel
            channel = int(quant.name[2])
            # check if channel is on
            if self.getValue('Ch%d - Enabled' % channel):
                self.writeAndLog(':WAV:SOUR CHAN%d' % channel)
                self.writeAndLog(':WAV:MODE NORMal')
                self.writeAndLog(':WAV:FORM ASCii')

                raw_data = self.askAndLog(':WAV:DATA?')
                string_list=raw_data[11:-1].split(',')         
                # 9000014000XXXXXXX
                wave_list=[float(s) for s in string_list]
                self.log(len(wave_list))


                origin_point = float(self.askAndLog(':WAVeform:XORigin?'))
                x_incre=float(self.askAndLog(':WAVeform:XINCrement?'))


                value = InstrumentQuantity.getTraceDict(wave_list, x0=origin_point  ,dx=x_incre  )

            else:
                # not enabled, return empty array
                value = np.asarray([])
        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # do special case get value for some quantities
        if quant.name == 'I Voltage':
            return self.getVoltage(1)
        elif quant.name == 'Q Voltage':
            return self.getVoltage(2)
        elif quant.name == 'I Autorange':
            return self.getCommand('A', 1)
        elif quant.name == 'Q Autorange':
            return self.getCommand('A', 2)
        elif quant.name == 'I Range':
            return self.getCommand('R', 1)
        elif quant.name == 'Q Range':
            return self.getCommand('R', 2)
        elif quant.name == 'I Offset':
            return self.IOffset
        elif quant.name == 'Q Offset':
            return self.QOffset
        elif quant.name == 'II':
            return self.II
        elif quant.name == 'QQ':
            return self.QQ
        elif quant.name == 'IQ':
            return self.IQ
        elif quant.name == 'QI':
            return self.QI

        
        else:
            # run the generic visa driver case
            return VISA_Driver.performGetValue(self, quant, options=options)
Example #8
0
 def performGetValue(self, quant, options={}):
     self.log('performGetValue called: ' + quant.name)
     if quant.name.startswith('Measure '):
         #Determine which variables are being measured
         quantDict = {'Measure Current':'CURR', \
                      'Measure Voltage':'VOLT', \
                      'Measure Resistance':'RES'}
         reply = VISA_Driver.askAndLog(self, 'FUNC?')
         if quantDict[quant.name] in reply:
             return True
         else:
             return False
     elif quant.name.endswith('variable'):
         #Have set up format so the read or fetch command always returns values in the following order
         quantDict = {'Voltage variable':0, \
                      'Current variable':1, \
                      'Resistance variable':2}
         #If this is first measurement call, perform read operation and return appropriate values
         if self.isFirstCall(options):
             reply = VISA_Driver.askAndLog(self, 'READ?')
         #otherwise perform fetch operation and return appropriate values
         else:
             reply = VISA_Driver.askAndLog(self, 'FETCH?')
         value = reply.split(',')
         return value[quantDict[quant.name]]
     else:
         return VISA_Driver.performGetValue(self, quant, options)
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""

        if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data',
                          'Ch4 - Data'):
            # traces, get channel
            channel = int(quant.name[2])
            # check if channel is on
            if self.getValue('Ch%d - Enabled' % channel):
                self.writeAndLog('FORMAT:DATA ASCii')
                raw_data = self.askAndLog('CHAN%d:WAV:DATA:VAL?' % channel)
                string_list = raw_data.split(',')
                data_list = [float(s) for s in string_list]
                self.log(len(data_list))

                if self.getValue('Return X value'):
                    x_list = data_list[0::2]
                    y_list = data_list[1::2]
                    value = InstrumentQuantity.getTraceDict(y_list, x=x_list)
                else:
                    y_list = data_list
                    x_incre = float(
                        self.askAndLog('TIMebase:RANGe?')) / len(y_list)
                    value = InstrumentQuantity.getTraceDict(y_list,
                                                            x0=0,
                                                            dx=x_incre)

            else:
                # not enabled, return empty array
                value = np.asarray([])
        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation."""
     if quant.name == 'FrequencyA':
         self.writeAndLog('C0')
         value = 1.e6 * float(self.ask('f?'))
     elif quant.name == 'PowerA':
         self.writeAndLog('C0')
         value = self.ask('W?')
     elif quant.name == 'OutputA':
         self.writeAndLog('C0')
         value = self.ask('r?')
         value = int(value)
     elif quant.name == 'FrequencyB':
         self.writeAndLog('C1')
         value = 1.e6 * float(self.ask('f?'))
     elif quant.name == 'PowerB':
         self.writeAndLog('C1')
         value = self.ask('W?')
     elif quant.name == 'OutputB':
         self.writeAndLog('C1')
         value = self.ask('r?')
         value = int(value)
     else:
         # otherwise, call standard VISA case
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #11
0
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        if (quant.datatype == quant.DOUBLE):
            value = self.askAndLog(quant.set_cmd + "?")
            value = value.replace(" ", "")
            for i, c in enumerate(value):
                if not c in "0123456789.-eE":
                    break
            number = float(value[:i])
            unit = value[i:]

            factor = 1
            cfactor = unit[:1]
            if (cfactor == "G"):
                factor = 1e9
            elif (cfactor == "M"):
                factor = 1e6
            elif (cfactor == "k"):
                factor = 1e3
            elif (cfactor == "m"):
                factor = 1e-3
            elif (cfactor == "u"):
                factor = 1e-6
            elif (cfactor == "n"):
                factor = 1e-9
            elif (cfactor == "p"):
                factor = 1e-12
            v = float(number) * factor
            return v
        else:
            value = VISA_Driver.performGetValue(self, quant, options)
            return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data', 'Ch4 - Data'):
         # traces, get channel
         channel = int(quant.name[2])
         # check if channel is on
         if self.getValue('Ch%d - Enabled' % channel):
             # select channel and set # of bytes to send
             self.write(':DATA:SOU CH%d;:WFMO:BYT_N 2;' % channel, bCheckError=False)
             # query range and offset
             sRange = self.ask(':WFMO:XZE?;:WFMO:XIN?;:WFMO:YMU?;:WFMO:YOF?;:WFMO:YZE?;', bCheckError=False)
             lRange = sRange.split(';')
             (t0, dt, gain, ioffset, offset) = [float(s) for s in lRange]
             # get data as i16, convert to numpy array
             self.write('CURV?', bCheckError=False)
             sData = self.read(ignore_termination=True)
             # strip header to find # of points
             i0 = sData.find('#')
             nDig = int(sData[i0+1])
             nByte = int(sData[i0+2:i0+2+nDig])
             nData = nByte/2
             # get data to numpy array
             vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)], 
                                   dtype='>h', count=nData)
             value = InstrumentQuantity.getTraceDict( \
                     gain*(vData - ioffset) + offset, dt=dt)
         else:
             # not enabled, return empty array
             value = InstrumentQuantity.getTraceDict([])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #13
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sCmd = 'SNAP?1,2'
         sAns = self.askAndLog(sCmd).strip()
         lData =  sAns.split(',')
         
         #Sometimes, we receive the value twice 
         #(0.12e-3,4.56e-70.12e-3,4.56e-7 instead of 0.12e-3,4.56e-7)
         #This is a simple fix:
         if len(lData) > 2:
             lData =  sAns[:len(sAns)/2].split(',')
         #Also, sometimes we receive an additional "-" at the end of a value
         #(0.12e-3,4.56e-7- instead of 0.12e-3,4.56e-7)
         #Hence, another simple fix:
         if lData[1][-1] == "-":
             lData[1] = ldata[1][:-1]
         
         # return complex values
         return complex(float(lData[0].strip()), float(lData[1].strip()))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # check type of quantity
        if quant.name in ('Spectrum'):
            # initialize to single mode
            self.writeAndLog(":INIT:CONT OFF")
            self.writeAndLog(":READ:SPEC?", bCheckError=False)
            sData = self.read(ignore_termination=True)
            # strip header to find # of points
            i0 = sData.find(b'#')
            # number of digits in <num_byte>
            nDig = int(sData[(i0 + 1):(i0 + 2)])
            # number of bytes of data that follows
            nByte = int(sData[(i0 + 2):(i0 + 2 + nDig)])
            # number of data points (4-byte IEEE format)
            nData = int(nByte / 4)

            self.log("(nDig, nByte, nData) = (%d, %d, %d)" % (nDig, nByte, nData))
            # restart continous mode
            self.writeAndLog(":INIT:CONT ON")
            # get data to numpy array
            vData = np.frombuffer(sData[(i0 + 2 + nDig):(i0 + 2 + nDig + nByte)],
                                  dtype='<f', count=nData)
            # get start/stop frequencies from instrument
            startFreq = self.readValueFromOther('Start frequency')
            stopFreq = self.readValueFromOther('Stop frequency')
            value = quant.getTraceDict(vData, x0=startFreq, x1=stopFreq)

        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
Example #15
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if channel_re.match(quant.name) or marker_re.match(quant.name) or \
         quant.name in ('Sequence - Trigger source'):
         # do nothing here
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for delay commands
     name = str(quant.name)
     if name.endswith(('Output', )):
         lName = name.split(' - ')
         return self.getValue(
             name)  # return the local value stored in the driver
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     # check quantity
     if quant.name == 'Magnetic Field':
         get_cmd = 'READ:DEV:GRPZ:PSU:SIG:FLD'
         value = float(self._do_read(get_cmd)[:-1])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     self.log("Quantity to be retrieved is " + str(quant.name))
     if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data',
                       'Ch4 - Data'):
         self.log("Quantity is a channel data")
         channel = int(quant.name[2])
         value = self.get_channel_data(channel, quant)
     else:
         self.log("Quantity is not a channel data")
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     # check quantity
     if quant.name == 'Magnetic Field':
         reply = self.askAndLog('R7')
         # strip first character
         value = float(reply[1:])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name in ("Time", "Amplitude"):
         if self.AvgTrace[quant.name] == None:
             self.sample_tV()
         value = self.AvgTrace[quant.name]
         self.AvgTrace[quant.name] = None
     else:
         # run the generic visa driver case
         value = VISA_Driver.performGetValue(self, quant, options=options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name in ('Current', 'Resistance'):
         # check if charge/discharge
         discharge = self.getValue('Discharge/charge before measuring')
         if discharge:
             delay_time = self.getValue('Delay between charging/measuring') 
             # start by discharging, then charging
             self.writeAndLog('MD2')
             self.writeAndLog('OT1')
             self.writeAndLog('MD1')
             # wait some time
             self.wait(delay_time)
             # turn on measurement mode
             self.writeAndLog('MD0')
         # after charging/discharing, run the visa driver case to get value
         return VISA_Driver.performGetValue(self, quant, options=options)
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #22
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation."""
     if quant.name == 'Frequency':
         value = self.ask('FR')
         value = float(value.strip().strip('FR').strip('HZ'))
     elif quant.name == 'Power':
         # value = self.as('LEOA;K')
         value = float(value.strip().strip('LE').strip('DM'))
     else:
         # otherwise, call standard VISA case
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #23
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name in ('Current', 'Resistance'):
         # check if charge/discharge
         discharge = self.getValue('Discharge/charge before measuring')
         if discharge:
             delay_time = self.getValue('Delay between charging/measuring')
             # start by discharging, then charging
             self.writeAndLog('MD2')
             self.writeAndLog('OT1')
             self.writeAndLog('MD1')
             # wait some time
             self.wait(delay_time)
             # turn on measurement mode
             self.writeAndLog('MD0')
         # after charging/discharing, run the visa driver case to get value
         return VISA_Driver.performGetValue(self, quant, options=options)
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #24
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     # check quantity
     if quant.name == 'Magnetic Field':
         reply = self.askAndLog('R7')
         # strip first character
         value = float(reply[1:])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     if quant.name in ('Ch 1', 'Ch 2', 'Ch 3', 'Ch 4', 'Ch 1 - Marker 1',
                       'Ch 1 - Marker 2', 'Ch 2 - Marker 1',
                       'Ch 2 - Marker 2', 'Ch 3 - Marker 1',
                       'Ch 3 - Marker 2', 'Ch 4 - Marker 1',
                       'Ch 4 - Marker 2', 'Sequence transfer mode'):
         # do nothing here
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #26
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for amplitude command
     if quant.name == 'Amplitude':
         # get voltage string from instrument
         sAns = self.askAndLog('AMPL? VP').strip()
         # strip "VP" from string 
         sData =  sAns.split('VP')[0]
         # return float
         return float(sData)
     else:
         # for all other cases, just run the generic visa driver
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #27
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch 1', 'Ch 2', 'Ch 3', 'Ch 4',
                       'Ch 1 - Marker 1', 'Ch 1 - Marker 2',
                       'Ch 2 - Marker 1', 'Ch 2 - Marker 2',
                       'Ch 3 - Marker 1', 'Ch 3 - Marker 2',
                       'Ch 4 - Marker 1', 'Ch 4 - Marker 2'):
         # do nothing here
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #28
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sCmd = 'SNAP?1,2'
         sAns = self.askAndLog(sCmd).strip()
         lData =  sAns.split(',')
         # return complex values
         return complex(float(lData[0].strip()), float(lData[1].strip()))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #29
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch1 - voltage', 'Ch2 - voltage'):
         ch = quant.name[2]
         wfInfor = self.askAndLog(f'SOUR{ch}:APPL?')
         # returned message is like "DC,DEF,DEF,1.000000E+00"
         value = float(wfInfor.strip('"').split(',')[-1])
     elif quant.name in ('Sweep speed'):
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #30
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sCmd = 'SNAP?1,2'
         sAns = self.askAndLog(sCmd).strip()
         lData = sAns.split(',')
         # return complex values
         return complex(float(lData[0].strip()), float(lData[1].strip()))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data',
                       'Ch4 - Data'):
         # traces, get channel
         channel = int(quant.name[2])
         # check if channel is on
         if self.getValue('Ch%d - Enabled' % channel):
             # select channel and set # of bytes to send
             if self.getModel() == 'TDS 3000':
                 self.write(':DATA:SOU CH%d;:WFMP:BYT_N 2;' % channel,
                            bCheckError=False)
             else:
                 self.write(':DATA:SOU CH%d;:WFMO:BYT_N 2;' % channel,
                            bCheckError=False)
             # query range and offset
             if self.getModel() == 'TDS 3000':
                 sRange = self.ask(
                     ':WFMP:XZE?;:WFMP:XIN?;:WFMP:YMU?;:WFMP:YOF?;:WFMP:YZE?;',
                     bCheckError=False)
             else:
                 sRange = self.ask(
                     ':WFMO:XZE?;:WFMO:XIN?;:WFMO:YMU?;:WFMO:YOF?;:WFMO:YZE?;',
                     bCheckError=False)
             lRange = sRange.split(';')
             (t0, dt, gain, ioffset, offset) = [float(s) for s in lRange]
             # get data as i16, convert to numpy array
             self.write('CURV?', bCheckError=False)
             sData = self.read(ignore_termination=True)
             # strip header to find # of points
             i0 = sData.find(b'#')
             nDig = int(sData[i0 + 1:i0 + 2])
             nByte = int(sData[i0 + 2:i0 + 2 + nDig])
             nData = int(nByte / 2)
             # get data to numpy array
             vData = np.frombuffer(sData[(i0 + 2 + nDig):(i0 + 2 + nDig +
                                                          nByte)],
                                   dtype='>h',
                                   count=nData)
             value = InstrumentQuantity.getTraceDict( \
                     gain*(vData - ioffset) + offset, dt=dt)
         else:
             # not enabled, return empty array
             value = InstrumentQuantity.getTraceDict([])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #32
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name[3:] in ('Position', 'Rotation', 'Value'):
         sAns = self.askAndLog(quant.get_cmd).strip()
         # Remove the query string from the response
         value = self.unitFactors[int(quant.name[2])]*float(sAns[len(quant.get_cmd):])
     elif quant.name[3:] in ('Name'):
         sAns = self.askAndLog(quant.get_cmd).strip()
         # Remove the query string from the response (-1 as the query contains a question mark)
         value = sAns[len(quant.get_cmd)-1:]
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name == 'Ch1 - Data':
         if self.data is None:
             self.sample()
         value = InstrumentQuantity.getTraceDict(self.data, t0=self.xdisp, dt=self.xincr)
         self.log(str(self.data))
         self.log(str(self.xdisp))
         self.log(str(self.xincr))
         self.data = None
     
     elif quant.name == 'Power1Mean':
         if self.P1Mean is None:
             self.Psi()
         
         value = self.P1Mean
         self.P1Mean = None
     
     elif quant.name == 'Power2Mean':
         if self.P2Mean is None:
             self.Psi()
         
         value = self.P2Mean
         self.P2Mean = None
     
     elif quant.name == 'RF Frequency 1':
         value = self.f1
         
     elif quant.name == 'RF Frequency 2':
         value = self.f2
     
     elif quant.name == 'Psi':
         if self.psi is None:
             self.IQ_demodulate()
         value = self.psi
         self.psi = None
         
     elif quant.name == 'Covar':
         if self.covar is None:
             self.Psi()
         value = self.covar.reshape([1, -1])[0]
         self.covar = None
     
     else:
         value = VISA_Driver.performGetValue(self, quant, options=options)
          
     return value
Example #34
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name[3:] in ('Position', 'Rotation', 'Value'):
         sAns = self.askAndLog(quant.get_cmd).strip()
         # Remove the query string from the response
         value = self.unitFactors[int(quant.name[2])] * float(
             sAns[len(quant.get_cmd):])
     elif quant.name[3:] in ('Name'):
         sAns = self.askAndLog(quant.get_cmd).strip()
         # Remove the query string from the response (-1 as the query contains a question mark)
         value = sAns[len(quant.get_cmd) - 1:]
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #35
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     # check quantity
     if quant.name == 'Magnetic Field':
         self.wait(delayTime)
         # conversion from mT -> T
         reply = self.askAndLog('R7')
         # strip first character
         reply = reply[1:]
         # convert to float, scale from mT to T
         value = 1E-3 * float(reply)
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""

        active_channel_quants = [
            'Temperature', 'Quadrature', 'Resistance', 'Power'
        ]

        #Try and parse the quantity name to get the quant type and channel number
        qname, qchannel = parse_qname(quant.name)

        if qname in active_channel_quants:
            #These are really just a convenience for remote operation
            #In any real measurements one would use the appropriate channel X quants
            current_channel = self.readValueFromOther('Active Channel')

            cmd = quant.get_cmd.replace('<*>', current_channel)
            value = self.askAndLog(cmd, bCheckError=False)

        elif qname == 'Active Channel':
            value = self.askAndLog('SCAN?', bCheckError=False).split(',')[0]

        elif qchannel is not None:

            for _cmd, _quants in SPECIAL_QUANTS.items():
                if qname in _quants:
                    cmd = _cmd
                    break

            vals_list = self.askAndLog('%s? %s' % (cmd, qchannel),
                                       bCheckError=False).split(',')

            #There is really no reason not to set all of the other ones here, too.
            for val, q in zip(vals_list, SPECIAL_QUANTS[cmd]):
                _qname = '%s Ch_%s' % (q, qchannel)

                #Have to do a check here because not all the quants exist for channel A
                if _qname in self.dQuantities.keys():
                    self.setValue(_qname, val)

                #Make sure the function still resturns the right thing
                if _qname == quant.name:
                    value = val

        else:
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""        
     if quant.name in ('Time', 'Amplitude'): #for time and amplitude, call the special acquisition function
         if self.AvgTrace[quant.name]==None:
             self.sample_tV()
         value=self.AvgTrace[quant.name]
         self.AvgTrace[quant.name]=None
     elif quant.name in ('RollAvg Time', 'RollAvg Amplitude'):
         if self.AvgTrace[quant.name]==None:
             self.sample_long()
         value=self.AvgTrace[quant.name]
         self.AvgTrace[quant.name]=None
     elif quant.name=="Number of shifts":
         value = self.numRep
     else:
         # otherwise run the generic visa driver case
         value=VISA_Driver.performGetValue(self, quant, options=options)
     return value
Example #38
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name in ('Function', 'Range (V)', 'Range (I)'):
         # common method for these quants
         s1 = self.askAndLog('OS')
         # this command returns five lines of info, get them all
         s2 = self.read()
         s3 = self.read()
         s4 = self.read()
         s5 = self.read()
         # check for errors and raise exception if necesary
         self.queryErrors()
         # first four characters in line 2 contains the info 'FnRm', with
         # F: n=1: voltage, n=5: current
         # R: m=2-6: voltage range, m=4-6: current range
         sFunc = s2[1]
         sRange = s2[3]
         if quant.name == 'Function':
             # func quantity, get value
             valueFunc = quant.getValueFromCmdString(sFunc)
             # function changed, keep track of new internal range quantities
             if valueFunc == 'Voltage':
                 quantRange = self.getQuantity('Range (V)')
             elif valueFunc == 'Current':
                 quantRange = self.getQuantity('Range (I)')
             valueRange = quantRange.getValueFromCmdString(sRange)
             quantRange.setValue(valueRange)
             # return func value
             return valueFunc
         else:
             # range quantity
             return quant.getValueFromCmdString(sRange)
     # check for output
     elif quant.name == 'Output':
         # get bit info, output is bit 4 (=16)
         status = self.askAndLog('OC')
         # check for errors and raise exception if necesary
         self.queryErrors()
         # perform bitwise and to get output on/off
         return (int(status[5:]) & 16) > 0
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch1 - Data', 'Ch2 - Data', 'Ch3 - Data',
                       'Ch4 - Data'):
         # traces, get channel
         channel = int(quant.name[2])
         # check if channel is on
         if self.getValue('Ch%d - Enabled' % channel):
             # query range and offset
             sRange = self.askAndLog('WAV:PRE?', bCheckError=False)
             lRange = sRange.split(',')
             #<format 16-bit NR1>, <type 16-bit NR1>, <points 32-bit NR1>, <count 32-bit NR1>,
             #<xincrement 64-bit floating point NR3>, <xorigin 64-bit floating point NR3>,
             #<xreference 32-bit NR1>,
             #<yincrement 32-bit floating point NR3>, <yorigin 32-bit floating point NR3>,
             #<yreference 32-bit NR1>
             iStep = 256 if int(lRange[0]) == 0 else 65536
             pts = int(lRange[2])
             dt = float(lRange[4])
             gain = float(lRange[7])
             y_offs = float(lRange[8])
             y_offs_byte = int(lRange[9])
             # get data as i16, convert to numpy array
             self.write('WAV:DATA?', bCheckError=False)
             sHead0 = self.read(n_bytes=10)
             # strip header to find # of points
             i0 = sData.find(b'#')
             nDig = int(sData[i0 + 1:i0 + 2])
             nByte = int(sData[i0 + 2:i0 + 2 + nDig])
             # read data, including final line feed
             sData = self.read(n_bytes=(1 + nByte))
             # get data to numpy array
             vData = np.frombuffer(sData[:-1], dtype='>f')
             value = quant.getTraceDict(gain * (vData - y_offs_byte) +
                                        y_offs,
                                        dt=dt)
         else:
             # not enabled, return empty array
             value = quant.getTraceDict([])
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #40
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name in ('Function', 'Range (V)', 'Range (I)'):
         # common method for these quants
         s1 = self.askAndLog('OS')
         # this command returns five lines of info, get them all
         s2 = self.read()
         s3 = self.read()
         s4 = self.read()
         s5 = self.read()
         # check for errors and raise exception if necesary
         self.queryErrors()
         # first four characters in line 2 contains the info 'FnRm', with
         # F: n=1: voltage, n=5: current
         # R: m=2-6: voltage range, m=4-6: current range
         sFunc = s2[1]
         sRange = s2[3]
         if quant.name == 'Function':
             # func quantity, get value
             valueFunc = quant.getValueFromCmdString(sFunc)
             # function changed, keep track of new internal range quantities
             if valueFunc == 'Voltage':
                 quantRange = self.getQuantity('Range (V)')
             elif valueFunc == 'Current':
                 quantRange = self.getQuantity('Range (I)')
             valueRange = quantRange.getValueFromCmdString(sRange)
             quantRange.setValue(valueRange)
             # return func value
             return valueFunc
         else:
             # range quantity
             return quant.getValueFromCmdString(sRange)
     # check for output
     elif quant.name == 'Output':
         # get bit info, output is bit 4 (=16)
         status = self.askAndLog('OC')
         # check for errors and raise exception if necesary
         self.queryErrors()
         # perform bitwise and to get output on/off
         return (int(status[5:]) & 16) > 0
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""

        if 'Slot' in quant.name:
            value = quant.getValue()
        elif quant.name == 'Passthrough':

            module_code = options.pop('module_code', None)
            if module_code is None:
                value = 'None'
            else:
                port = self.ports_dict[module_code]
                module_cmd = options.pop('module_cmd', None)

                value = self.sim900_module_ask(port, module_cmd)

        else:
            value = VISA_Driver.performGetValue(self, quant, options=options)
        return value
Example #42
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('Ch 1', 'Ch 2', 'Ch 3', 'Ch 4'):
         # do nothing here
         value = quant.getValue()
     if quant.name == 'Run mode':
         # run mode is handled by two commands
         cont = int(self.askAndLog(':INIT:CONT?'))
         gate = int(self.askAndLog(':INIT:GATE?'))
         if cont:
             value = 'Continuous'
         elif gate:
             value = 'Gated'
         else:
             value = 'Triggered'
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == "Value":
         # get complex value in one instrument reading
         sAns = self.askAndLog(quant.get_cmd).strip()
         lData = sAns.split(",")
         # Python float() complains about 0.0E+00
         #            if lData[0].strip() == "0.0E+00":
         #                lData[0] = "0"
         #            if lData[1].strip() == "0.0E+00":
         #                lData[1] = "0"
         #            self.log("Test: " + lData[1])
         #            return complex(0.0, 0.0)
         # return complex values
         return complex(float(lData[0].rstrip(" \r\n\0")), float(lData[1].rstrip(" \r\n\0")))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
Example #44
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check quantity
     if quant.name == 'He level':
         self.wait(0.1)
         # switch instrument to fast mode
         self.writeAndLog('$T1')
         self.wait(0.1)
         reply = self.askAndLog('R1')
         self.wait(0.1)
         # switch instrument to slow mode
         self.writeAndLog('$S1')
         # strip first character
         reply = reply[1:]
         # convert to float, scale to percentage
         value = 0.1 * float(reply)
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
Example #45
0
 def performGetValue(self, quant, options={}):
     if quant.name == 'Output':
         value = VISA_Driver.askAndLog(self,'OUTP:STAT?')
         #Value will be 0 (false/off) or 1 (true/on)
         return int(value)
     elif quant.name == 'Function':
         value = VISA_Driver.askAndLog(self,'SOUR:FUNC?')
         if value == 'VOLT':
             return 'Voltage'
         elif value == 'CURR':
             return 'Current'
         return value
     elif quant.name == 'Source Current Range' or quant.name == 'Source Voltage Range':
         return VISA_Driver.askAndLog(self,'SOUR:RANG?')
     elif quant.name == 'Source Voltage Level' or quant.name == 'Source Current Level':
         returnVal = VISA_Driver.askAndLog(self,'SOUR:LEV?')
         return float(returnVal)
     else:
         self.log('Get quantity not listed elsewhere: '+quant.name)
         return VISA_Driver.performGetValue(self,quant,options)
Example #46
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for delay commands
     name = str(quant.name)
     if name.endswith(('Start time', 'Start reference',
                       'Stop time', 'Stop reference')):
         # get pulse channel in use
         lName =  name.split(' ')
         key = '%s - %s' % (lName[0], lName[2])
         sChannel = '%d' % self.dChCmd[key]
         sCmd = 'DLAY?%s' % sChannel
         sAns = self.askAndLog(sCmd).strip()
         lAns = sAns.split(',')
         # return time or reference
         if lName[3] == 'time':
             return float(lAns[1])
         else:
             return quant.getValueFromCmdString(lAns[0])
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # perform special getValue for reading complex value
     name = str(quant.name)
     if name == 'Value':
         # get complex value in one instrument reading
         sAns = self.askAndLog(quant.get_cmd).strip()
         lData = sAns.split(',')
         #Python float() complains about 0.0E+00
         #            if lData[0].strip() == "0.0E+00":
         #                lData[0] = "0"
         #            if lData[1].strip() == "0.0E+00":
         #                lData[1] = "0"
         #            self.log("Test: " + lData[1])
         #            return complex(0.0, 0.0)
         # return complex values
         return complex(float(lData[0].rstrip(" \r\n\0")),
                        float(lData[1].rstrip(" \r\n\0")))
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # do special case get value for some quantities
     if quant.name == 'Channel 1 Voltage':
         return self.getVoltage(1)
     elif quant.name == 'Channel 2 Voltage':
         return self.getVoltage(2)
     elif quant.name == 'Channel 3 Voltage':
         return self.getVoltage(3)
     elif quant.name == 'Channel 4 Voltage':
         return self.getVoltage(4)
     elif quant.name == 'Channel 1 Autorange':
         return self.getCommand('A', 1)
     elif quant.name == 'Channel 2 Autorange':
         return self.getCommand('A', 2)
     elif quant.name == 'Channel 3 Autorange':
         return self.getCommand('A', 3)
     elif quant.name == 'Channel 4 Autorange':
         return self.getCommand('A', 4)
     elif quant.name == 'Channel 1 Range':
         return self.getCommand('R', 1)
     elif quant.name == 'Channel 2 Range':
         return self.getCommand('R', 2)
     elif quant.name == 'Channel 3 Range':
         return self.getCommand('R', 3)
     elif quant.name == 'Channel 4 Range':
         return self.getCommand('R', 4)
     elif quant.name == 'Channel 1 Autosweep':
         return self.bSweep1
     elif quant.name == 'Channel 2 Autosweep':
         return self.bSweep2
     elif quant.name == 'Channel 3 Autosweep':
         return self.bSweep3
     elif quant.name == 'Channel 4 Autosweep':
         return self.bSweep4   
     
     else:
         # run the generic visa driver case
         return VISA_Driver.performGetValue(self, quant, options=options)
 def performGetValue(self, quant, options={}):
     try:
         if quant.name == "Frequency":
             return self.dFreq
         elif quant.name == "Power":
             return self.dPower
         elif quant.name == "Output":
             return self.bOutput
         elif quant.name == "Phase Offset":
             return self.dPhaseOffset
         elif quant.name == "Amplitude Modulation":
             return self.bAmplitudeModulation
         elif quant.name == "Amplitude Modulation Mode":
             value = quant.getValueString(self.nAmplitudeModulationMode)
             return value
         elif quant.name == "Internal Pulse Modulation":
             return self.bInternalPulseModulation
         elif quant.name == "Internal Pulse Modulation Mode":
             value = quant.getValueString(self.nInternalPulseModulationMode)
             return value
         elif quant.name == "Internal Pulse Period":
             return self.dInternalPulsePeriod
         elif quant.name == "Internal Pulse Width":
             return self.dInternalPulseWidth
         elif quant.name == "Internal Pulse Width":
             return self.dInternalPulseDelay
         elif quant.name == "Trigger Mode":
             value = quant.getValueString(self.nTriggerMode)
             return value
         elif quant.name == "Positive or Negative Trigger Edge":
             value = quant.getValueString(self.nPosOrNegEdge)
             return value
         else:
             return VISA_Driver.performGetValue(self, quant, options=options)
     except Error as e:
         # re-cast errors as a generic communication error
         msg = str(e)
         raise InstrumentDriver.CommunicationError(msg)
 def performGetValue(self, quant, options={}):
     self.log("performGetValue called: " + quant.name)
     if quant.name.startswith("Measure "):
         # Determine which variables are being measured
         quantDict = {"Measure Current": "CURR", "Measure Voltage": "VOLT", "Measure Resistance": "RES"}
         reply = VISA_Driver.askAndLog(self, "FUNC?")
         if quantDict[quant.name] in reply:
             return True
         else:
             return False
     elif quant.name.endswith("variable"):
         # Have set up format so the read or fetch command always returns values in the following order
         quantDict = {"Voltage variable": 0, "Current variable": 1, "Resistance variable": 2}
         # If this is first measurement call, perform read operation and return appropriate values
         if self.isFirstCall(options):
             reply = VISA_Driver.askAndLog(self, "READ?")
         # otherwise perform fetch operation and return appropriate values
         else:
             reply = VISA_Driver.askAndLog(self, "FETCH?")
         value = reply.split(",")
         return value[quantDict[quant.name]]
     else:
         return VISA_Driver.performGetValue(self, quant, options)
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ("S11 - Enabled", "S21 - Enabled", "S12 - Enabled", "S22 - Enabled"):
         # update list of channels in use
         self.getActiveMeasurements()
         # get selected parameter
         param = quant.name[:3]
         value = param in self.dMeasParam
     elif quant.name in ("S11", "S21", "S12", "S22"):
         # check if channel is on
         if quant.name not in self.dMeasParam:
             # get active measurements again, in case they changed
             self.getActiveMeasurements()
         if quant.name in self.dMeasParam:
             # get trace name from parameter (use last trace in list)
             sName = self.dMeasParam[quant.name][-1]
             self.writeAndLog("CALC:PAR:SEL '%s'" % sName)
             # if not in continous mode, trig from computer
             bWaitTrace = self.getValue("Wait for new trace")
             bAverage = self.getValue("Average")
             # wait for trace, either in averaging or normal mode
             if bWaitTrace:
                 if bAverage:
                     nAverage = self.getValue("# of averages")
                     self.writeAndLog(":SENS:AVER:CLE;:ABOR;")
                 else:
                     self.writeAndLog(":ABOR;:INIT:CONT OFF;:INIT:IMM;*OPC")
                 # wait some time before first check
                 self.thread().msleep(30)
                 bDone = False
                 while (not bDone) and (not self.isStopped()):
                     # check if done
                     if bAverage:
                         sAverage = self.askAndLog("SENS:AVER:COUN:CURR?")
                         bDone = int(sAverage) >= nAverage
                     else:
                         stb = int(self.askAndLog("*ESR?"))
                         bDone = (stb & 1) > 0
                     if not bDone:
                         self.thread().msleep(100)
                 # if stopped, don't get data
                 if self.isStopped():
                     self.writeAndLog("*CLS;:INIT:CONT ON;")
                     return []
             # get data as float32, convert to numpy array
             self.write(":FORM REAL,32;CALC:DATA? SDATA", bCheckError=False)
             sData = self.read(ignore_termination=True)
             if bWaitTrace and not bAverage:
                 self.writeAndLog(":INIT:CONT ON;")
             # strip header to find # of points
             i0 = sData.find("#")
             nDig = int(sData[i0 + 1])
             nByte = int(sData[i0 + 2 : i0 + 2 + nDig])
             nData = nByte / 4
             nPts = nData / 2
             # get data to numpy array
             vData = np.frombuffer(sData[(i0 + 2 + nDig) : (i0 + 2 + nDig + nByte)], dtype=">f", count=nData)
             # data is in I0,Q0,I1,Q1,I2,Q2,.. format, convert to complex
             mC = vData.reshape((nPts, 2))
             vComplex = mC[:, 0] + 1j * mC[:, 1]
             # get start/stop frequencies
             startFreq = self.readValueFromOther("Start frequency")
             stopFreq = self.readValueFromOther("Stop frequency")
             sweepType = self.readValueFromOther("Sweep type")
             # if log scale, take log of start/stop frequencies
             if sweepType == "Log":
                 startFreq = np.log10(startFreq)
                 stopFreq = np.log10(stopFreq)
             # create a trace dict
             value = InstrumentQuantity.getTraceDict(vComplex, t0=startFreq, dt=(stopFreq - startFreq) / (nPts - 1))
         else:
             # not enabled, return empty array
             value = InstrumentQuantity.getTraceDict([])
     elif quant.name in ("Wait for new trace",):
         # do nothing, return local value
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     # check type of quantity
     if quant.name in ('S11 - Enabled', 'S21 - Enabled', 'S12 - Enabled',
                       'S22 - Enabled'):
         # update list of channels in use
         self.getActiveMeasurements()
         # get selected parameter
         param = quant.name[:3]
         value = (param in self.dMeasParam)
     elif quant.name in ('S11', 'S21', 'S12', 'S22'):
         # check if channel is on
         if quant.name not in self.dMeasParam:
             # get active measurements again, in case they changed
             self.getActiveMeasurements()
         if quant.name in self.dMeasParam:
             if self.getModel() in ('E5071C',):
                 # new trace handling, use trace numbers
                 self.writeAndLog("CALC:PAR%d:SEL" % self.dMeasParam[quant.name])
             else:
                 # old parameter handing, select parameter (use last in list)
                 sName = self.dMeasParam[quant.name][-1]
                 self.writeAndLog("CALC:PAR:SEL '%s'" % sName)
             # if not in continous mode, trig from computer
             bWaitTrace = self.getValue('Wait for new trace')
             bAverage = self.getValue('Average')
             # wait for trace, either in averaging or normal mode
             if bWaitTrace:
                 if bAverage:
                     # set channels 1-4 to set event when average complete (bit 1 start)
                     self.writeAndLog(':SENS:AVER:CLE;:STAT:OPER:AVER1:ENAB 30;:ABOR;:SENS:AVER:CLE;')
                 else:
                     self.writeAndLog(':ABOR;:INIT:CONT OFF;:INIT:IMM;')
                     self.writeAndLog('*OPC') 
                 # wait some time before first check
                 self.thread().msleep(30)
                 bDone = False
                 while (not bDone) and (not self.isStopped()):
                     # check if done
                     if bAverage:
                         sAverage = self.askAndLog('STAT:OPER:AVER1:COND?')
                         bDone = int(sAverage)>0
                     else:
                         stb = int(self.askAndLog('*ESR?'))
                         bDone = (stb & 1) > 0
                     if not bDone:
                         self.thread().msleep(100)
                 # if stopped, don't get data
                 if self.isStopped():
                     self.writeAndLog('*CLS;:INIT:CONT ON;')
                     return []
             # get data as float32, convert to numpy array
             if self.getModel() in ('E5071C',):
                 # new trace handling, use trace numbers
                 self.write(':FORM:DATA REAL32;:CALC:SEL:DATA:SDAT?', bCheckError=False)
             else:
                 # old parameter handing
                 self.write(':FORM REAL,32;CALC:DATA? SDATA', bCheckError=False)
             sData = self.read(ignore_termination=True)
             if bWaitTrace and not bAverage:
                 self.writeAndLog(':INIT:CONT ON;')
             # strip header to find # of points
             i0 = sData.find('#')
             nDig = int(sData[i0+1])
             nByte = int(sData[i0+2:i0+2+nDig])
             nData = nByte/4
             nPts = nData/2
             # get data to numpy array
             vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)], 
                                   dtype='>f', count=nData)
             # data is in I0,Q0,I1,Q1,I2,Q2,.. format, convert to complex
             mC = vData.reshape((nPts,2))
             vComplex = mC[:,0] + 1j*mC[:,1]
             # get start/stop frequencies
             startFreq = self.readValueFromOther('Start frequency')
             stopFreq = self.readValueFromOther('Stop frequency')
             sweepType = self.readValueFromOther('Sweep type')
             # if log scale, take log of start/stop frequencies
             if sweepType == 'Log':
                 startFreq = np.log10(startFreq)
                 stopFreq = np.log10(stopFreq)
             # create a trace dict
             value = InstrumentQuantity.getTraceDict(vComplex, t0=startFreq,
                                            dt=(stopFreq-startFreq)/(nPts-1))
         else:
             # not enabled, return empty array
             value = InstrumentQuantity.getTraceDict([])
     elif quant.name in ('Wait for new trace',):
         # do nothing, return local value
         value = quant.getValue()
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # check type of quantity
        if quant.name in ('Signal',):
            # check if channel is on
            if True: #quant.name in self.dMeasParam:
                # if not in continous mode, trig from computer
                bWaitTrace = self.getValue('Wait for new trace')
                bAverage = self.getValue('Average')
                # wait for trace, either in averaging or normal mode
                if bWaitTrace:
                    if bAverage:
                        nAverage = self.getValue('# of averages')
#                        self.writeAndLog(':SENS:AVER:CLE;:ABOR;:INIT;*WAI')
                        self.writeAndLog(':ABOR;:INIT:CONT OFF;:SENS:AVER:COUN %d;:INIT:IMM;*OPC' % nAverage)
                    else:
                        self.writeAndLog(':ABOR;:INIT:CONT OFF;:SENS:AVER:COUN 1;:INIT:IMM;*OPC')
                    # wait some time before first check
                    self.wait(0.03)
                    bDone = False
                    while (not bDone) and (not self.isStopped()):
                        # check if done
                        if bAverage:
#                            sAverage = self.askAndLog('SENS:AVER:COUN:CURR?')
#                            bDone = (int(sAverage) >= nAverage)
                            stb = int(self.askAndLog('*ESR?'))
                            bDone = (stb & 1) > 0
                        else:
                            stb = int(self.askAndLog('*ESR?'))
                            bDone = (stb & 1) > 0
                        if not bDone:
                            self.wait(0.1)
                    # if stopped, don't get data
                    if self.isStopped():
                        self.writeAndLog('*CLS;:INIT:CONT ON;')
                        return []
                # get data as float32, convert to numpy array
                sData = self.ask(':FORM REAL,32;TRAC1? TRACE1')
                if bWaitTrace and not bAverage:
                    self.writeAndLog(':INIT:CONT ON;')
                # strip header to find # of points
                i0 = sData.find('#')
                nDig = int(sData[i0+1])
                nByte = int(sData[i0+2:i0+2+nDig])
                nData = nByte/4
                # get data to numpy array
                vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)], 
                                      dtype='<f', count=nData)
                # get start/stop frequencies
#                if self.getValue('Range type')=='Center - Span':
#                    startFreq = self.getValue('Center frequency') - self.getValue('Span')/2.0
#                    stopFreq = self.getValue('Center frequency') + self.getValue('Span')/2.0
#                else:
#                    startFreq = self.getValue('Start frequency')
#                    stopFreq = self.getValue('Stop frequency')
                startFreq = self.readValueFromOther('Start frequency')
                stopFreq = self.readValueFromOther('Stop frequency')
#                sweepType = self.getValue('Sweep type')
                # if log scale, take log of start/stop frequencies
#                if sweepType == 'Log':
#                    startFreq = np.log10(startFreq)
#                    stopFreq = np.log10(stopFreq)
                # if log scale, take log of start/stop frequencies

                # create a trace dict
                value = quant.getTraceDict(vData, x0=startFreq, x1=stopFreq)
            else:
                # not enabled, return empty array
                value = quant.getTraceDict([])
        elif quant.name in ('Wait for new trace',):
            # do nothing, return local value
            value = quant.getValue()
        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value
Example #54
0
 def performGetValue(self, quant, options={}):
     """Perform the Get Value instrument operation"""
     value = VISA_Driver.performGetValue(self, quant, options)
     return value
	def performGetValue(self, quant, options={}):
		"""Perform the Get Value instrument operation"""
		# check type of quantity
		#if quant.name in ('Zero-span mode',):
		if quant.name in ('Range type',):
			# check if span is zero
			span = self.readValueFromOther('Span')
			if span == 0:
				value = 'Zero-span mode'
			else:
				# return old value if not in zero span
				value = quant.getValueString()
				if value == 'Zero-span mode':
					value = 'Center - Span'
		elif quant.name in ('Signal', 'Signal - Zero span'):
			# if not in continous mode, trig from computer
			bWaitTrace = self.getValue('Wait for new trace')
			bAverage = self.getValue('Average')
			# wait for trace, either in averaging or normal mode
			if bAverage:
				# clear averages
				self.writeAndLog(':SENS:AVER:CLE;')
				self.writeAndLog(':ABOR;:INIT:CONT OFF;:INIT:IMM;*OPC')
				# wait some time before first check
				self.thread().msleep(30)
				bDone = False
				while (not bDone) and (not self.isStopped()):
					# check if done
					stb = int(self.askAndLog('*ESR?'))
					bDone = (stb & 1) > 0
					if not bDone:
						self.thread().msleep(50)
				# if stopped, don't get data
				if self.isStopped():
					self.writeAndLog('*CLS;:INIT:CONT ON;')
					return []
			# get data as float32, convert to numpy array
			self.write(':FORM REAL,32;TRAC:DATA? TRACE1', bCheckError=False)
			sData = self.read(ignore_termination=True)
			if bWaitTrace and not bAverage:
				self.writeAndLog(':INIT:CONT ON;')
			# strip header to find # of points
			i0 = sData.find('#')
			nDig = int(sData[i0+1])
			nByte = int(sData[i0+2:i0+2+nDig])
			nPts = nByte/4
			# get data to numpy array
			vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)],
											dtype='>f', count=nPts)
			# get start/stop frequencies
			startFreq = self.readValueFromOther('Start frequency')
			stopFreq = self.readValueFromOther('Stop frequency')
            # sweepType = self.readValueFromOther('Sweep type')
            # # if log scale, take log of start/stop frequencies
            # if sweepType == 'Log':
                # startFreq = np.log10(startFreq)
                # stopFreq = np.log10(stopFreq)
            # check if return trace or trace average
			if quant.name == 'Signal - Zero span':
				# return average
				value = np.average(vData)
			else:
				# create a trace dict
				value = InstrumentQuantity.getTraceDict(vData, t0=startFreq, 
																		  dt=(stopFreq-startFreq)/(nPts-1))
		elif quant.name in ('Signal - CW'):
			# if not in continous mode, trig from computer
			bWaitTrace = self.getValue('Wait for new trace')
			bAverage = self.getValue('Average CW')
			# wait for trace, either in averaging or normal mode
			if bAverage:
				# clear averages
				self.writeAndLog(':WAV:AVER:CLE;')
				self.writeAndLog(':ABOR;:INIT:CONT OFF;:INIT:IMM;*OPC')
				# wait some time before first check
				self.thread().msleep(30)
				bDone = False
				while (not bDone) and (not self.isStopped()):
					# check if done
					stb = int(self.askAndLog('*ESR?'))
					bDone = (stb & 1) > 0
					if not bDone:
						self.thread().msleep(50)
				# if stopped, don't get data
				if self.isStopped():
					self.writeAndLog('*CLS;:INIT:CONT ON;')
					return []
			# get data as float32, convert to numpy array
			sTraceNum = self.getTraceDict(quant)
			sWrite = ':FORM REAL,32;READ:WAV'+sTraceNum+'?'
			self.write(sWrite, bCheckError=False)
			sData = self.read(ignore_termination=True)
			if bWaitTrace and not bAverage:
				self.writeAndLog(':INIT:CONT ON;')
			# strip header to find # of points
			i0 = sData.find('#')
			nDig = int(sData[i0+1])
			nByte = int(sData[i0+2:i0+2+nDig])
			nPts = nByte/4
			# get data to numpy array
			vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)],
											dtype='>f', count=nPts)
			# get start/stop frequencies
			#duration = self.readValueFromOther('Measurement Time IQ')
			sampleFreq = self.readValueFromOther('Sample Rate CW')
            # sweepType = self.readValueFromOther('Sweep type')
            # # if log scale, take log of start/stop frequencies
            # if sweepType == 'Log':
                # startFreq = np.log10(startFreq)
                # stopFreq = np.log10(stopFreq)
            # check if return trace or trace average
			# create a trace dict
			if self.getValue('Trace type CW') == 'unprocessed IQ trace data (V)':
				#the trace is complex.  I values are even indices while Q values are odd indices.
				realData = vData[0:nPts:2]
				imagData = vData[1:nPts:2]
				cData = realData +1j*imagData
				samplePeriod = (2/sampleFreq)
			else:
				#the trace is a simple vector.
				cData = vData +1j*np.zeros(vData.shape)
				samplePeriod = (1/sampleFreq)
			
			value = InstrumentQuantity.getTraceDict(cData, t0=0.0, dt=samplePeriod)
			
		elif quant.name in ('Signal - CS'):
			# if not in continous mode, trig from computer
			bWaitTrace = self.getValue('Wait for new trace')
			bAverage = self.getValue('Average CS')
			# wait for trace, either in averaging or normal mode
			if bAverage:
				# clear averages
				self.writeAndLog(':SPEC:AVER:CLE;')
				self.writeAndLog(':ABOR;:INIT:CONT OFF;:INIT:IMM;*OPC')
				# wait some time before first check
				self.thread().msleep(30)
				bDone = False
				while (not bDone) and (not self.isStopped()):
					# check if done
					stb = int(self.askAndLog('*ESR?'))
					bDone = (stb & 1) > 0
					if not bDone:
						self.thread().msleep(50)
				# if stopped, don't get data
				if self.isStopped():
					self.writeAndLog('*CLS;:INIT:CONT ON;')
					return []
			# get data as float32, convert to numpy array
			sTraceNum = self.getTraceDict(quant)
			sWrite = ':FORM REAL,32;READ:SPEC'+sTraceNum+'?'
			self.write(sWrite, bCheckError=False)
			sData = self.read(ignore_termination=True)
			if bWaitTrace and not bAverage:
				self.writeAndLog(':INIT:CONT ON;')
			# strip header to find # of points
			i0 = sData.find('#')
			nDig = int(sData[i0+1])
			nByte = int(sData[i0+2:i0+2+nDig])
			nPts = nByte/4
			# get data to numpy array
			vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)],
											dtype='>f', count=nPts)
			# get start/stop frequencies
			#duration = self.readValueFromOther('Measurement Time IQ')
			centerFreq = self.getValue('Center frequency CS')
			span = self.getValue('Span CS')
			startFreq = centerFreq - span/2
			stopFreq = centerFreq + span/2
            # sweepType = self.readValueFromOther('Sweep type')
            # # if log scale, take log of start/stop frequencies
            # if sweepType == 'Log':
                # startFreq = np.log10(startFreq)
                # stopFreq = np.log10(stopFreq)
            # check if return trace or trace average
			# create a trace dict
			if self.getValue('Trace type CS') in ('unprocessed IQ trace data (V)', 'processed I/Q trace vs. time'):
				#the trace is complex.  I values are even indices while Q values are odd indices.
				realData = vData[0:nPts:2]
				imagData = vData[1:nPts:2]
				cData = realData +1j*imagData
				nPts_new = nPts/2
			else:
				#the trace is a simple vector.
				cData = vData +1j*np.zeros(vData.shape)
				nPts_new = nPts
				
			if self.getValue('Trace type CS') in ('log-mag vs. Freq.', 'avged log-mag vs. Freq.', 'phase of FFT vs. Freq.', 'linear spectrum (V RMS)', 'avged linear spectrum (V RMS)'):
				startValue=startFreq
				delta=(stopFreq-startFreq)/(nPts_new-1)
			else:
				startValue=0
				delta = 1
				
				
			value = InstrumentQuantity.getTraceDict(cData, t0=startValue, 
																		  dt=delta)
			
		elif quant.name in ('Wait for new trace',):
			# do nothing, return local value
			value = quant.getValue()
		elif quant.name in ('Trace type CS', 'Trace type CW', 'Measurement Type'):
			value = self.getValue(quant.name)
		else:
			# for all other cases, call VISA driver
			value = VISA_Driver.performGetValue(self, quant, options)
		return value
 def performGetValue(self, quant, options ={}):
     couplingModes = ['Coupling CFRQAB','Coupling CFRQAC','Coupling RFLVAB','Coupling RFLVAC']
     self.log('Quant.name is: '+quant.name+' Get value')
     if quant.name[-1] == ')':
         #quant is source specific
         source = quant.name[-2]
         #Use sourceCmd before every source specific command
         sourceCmd = 'SOURCE '+source+'; :'
     if quant.name == 'Combiner mode':
         reply = VISA_Driver.askAndLog(self,'CMODE?')
         #return syntax is ':CMODE <*>'
         reply = reply.split(' ')[1]
         combos = ['A','B','C','AB','BC','AC','ABC','OFF']
         for comboValue in combos:
             #Need set so we get AB == BA, etc
             if set(reply) == set(comboValue):
                 return comboValue
         self.log('Coupling mode not found: '+reply)
     elif quant.name == 'Impedance':
         reply = VISA_Driver.askAndLog(self,'IMPEDANCE?')
         if reply.split(' ')[1] == 'Z50R':
             return '50 Ohms'
         else:
             return '75 Ohms'
     elif quant.name in couplingModes:
         mode = quant.name.split(' ')[1]
         reply = VISA_Driver.askAndLog(self,'COUPLING?')
         #Reply syntax: COUPLING:MODE CFRQAB,RFLVAC,...
         #get rid of 'COUPLING:MODE'
         reply = reply.split(' ')[1]
         #puts 2nd part into list of enabled modes
         reply = reply.split(',')
         if mode in reply:
             return True
         else:
             return False
     elif quant.name.startswith('Coupling'):
         cmd = quant.name.split(' ')
         """
         cmd[0] = 'coupling'
         cmd[1] = one of the coupling modes
         cmd[2] = MODE, HARM, SUBHARM, or OFFSET
         """
         cmdStr = 'COUPLING: '+cmd[1]+'?'
         reply = VISA_Driver.askAndLog(self,cmdStr)
         #Reply syntax: :COUPLING:CFRQAC:MODE SUBHARM;HARM 2;SUBHARM 6;OFFSET 2 
         replist = reply.split(';')
         if cmd[2] == 'MODE':
             #Split MODE and SUBHARM in reply[0], return SUBHARM
             return replist[0].split(' ')[1]
         elif cmd[2] == 'HARM':
             #split HARM and value in reply[1]
             return replist[1].split(' ')[1]
         elif cmd[2] == 'SUBHARM':
             #split SUBHARM and value in reply[2]
             return replist[2].split(' ')[1]
         elif cmd[2] == 'OFFSET':
             #Split offset and value in reply[3]
             return replist[3].split(' ')[1]
         else:
             self.log('Received invalid response: '+reply)
     elif quant.name.startswith('Carrier Frequency'):
         reply = VISA_Driver.askAndLog(self,sourceCmd+'CFRQ?')
         #reply syntax: :CFRQ:VALUE 1000000000.0;INC 25000.0
         reply = reply.split(';')[0]
         reply = reply.split(' ')[1]
         self.log('Carrier frequency: '+reply)
         return float(reply)
     elif quant.name.startswith('RF'):
         cmd = quant.name.split(' ')
         #cmd[1] = Output, Level, or Type
         #Reply syntax: :RFLV:UNITS DBM;TYPE PD;VALUE −103.5;INC 2.0;ON
         reply = VISA_Driver.askAndLog(self,sourceCmd+'RFLV?')
         reply = reply.split(';')
         if cmd[1] == 'Output':
             if reply[3] == 'ON':
                 return True
             else:
                 return False
         elif cmd[1] == 'Level':
             return reply[2].split(' ')[1]
         elif cmd[1] == 'Type':
             return reply[1].split(' ')[1]
         else:
             self.log('Quant not recognised: '+quant.name)
     elif quant.name.startswith('Modulation Control'):
         reply = VISA_Driver.askAndLog(self,sourceCmd+'MOD?')
         if reply.split(':')[-1] == 'ON':
             return True
         else:
             return False
     elif quant.name.startswith('Modulation mode'):
         reply = VISA_Driver.askAndLog(self,sourceCmd+'MODE?')
         #Reply syntax: :MODE AM,FM,PULSE
         #Remove ':MODE' component of reply
         reply = reply.split(' ')[1]
         #Separate activated modes into list
         reply = reply.split(',')
         if 'AM' in reply:
             if 'FM' in reply:
                 return 'AM & FM'
             elif 'PM' in reply:
                 return 'AM & PM'
             else:
                 return 'AM'
         elif 'FM' in reply:
             return 'FM'
         elif 'PM' in reply:
             return 'PM'
         elif 'FSK2L' in reply:
             return 'FSK2L'
         elif 'FSK4L' in reply:
             return 'FSK4L'
         else:
             self.log('No modulation mode active')
     elif quant.name[:2] in ['FM','PM','AM']:
         cmd = quant.name.split(' ')
         """
         cmd[0] = FM, FM1, FM2, PM, PM1, PM2, AM, AM1, or AM2
         cmd[1] = Status, Deviation, Source, Modulation, Waveform, Phase, (Depth for AM)
         """
         if cmd[1] == 'Status':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+'?')
             #Reply syntax: :FM1:DEVN 1000.0;INT;OFF;INC 1000.0
             reply = reply.split(';')
             if reply[2] == 'OFF':
                 return False
             else:
                 return True
         elif cmd[1] == 'Deviation':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+'?')
             #Reply syntax: :FM1:DEVN 25000.0;INT;ON;INC 1000.0
             reply = reply.split(';')
             return reply[0].split(' ')[1]
         elif cmd[1] == 'Source':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+'?')
             #Reply syntax: :FM1:DEVN 25000.0;INT;ON;INC 1000.0
             reply = reply.split(';')
             comboDict = {'INT':'Internal','EXTAC':'External AC','EXTALC':'External ALC','EXTDC':'External DC'}
             return comboDict[reply[1]]
         elif cmd[1] == 'Modulation':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+':MODF?')
             #Reply syntax: :FM1:MODF:VALUE 5750.00;SIN;INC 1000.00
             reply = reply.split(';')[0]
             return reply.split(' ')[1]
         elif cmd[1] == 'Waveform':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+':MODF?')
             #Reply syntax: :FM1:MODF:VALUE 5750.00;SIN;INC 1000.00
             return reply.split(';')[1]
         elif cmd[1] == 'Phase':
             return 0 #No way to get this setting
         elif cmd[1] == 'Depth':
             reply = VISA_Driver.askAndLog(self,sourceCmd+cmd[0]+'?')
             #Reply syntax: :FM1:DEVN 25000.0;INT;ON;INC 1000.0
             reply = reply.split(';')
             return reply[0].split(' ')[1]
         else:
             self.log('Quant command not recognised: '+quant.name)
     elif quant.name.startswith('Pulse Modulation'):
         reply = VISA_Driver.askAndLog(self,sourceCmd+'PULSE?')
         #Reply syntax: :PULSE:ON/OFF
         #Remove ':MODE' component of reply
         if reply.endswith('ON'):
             return True
         else:
             return False
     else:
         self.log('quant.name not tringgered: '+quant.name)
         return VISA_Driver.performGetValue(self,quant,options)
Example #57
0
 def performGetValue(self, quant, options={}):
     self.clearMessages()
     self.log('performGetValue of: '+quant.name)
     """Perform the Get Value instrument operation"""
     # check type of quantity
     # check quantity
     if quant.name == 'Magnetic Field':
         hStatus = self.readValueFromOther('Heater status')
         self.wait(delayTime)
         if hStatus:
             #If heater is on, get source field
             reply = self.askAndLog('R7')
             self.wait(delayTime)
         else:
             #If heater is off, get persistent field
             reply = self.askAndLog('R18')
             self.wait(delayTime)
         return float(reply[1:])
     if quant.name == 'Current':
         hStatus = self.readValueFromOther('Heater status')
         self.wait(delayTime)
         if hStatus:
             #If heater is on, get source current
             reply = self.askAndLog('R0')
             self.wait(delayTime)
         else:
             #If heater is off, get persistent current
             reply = self.askAndLog('R16')
             self.wait(delayTime)
         value = float(reply[1:])
     elif quant.name == 'Heater status':
         reply = self.askAndLog('X')
         self.wait(delayTime)
         if not(reply.startswith('X')):
             self.log('Mismatched response to X: '+reply)
             return 0
         #Reply is of the form XmnAnCnHnMmnPmn
         #So, find index of the 'H' and return the value that is one after it
         index = reply.index('H')+1
         self.log('In performGetValue - Heater status')
         self.log('Reply is: '+reply)
         self.log('Index +1 is: '+str(index))
         self.log('Length of reply is: '+str(len(reply)))
         self.log('Status value is: '+str(reply[index]))
         status = int(reply[index])
         if status == 1:
             self.log('Returning True, Heater is on')
             return True
         else:
             self.log('Returning fALSE, Heater is off')
             return False
     elif quant.name == 'Current or Field':
         reply = self.askAndLog('X')
         self.wait(delayTime)
         if not(reply.startswith('X')):
             self.log('Mismatched response to X: '+reply)
             return 0
         index = reply.index('M')+1
         status = int(reply[index])
         if status == 0 or status == 4:
             return 'Current'
         elif status == 1 or status == 3:
             return 'Magnetic field'
     elif quant.name == 'Source Current':
         reply = self.askAndLog('R0')
         self.wait(delayTime)
         if not(reply.startswith('R')):
             self.log('Mismatched response to R0: '+reply)
             return 0
         # strip first character
         reply = reply[1:]
         # convert to float
         value = float(reply)
     elif quant.name == 'Source Magnetic Field':
         reply = self.askAndLog('R7')
         self.wait(delayTime)
         if not(reply.startswith('R')):
             self.log('Mismatched response to R7: '+reply)
             return 0
         # strip first character
         reply = reply[1:]
         # convert to float
         value = float(reply)
     else:
         # for all other cases, call VISA driver
         value = VISA_Driver.performGetValue(self, quant, options)
     return value
    def performGetValue(self, quant, options={}):
        """Perform the Get Value instrument operation"""
        # check type of quantity
#        if quant.name in ('Zero-span mode',):
        if quant.name in ('Range type',):
            # check if span is zero
            span = self.readValueFromOther('Span')
            if span == 0:
                value = 'Zero-span mode'
            else:
                # return old value if not in zero span
                value = quant.getValueString()
                if value == 'Zero-span mode':
                    value = 'Center - Span'
        elif quant.name in ('Signal', 'Signal - Zero span'):
            # if not in continous mode, trig from computer
            bWaitTrace = self.getValue('Wait for new trace')
            bAverage = self.getValue('Average')
            # wait for trace, either in averaging or normal mode
            if bWaitTrace:
                if bAverage:
                    # clear averages
                    self.writeAndLog(':SENS:AVER:CLE;')
                self.writeAndLog(':ABOR;:INIT:CONT OFF;:INIT:IMM;*OPC')
                # wait some time before first check
                self.thread().msleep(30)
                bDone = False
                while (not bDone) and (not self.isStopped()):
                    # check if done
                    stb = int(self.askAndLog('*ESR?'))
                    bDone = (stb & 1) > 0
                    if not bDone:
                        self.thread().msleep(50)
                # if stopped, don't get data
                if self.isStopped():
                    self.writeAndLog('*CLS;:INIT:CONT ON;')
                    return []
            # get data as float32, convert to numpy array
            self.write(':FORM REAL,32;TRAC:DATA? TRACE1', bCheckError=False)
            sData = self.read(ignore_termination=True)
            if bWaitTrace and not bAverage:
                self.writeAndLog(':INIT:CONT ON;')
            # strip header to find # of points
            i0 = sData.find('#')
            nDig = int(sData[i0+1])
            nByte = int(sData[i0+2:i0+2+nDig])
            nPts = nByte/4
            # get data to numpy array
            vData = np.frombuffer(sData[(i0+2+nDig):(i0+2+nDig+nByte)], 
                                  dtype='>f', count=nPts)
            # get start/stop frequencies
            startFreq = self.readValueFromOther('Start frequency')
            stopFreq = self.readValueFromOther('Stop frequency')
            sweepType = self.readValueFromOther('Sweep type')
            # if log scale, take log of start/stop frequencies
            if sweepType == 'Log':
                startFreq = np.log10(startFreq)
                stopFreq = np.log10(stopFreq)
            # check if return trace or trace average
            if quant.name == 'Signal - Zero span':
                # return average
                value = np.average(vData)
            else:
                # create a trace dict
                value = InstrumentQuantity.getTraceDict(vData, t0=startFreq,
                                               dt=(stopFreq-startFreq)/(nPts-1))
        elif quant.name in ('Wait for new trace',):
            # do nothing, return local value
            value = quant.getValue()
        else:
            # for all other cases, call VISA driver
            value = VISA_Driver.performGetValue(self, quant, options)
        return value