def __on_refresh(self, _event): dlg = wx.BusyInfo('Please wait...') try: if self.device.isDevice: sdr = rtlsdr.RtlSdr(self.device.indexRtl) else: sdr = RtlTcp(self.device.server, self.device.port, None) sdr.set_sample_rate(SAMPLE_RATE) sdr.set_center_freq(self.spinFreq.GetValue() * 1e6) sdr.set_gain(self.spinGain.GetValue()) capture = sdr.read_samples(2 ** 21) sdr.close() except IOError as error: if self.device.isDevice: message = error.message else: message = error dlg.Destroy() dlg = wx.MessageDialog(self, 'Capture failed:\n{}'.format(message), 'Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.__plot(capture) dlg.Destroy()
def on_refresh(self, _event): plot = [] dlg = wx.BusyInfo('Please wait...') try: if self.device.isDevice: sdr = rtlsdr.RtlSdr(self.device.index) else: sdr = RtlTcp(self.device.server, self.device.port) sdr.set_sample_rate(SAMPLE_RATE) sdr.set_center_freq(self.spinFreq.GetValue() * 1e6) sdr.set_gain(self.spinGain.GetValue()) capture = sdr.read_samples(2 ** 18) sdr.close() except IOError as error: if self.device.isDevice: message = error.message else: message = error dlg.Destroy() dlg = wx.MessageDialog(self, 'Capture failed:\n{0}'.format(message), 'Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return powers, freqs = matplotlib.mlab.psd(capture, NFFT=1024, Fs=SAMPLE_RATE / 1e6, window=matplotlib.numpy.hamming(1024)) for x, y in itertools.izip(freqs, powers): x = x * SAMPLE_RATE / 2e6 plot.append((x, y)) plot.sort() x, y = numpy.transpose(plot) self.axes.clear() self.band1 = None self.band2 = None self.axes.set_xlabel("Frequency (MHz)") self.axes.set_ylabel('Level (dB)') self.axes.set_yscale('log') self.axes.plot(x, y, linewidth=0.4) self.axes.grid(True) self.draw_limits() dlg.Destroy()
def __on_refresh(self, _event): dlg = wx.BusyInfo('Please wait...') try: if self.device.isDevice: sdr = rtlsdr.RtlSdr(self.device.indexRtl) else: sdr = RtlTcp(self.device.server, self.device.port, None) sdr.set_sample_rate(SAMPLE_RATE) sdr.set_center_freq(self.spinFreq.GetValue() * 1e6) sdr.set_gain(self.spinGain.GetValue()) capture = sdr.read_samples(2**21) sdr.close() except IOError as error: if self.device.isDevice: message = error.message else: message = error dlg.Destroy() dlg = wx.MessageDialog(self, 'Capture failed:\n{}'.format(message), 'Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.__plot(capture) dlg.Destroy()