Beispiel #1
0
    def set_device(self, dut=None, playback_filename=None):
        """
        Detach any currenly attached device and stop playback then
        optionally attach to a new device or playback file.

        :param dut: a :class:`pyrf.thinkrf.WSA` or None
        :param playback_filename: recorded VRT data filename or None
        :param playback_scheduler: function to schedule each playback capture
        """
        if self._playback_file:
            self._playback_file.close()
            self._playback_file = None

        if self._dut:
            self._dut.disconnect()

        if playback_filename:
            self._playback_file = open(playback_filename, 'rb')
            self._playback_started = False
            self._playback_context = {}
            vrt_packet = self._playback_vrt(auto_rewind=False)
            state_json = vrt_packet.fields['speca']
            # support old playback files
            if state_json['device_identifier'] == 'unknown':
                state_json['device_identifier'] = 'ThinkRF,WSA5000 v3,0,0'
            dut = Playback(state_json['device_class'],
                           state_json['device_identifier'])
            self._sweep_device = SweepDevice(dut)
            self._capture_device = CaptureDevice(dut)
        elif dut:
            dut.reset()
            self._sweep_device = SweepDevice(dut, self.process_sweep)
            self._capture_device = CaptureDevice(dut, self.process_capture)
            state_json = dict(dut.properties.SPECA_DEFAULTS,
                              device_identifier=dut.device_id)

        self._dut = dut
        if not dut:
            return

        self.device_change.emit(dut)
        self._apply_complete_settings(state_json, bool(self._playback_file))
        self.start_capture()
    def get_npoints(self):
        '''
        get the number of points by calling capture function and filtering 
        to start/stop frequencies, if required
        '''

        if (self._capture_mode == 'BLOCK'):
            fstart, fstop, spectra = capture_spectrum(self.dut, self.rbw(),
                                                      self.average())

            flist = np.linspace(fstart, fstop, len(spectra))

            filteredFreq, filteredSpectra = self.filter_span(flist, spectra)

            return len(filteredSpectra)

        if (self._capture_mode == 'SWEEP'):

            #TODO : calling center frequency function (or any function that returns numeric data) after sweepdev creation gives error, find a workaround
            scan_startf = self.f_start()
            scan_stopf = self.f_stop()
            atten = self.attenuation()
            rbw = self.rbw()
            mode = self.rfe_mode()
            avg = self._average()

            sweepdev = SweepDevice(self.dut)

            fstart, fstop, spectra = sweepdev.capture_power_spectrum(
                scan_startf,
                scan_stopf,
                rbw, {'attenuator': atten},
                mode=mode,
                niter=1,
                average=avg)

            self._freqlist = np.linspace(fstart, fstop, len(spectra))
            self._spectra = spectra

            return (len(spectra))
Beispiel #3
0
    fp = open("mcfail.log", "a")

# connect to siggen
sg = N5183("10.126.110.19")
sg.freq(2400e6)
sg.amplitude(pin)
sg.output(1)

# connect to wsa
dut = WSA()
dut.connect(sys.argv[1])
dut.scpiset("*RST")
dut.flush()

# create sweep device
sd = SweepDevice(dut)

# test for a long time
t = 0
while t < numtrials:

    # choose random fstart
    req_fstart = int(random.random() * 8e9)

    # choose random fstop
    req_fstop = req_fstart + int(random.random() * (8e9 - req_fstart))

    # choose random fin between fstart and fstop
    fin = req_fstart + int(random.random() * (req_fstop - req_fstart))

    # choose a random rbw between 3kHz and 500 kHz
Beispiel #4
0
    def get_npoints(self):
        '''
        Configs the sweep and collects the data. Returns length of data for
        generating the setpoints.
        '''             
        fstart = self.f_start()
        fstop = self.f_stop()
        rbw = self.rbw()
        device_settings = { 'attenuator' : self.attenuation() }
        mode = self.rfe_mode()
        average = self.average()

        self.dut.reset()
        self.dut.psfm_gain(self._gain)
        self.dut.spp(1024)
        self.dut.ppb(4)
        self.dut.pll_reference('EXT')

        try:
            sweepdev = SweepDevice(self.dut)
        except TypeError:
            self.dut.abort()
            self.dut.flush()
            self.dut.disconnect()

            self.dut.connect(self.addr)
            self.dut.reset()
            self.dut.psfm_gain(self._gain)
            self.dut.spp(1024)
            self.dut.ppb(4)
            self.dut.pll_reference('EXT')
        finally:
            try:
                sweepdev = SweepDevice(self.dut)

            except TypeError:
                self.dut.connect(self.addr)
                self.dut.abort()
                self.dut.flush()

                self.dut.reset()
                self.dut.psfm_gain(self._gain)
                self.dut.spp(1024)
                self.dut.ppb(4)
                self.dut.pll_reference('EXT')
                sweepdev = SweepDevice(self.dut)

        sweepdev.real_device.flush_captures()
        fstart, fstop, spectrum = sweepdev.capture_power_spectrum(fstart=fstart,
                               fstop=fstop,
                               rbw=rbw,
                               device_settings=device_settings,
                               mode=mode,
                               average = average)
        
        self._acquired_data = dict({'fstart':fstart,
                                'fstop' : fstop,
                                'spectrum' : spectrum,
                                'npts' : len(spectrum) })
        self.f_start(fstart)
        self.f_stop(fstop)

        self.dut.sweep_stop()
        self.dut.abort()
        self.dut.flush_captures()

        return len(spectrum)
