本文整理匯總了Python中rtlsdr.RtlSdr.set_center_freq方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.set_center_freq方法的具體用法?Python RtlSdr.set_center_freq怎麽用?Python RtlSdr.set_center_freq使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rtlsdr.RtlSdr
的用法示例。
在下文中一共展示了RtlSdr.set_center_freq方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Sampler
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import set_center_freq [as 別名]
class Sampler(QtCore.QObject):
samplerError = QtCore.pyqtSignal(object)
dataAcquired = QtCore.pyqtSignal(object)
def __init__(self, gain, sampRate, freqs, numSamples, parent=None):
super(Sampler, self).__init__(parent)
self.gain = gain
self.sampRate = sampRate
self.freqs = freqs
self.numSamples = numSamples
self.offset = 0
self.sdr = None
self.errorMsg = None
self.WORKING = True
self.BREAK = False
self.MEASURE = False
try:
self.sdr = RtlSdr()
self.sdr.set_manual_gain_enabled(1)
self.sdr.gain = self.gain
self.sdr.sample_rate = self.sampRate
except IOError:
self.WORKING = False
print "Failed to initiate device. Please reconnect."
self.errorMsg = "Failed to initiate device. Please reconnect."
self.samplerError.emit(self.errorMsg)
def sampling(self):
print 'Starting sampler...'
while self.WORKING:
prev = 0
counter = 0
gain = self.gain
numSamples = self.numSamples
self.BREAK = False
self.sdr.gain = gain
start = time.time()
#print self.sdr.get_gain()
for i in range(len(self.freqs)):
if self.BREAK:
break
else:
centerFreq = self.freqs[i]
#print "frequency: " + str(center_freq/1e6) + "MHz"
if centerFreq != prev:
try:
self.sdr.set_center_freq(centerFreq)
except:
self.WORKING = False
print "Device failure while setting center frequency"
self.errorMsg = "Device failure while setting center frequency"
self.samplerError.emit(self.errorMsg)
break
prev = centerFreq
else:
pass
#time.sleep(0.01)
try:
x = self.sdr.read_samples(2048)
data = self.sdr.read_samples(numSamples)
except:
self.WORKING = False
print "Device failure while getting samples"
self.errorMsg = "Device failure while getting samples"
self.samplerError.emit(self.errorMsg)
break
if self.MEASURE:
self.offset = np.mean(data)
counter += 1
self.dataAcquired.emit([i, centerFreq, data])
if self.errorMsg is not None:
self.samplerError.emit(self.errorMsg)
if self.sdr is not None:
self.sdr.close()