def getPressures(self, dev):
     """Read sensor data."""
     # Iterate through sensors 1 to 6.
     for i in range(1, 7):
         # The serial command 'PRx' tells the device that we are
         # talking about sensor x.
         yield self.dev.write("PR{0}\r\n".format(i))
         # Give the device time to receive and process the request.
         yield sleep(0.1)
         # The device responds with an acknowledge, discard it.
         yield self.dev.read()
         yield sleep(0.1)
         # Write the 'enquire' code to the serial bus. This tells the
         # device that we want a reading.
         yield self.dev.write("\x05\r\n")
         yield sleep(0.1)
         response = yield self.dev.read()
         # The reading is formatted in the following way:
         # 'status,measurement.'
         # Separate the status code from the measurement.
         response = response.rsplit(',')
         pressure = response[1]
         status = response[0]
         self.measurements[i - 1] = float(response[1]) * mbar
         self.statusCodes[i - 1] = response[0]
 def getResistances(self, c):
     self.dev = self.selectedDevice(c)
     resistances = []
     for i in range(0, 8):
         self.dev.write_line("inp1;mux%s;ran%s;exc%s" %
                             (str(i), self.range, self.excitation))
         yield sleep(.1)
         self.dev.write_line("res?")
         yield sleep(.1)
         reading = yield self.dev.read_line()
         reading = reading.rstrip("\r\n")
         reading = float(reading) * units.Ohm
         resistances.append(reading)
     returnValue(resistances)
    def getInfo(self, ctx):
        self.dev = self.selectedDevice(ctx)
        yield self.dev.write_line('?')
        yield sleep(0.05)
        reading = yield self.dev.read_line()

        returnValue(reading)
Example #4
0
    def getResistances(self, ctx):
        readings = []
        self.dev = self.selectedDevice(ctx)

        for i in range(2):
            yield self.dev.write_line(str(i + 1))
            yield sleep(0.2)
            reading = yield self.dev.read_line()

            readings.append(reading)
            readings[i] = reading.strip()
            if (reading == "OL\r\n"):
                readings[i] = np.nan
            elif len(reading) is 0:
                readings[i] = np.nan
            else:
                readings[i] = reading.strip()
        try:
            readings = [
                float(readings[0]) * units.Ohm,
                float(readings[1]) * units.Ohm
            ]
        except:
            traceback.print_exc()
        returnValue(readings)
 def identify(self, c):
     self.dev = self.selectedDevice(c)
     yield self.dev.write_line("*IDN?")
     yield sleep(0.5)
     reading = yield self.dev.read_line()
     reading = yield str(reading.rstrip("\r\n"))
     returnValue(reading)
Example #6
0
 def initialize(self):
     # Create a new packet.
     p = self._packet()
     # Write to the packet.
     # Run the system preset command.
     p.write('SYST:PRES')
     yield p.send()
     yield sleep(0.1)
 def getReading(self, ctx):
     self.dev = self.selectedDevice(ctx)
     yield self.dev.write_line("1")
     yield sleep(0.1)
     reading = yield self.dev.read_line()
     reading = reading.strip()
     reading = float(reading)
     reading = reading * units.V
     returnValue(reading)
    def getTemperatures(self, c):

        self.dev = self.selectedDevice(c)
        temperatures = []
        for i in range(0, 8):

            # GET RESISTANCE FROM BRIDGE
            self.dev.write_line("inp1;mux%s;ran%s;exc%s" %
                                (str(i), self.range, self.excitation))
            yield sleep(.1)
            self.dev.write_line("res?")
            yield sleep(.1)
            reading = yield self.dev.read_line()
            reading = reading.rstrip("\r\n")
            print reading
            reading = float(reading)

            # GET CALIBRATION FROM FILE
            cal_array = []
            filename = self.calibrations[i]
            if filename != 'NONE':
                file = open(('avs47_calibrations/' + filename), "r")
                index = 1
                exponent = 0.0
                result = 0.0

                for line in file:
                    cal_array.insert(0, float(line.strip('\n')))

                # CONVERT RESISTANCE TO TEMPERATURE WITH CALIBRATION
                exponent += cal_array.pop()
                while (len(cal_array) != 0):
                    exponent += cal_array.pop() * (log10(reading)**index)
                    index += 1

                result = 10**exponent
                temperatures.append(result)

            else:
                temperatures.append(0.0)

        print temperatures
        returnValue(True)