Beispiel #5
0
def GetReading(IP,Frequency,Name,degrees):
    #read command line for IP (WSA5000 hostname: thinkrf.uct.ac.za)
    try:

        global fail
        dut.connect(IP)
        dut.reset()
                 
        freq=float(Frequency)*1000000000
        
        #we need to set the sweep range (this is approximately the default set by pyRF RTSA)
        start=freq-62.5e6
        stop=freq+62.5e6
        bw=976.562e3

        dut.request_read_perm()
        sd = SweepDevice(dut)

        fstart, fstop, bins = sd.capture_power_spectrum(start, stop, bw,
            {'attenuator':0})

        #Checks the date to add to the file name
        i = datetime.now()

        #Sets the text file name as "FileName_Date"
        text = Name+'_[deg_('+degrees+')]'+i.strftime('_%Y_%m_%d')+'.csv'
        f = open(text, 'a')
        
        global success
        print success
        
        peak=-200
        for i in bins:
            if i>peak:
                peak=i

        print "Peak:",peak,"dBm"
        f.write(str(peak)+',\n')

        print "Saved to file:",text
        
        #Check to see whether the file name has changed to that
        #we can reset the counter
        global counter
        global newName
        if newName == Name:
            counter = counter+int(degrees)
            print "Degree:",counter

        else:
            counter = 0
            print "Degree:",counter
            newName=Name

        print
        f.close()
        fail = 0

    #if error, throw exception to user
    except:
        global errorMessage
        print errorMessage
        fail = 1
        print
Beispiel #6
0
# get device's IP and connect
if len(sys.argv) > 1:
    ip = sys.argv[1]
else:
    ip, ok = QtGui.QInputDialog.getText(win, 'Open Device',
                                        'Enter a hostname or IP address:')
dut.connect(ip)

# initialize RTSA configurations
dut.reset()
dut.request_read_perm()
dut.psfm_gain(GAIN)

# setup a sweep device
sweepdev = SweepDevice(dut)

# initialize the plot
win.resize(1000, 600)
win.setWindowTitle("PYRF FFT Plot Example - " + ip)
fft_plot = win.addPlot(title="Power Vs. Frequency")
fft_plot.enableAutoRange('xy', True)
curve = fft_plot.plot(pen='g')
fft_plot.setLabel('bottom', text='Frequency', units='Hz', unitPrefix=None)

# initialize the y-axis of the plot
plot_ymin = -130
plot_ymax = 10
fft_plot.setYRange(plot_ymin, plot_ymax)
fft_plot.setLabel('left', text='Power', units='dBm', unitPrefix=None)
Beispiel #7
0
def start_sweep(v):
    global sd
    sd = SweepDevice(dut, plot_sweep)
    fstart, fstop, spectral_data = sd.capture_power_spectrum(
        START_FREQ, STOP_FREQ, RBW, {'attenuator': 0})
Beispiel #8
0
ATTENUATION = 20
GAIN = 'HIGH'
AVERAGE = 50
DECIMATION = 1  # no decimation

span = STOP_FREQ - START_FREQ
#%%
dut = WSA()
dut.connect('169.254.16.253')

dut.reset()
#dut.request_read_perm()
dut.psfm_gain(GAIN)
#%%
sweepdev = SweepDevice(
    dut
)  ## numeric values start being gibberish after this point, but the spectrum capture works fine
#%%
#avglist = [1,5,10,50,100,500,1000,5000,10000]
#timelist = []
#for avg in avglist:
startT = time()
fstart, fstop, spectra_data = sweepdev.capture_power_spectrum(
    START_FREQ,
    STOP_FREQ,
    RBW, {'attenuator': ATTENUATION},
    mode=RFE_MODE,
    niter=1,
    average=AVERAGE)
freq_range = np.linspace(fstart, fstop, len(spectra_data))
stopT = time()
Beispiel #9
0
def start_sweep(v):
    global sd
    sd = SweepDevice(dut, plot_sweep)
    sd.capture_power_spectrum(0e6, 20000e6, 5e6, {'attenuator': 0})