Example #9
0
 def sweep_points(self, sweep_pts=None):
     """
     Set or get number of points in a sweep. The number will be
     automatically coarsen to 3, 11, 21, 26, 51, 101, 201, 401, 801,
     or 1601 by the network analyzer.
     """
     if sweep_pts is not None:
         yield self.write('POIN%i' %sweep_pts)
         t = yield self.query('SWET?')
         yield sleep(2 * float(t)) # Be sure to wait for two sweep
                                   # times as required in the docs.
     resp = yield self.query('POIN?')
     sweep_pts = int(float(resp))
     returnValue(sweep_pts)
Example #10
0
    def get_data(self):
        """Get the active trace(s) from the network analyzer."""
        # Get list of traces in form "name, S21, name, S32,...".
        formats_s_params = yield self.query('CALC:PAR:CAT?')
        formats_s_params = formats_s_params.strip('"').split(',')

        # yield self.write('FORM REAL,64') # Do we need to add ',64'?
        yield self.write('FORM ASC,0')

        avg_mode = yield self.average_mode()
        if avg_mode:
            avgCount = yield self.average_points()
            yield self.restart_averaging()
            yield self.write('SENS:SWE:GRO:COUN %i' %avgCount)
            yield self.write('ABORT;SENS:SWE:MODE GRO')
        else:
            # Stop the current sweep and immediately send a trigger.
            yield self.write('ABORT;SENS:SWE:MODE SING')

        # Wait for the measurement to finish.
        # yield self.query('*OPC?', timeout=24*units.h) <-- old way, blocked GPIB chain entirely
        measurement_finished = False 
        yield self.write('*OPC') # will trigger bit in ESR when measurement finished
        while measurement_finished == False:
            yield sleep(0.05) # polling rate = 20Hz 
            opc_bit = yield self.query('*ESR?') # poll ESR for measurement completion
            opc_bit = int(opc_bit) & 0x1
            if (opc_bit == 1):
                measurement_finished = True
        
        # Pull the data.
        data = ()
        pair = ()
        unit_multipliers = {'R': 1, 'I': 1,
                'M': units.dB, 'P': units.deg}
        # The data will come in with a header in the form
        # '#[single char][number of data points][data]'.
        for idx, meas in enumerate(formats_s_params[::2]):
            yield self.write('CALC:PAR:SEL "%s"' %meas)
            data_string = yield self.query('CALC:DATA? FDATA')
            d = np.array(data_string.split(','), dtype=float)
            pair += (d * unit_multipliers[meas[0]]),
            if idx % 2:
                data += (pair),
                pair = ()
        returnValue(data)
Example #11
0
 def getRate(self, dev):
     """Get flow rate."""
     # The string '@U?V' asks the device for the current reading
     # The '\r' at the end is the carriage return letting the device
     # know that it was the end of the command.
     #print("getting rate")
     yield dev.write_line("@U?V\r")
     yield sleep(0.5)
     reading = yield dev.read_line()
     # Instrument randomly decides not to return, here's a hack.
     if not reading:
         returnValue(None)
     else:
         # Get the last number in the string.
         reading.rsplit(None, 1)[-1]
         # Strip the 'L' off the string.
         reading = float(reading.lstrip("L"))
         # Convert the reading to the correct units.
         gal = units.WithUnit(1, 'gal')
         output = reading * gal / units.min
         returnValue(output)
Example #12
0
    def get_data(self):
        """Get the active trace(s) from the network analyzer."""
        avg_mode = yield self.average_mode()
        if avg_mode:
            yield self.write('TRIG:AVER 1')
        
        # Start the measurement.
        yield self.write('INIT1:CONT 0')
        yield self.write('ABOR')
        yield self.write('INIT1')

        # Wait for the measurement to finish.
        sweep_time = yield self.get_sweep_time()
        yield sleep(sweep_time)

        # Wait for the measurement to finish.
        yield self.query('*OPC?', timeout=24*units.h)

        # Pull the data.
        yield self.write('FORM:DATA ASC')
        data = ()
        pair = ()
        unit_multipliers = {'REAL': 1, 'IMAG': 1,
                 'MLOG': units.dB, 'PHAS': units.deg}
        num_params = yield self.query('CALC1:PAR:COUNT?')
        for k in range(int(num_params)):
            yield self.write('CALC1:PAR%d:SEL' %(k + 1))     
            format = (yield self.query('CALC1:FORM?'))
            data_string = (yield self.query('CALC1:DATA:FDAT?'))
            d = np.array(data_string.split(','), dtype=float)
            # Select only every other element.
            d = d[::2]
            pair += (d * unit_multipliers[format]),
            if k % 2:
                data += (pair),
                pair = ()
        returnValue(data)
Example #13
0
 def _rw_line(self, code):
     """Write data to the device."""
     yield self.server.write_line(code, context=self.ctx)
     yield sleep(0.1)
     ans = yield self.server.read(context=self.ctx)
     returnValue(ans)