RuntimeError: LookupError: KeyError: No devices found for ----->Device Address: b200
RuntimeError: LookupError: KeyError: No devices found for ----->Device Address: b200
当我尝试通过 Flask 网络服务器 运行 我的 gnuradio python 程序时遇到此错误。当我将我的 USRP b200 代码行添加到我的原始 "working/healthy" 代码中时,我遇到了这个错误。在这个程序中,我试图通过我的 Flask 网络服务器中的滑块小部件来控制我的代码的变量。
同样,每当我 运行 我的 GnuRadio 软件本身中的任何应用程序时,我使用的 USRP 都可以正常工作。但是当我通过 Flask 尝试它时,它 运行s 一两秒钟然后崩溃。
如有任何帮助,我们将不胜感激。
错误回溯:
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
[top_block_22] __init__: sample_rate: 0
[top_block_22] __init__: amplitude: 0
[top_block_22] __init__: frequency: 0
[top_block_22] __init__: bandwidth: 0
[top_block_22] __init__: USRPsamp_rate: 0
[top_block_22] __init__: gain: 0
[top_block_22] __init__: center_frequency: 0
-- Detected Device: B200mini
-- Operating over USB 3.
-- Initialize CODEC control...
-- Initialize Radio control...
-- Performing register loopback test... pass
-- Performing CODEC loopback test... pass
-- Setting master clock rate selection to 'automatic'.
-- Asking for clock rate 16.000000 MHz...
-- Actually got clock rate 16.000000 MHz.
-- Performing timer loopback test... pass
gr::log :INFO: audio source - Audio sink arch: alsa
UHD Warning:
The hardware does not support the requested TX sample rate:
Target sample rate: 0.000000 MSps
Actual sample rate: 0.031250 MSps
-- Asking for clock rate 32.000000 MHz...
-- Actually got clock rate 32.000000 MHz.
-- Performing timer loopback test... pass
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU * Serving Flask app "app" (lazy loading)
U * Environment: production
UU WARNING: This is a development server. Do not use it in a production deployment.
UU Use a production WSGI server instead.
UU * Debug mode: on
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
UUUU * Restarting with stat
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUlinux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU[top_block_22] __init__: sample_rate: 0
[top_block_22] __init__: amplitude: 0
[top_block_22] __init__: frequency: 0
[top_block_22] __init__: bandwidth: 0
[top_block_22] __init__: USRPsamp_rate: 0
[top_block_22] __init__: gain: 0
[top_block_22] __init__: center_frequency: 0
Traceback (most recent call last):
File "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py", line 175, in <module>
tb = top_block_22(0, 0, 0, 0, 0, 0, 0)
File "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py", line 48, in __init__
channels=range(1),
File "/usr/lib/python2.7/dist-packages/gnuradio/uhd/__init__.py", line 122, in constructor_interceptor
return old_constructor(*args)
File "/usr/lib/python2.7/dist-packages/gnuradio/uhd/uhd_swig.py", line 3012, in make
return _uhd_swig.usrp_sink_make(*args)
RuntimeError: LookupError: KeyError: No devices found for ----->
Device Address:
b200:
[Finished in 85.7s with exit code 1]
[shell_cmd: python -u "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py"]
[dir: /home/fit-pc/my_flask_app/virtualenv/Slider]
[path: /home/fit-pc/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
app.py代码:
from __future__ import print_function
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from gnuradio import uhd
import time
class top_block_22(gr.top_block): # PEP8: CamelCaseName for classes
def __init__(self, sample_rate=0, amplitude=0, frequency=0, bandwidth=0, gain=0, center_frequency=0, USRPsamp_rate=0):
gr.top_block.__init__(self, "Top Block 22")
##################################################
# Variables
##################################################
self.sample_rate = sample_rate
print('[top_block_22] __init__: sample_rate:', self.sample_rate)
self.amplitude = amplitude
print('[top_block_22] __init__: amplitude:', self.amplitude)
self.frequency = frequency
print('[top_block_22] __init__: frequency:', self.frequency)
self.bandwidth = bandwidth
print('[top_block_22] __init__: bandwidth:', self.bandwidth)
self.USRPsamp_rate = USRPsamp_rate
print('[top_block_22] __init__: USRPsamp_rate:', self.USRPsamp_rate)
self.gain = gain
print('[top_block_22] __init__: gain:', self.gain)
self.center_frequency = center_frequency
print('[top_block_22] __init__: center_frequency:', self.center_frequency)
##################################################
# Blocks
##################################################
self.uhd_usrp_sink_0 = uhd.usrp_sink(
",".join(("b200", "")),
uhd.stream_args(
cpu_format="sc16",
channels=range(1),
),
)
# for mute_on, mute_off
#self.old_sample_rate = self.sample_rate
#self.old_ampliture = self.ampliture
#self.old_frequency = self.frequency
#self.old_bandwidth = self.bandwidth
##################################################
# Blocks
##################################################
self.blocks_add_xx = blocks.add_vff(1)
self.audio_sink = audio.sink(32000, '', True)
self.analog_sig_source_x_0 = analog.sig_source_f(sample_rate, analog.GR_COS_WAVE, frequency, amplitude, 0)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, amplitude, -42)
self.uhd_usrp_sink_0.set_samp_rate(USRPsamp_rate)
self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
self.uhd_usrp_sink_0.set_center_freq(center_frequency, 0)
self.uhd_usrp_sink_0.set_gain(gain, 0)
self.uhd_usrp_sink_0.set_bandwidth(bandwidth, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 1))
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
self.connect((self.analog_noise_source_x_0, 0), (self.uhd_usrp_sink_0, 0))
def change_sample_rate(self, value=None):
if value is not None:
self.sample_rate = value
print('[top_block_22] change: sample_rate:', value)
self.analog_sig_source_x_0.set_sampling_freq(value)
def change_amplitude(self, value=None):
if value is not None:
value /= 10000.
self.amplitude = value
print('[top_block_22] change: amplitude:', value)
self.analog_sig_source_x_0.set_amplitude(value)
self.analog_noise_source_x_0.set_amplitude(value)
def change_frequency(self, value=None):
if value is not None:
self.frequency = value
print('[top_block_22] change: frequency:', value)
self.analog_sig_source_x_0.set_frequency(value)
#TODO: change some values
def change_bandwidth(self, value=None):
if value is not None:
self.bandwidth = value
print('[top_block_22] change: bandwidth:', value)
self.uhd_usrp_sink_0.set_bandwidth(value)
def change_gain(self, value=None):
if value is not None:
self.gain = value
print('[top_block_22] change: gain:', value)
self.uhd_usrp_sink_0.set_gain(value)
def change_center_frequency(self, value=None):
if value is not None:
self.center_frequency = value
print('[top_block_22] change: center_frequency:', value)
self.uhd_usrp_sink_0.set_center_freq(value)
def change_USRPsamp_rate(self, value=None):
if value is not None:
self.USRPsamp_rate = value
print('[top_block_22] change: USRPsamp_rate:', value)
self.uhd_usrp_sink_0.set_USRPsamp_rate(value)
def change(self, sample_rate=None, amplitude=None, frequency=None, bandwidth=None, gain=None, center_frequency=None, USRPsamp_rate=None):
#self.change_sample_rate(sample_rate)
#self.change_amplitude(amplitude)
#self.change_frequency(frequency)
#self.change_bandwidth(bandwidth)
#self.change_gain(gain)
#self.change_center_frequency(center_frequency)
#self.change_USRPsamp_rate(center_USRPsamp_rate)
if sample_rate is not None:
self.change_sample_rate(sample_rate)
if amplitude is not None:
self.change_amplitude(amplitude)
if frequency is not None:
self.change_frequency(frequency)
if bandwidth is not None:
self.change_bandwidth(bandwidth)
if gain is not None:
self.change_gain(gain)
if center_frequency is not None:
self.change_center_frequency(center_frequency)
if USRPsamp_rate is not None:
self.change_USRPsamp_rate(USRPsamp_rate)
def turn_off(self):
self.change(0, 0, 0, 0, 0, 0, 0)
#def mute_on(self):
# # remember values
# self.old_sample_rate = self.sample_rate
# self.old_ampliture = self.ampliture
# self.old_frequency = self.frequency
# self.old_ampliture = self.gain
# self.old_center_frequency = self.center_frequency
# self.old_USRPsamp_rate = self.USRPsamp_rate
# # turn off sound
# self.change(0, 0, 0, 0, 0, 0, 0)
#def mute_off(self):
# # set old values
# self.change(self.old_sample_rate, self.old_ampliture, self.old_frequency, self.old_gain, self.old_center_frequency, self.old_USRPsamp_rate)
# -----------------------------------------------------------------------------
from flask import Flask, request, jsonify
app = Flask(__name__)
# start with default values
#tb = top_block_22()
tb = top_block_22(0, 0, 0, 0, 0, 0, 0)
tb.start(True)
@app.route('/')
def index():
return '''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GNURadio Slider Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>
<style>
.slider {
position: absolute;
align:center;
}
.row1 {top:100px;}
.row2 {top:450px;}
.row3 {top:750px;}
.col1 {left:75px;}
.col2 {left:470px;}
.col3 {left:870px;}
.col1 {left:75px;}
</style>
</head>
<body>
<div id="slider1" class='slider row1 col1'></div>
<!-- <p>Sample Rate Slider</p> -->
<div id="slider2" class='slider row1 col2'></div>
<!-- <p>Amplitude Slider2</p> -->
<div id="slider3" class='slider row1 col3'></div>
<!-- <p>Frequency Slider3</p> -->
<div id="slider4" class='slider row2 col1'></div>
<!-- <p>Bandwidth Slider4</p> -->
<div id="slider5" class='slider row2 col2'></div>
<!-- <p>Gain Slider5</p> -->
<div id="slider6" class='slider row2 col3'></div>
<!-- <p>Center Frequency Slider6</p> -->
<div id="slider7" class='slider row3 col1'></div>
<!-- <p>USRP Sample Rate Slider7</p> -->
<button id="turn_off_button">TURN OFF</button>
<script>
// create sliders
$("#slider1").roundSlider({
//sliderType: "min-range",
radius: 150,
min: 0,
max: 1000000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide1_val: event.value}); }
change: function(event) { $.getJSON('/set_sample_rate/' + event.value); }
});
$("#slider2").roundSlider({
//sliderType: "min-range",
radius: 150,
min: 0,
max: 1000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide2_val: event.value}); }
change: function(event) { $.getJSON('/set_amplitude/' + event.value); }
});
$("#slider3").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide3_val: event.value}); }
change: function(event) { $.getJSON('/set_frequency/' + event.value); }
});
$("#slider4").roundSlider({
radius: 150,
min: 0,
max: 10000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide4_val: event.value}); }
change: function(event) { $.getJSON('/set_bandwidth/' + event.value); }
});
$("#slider5").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide5_val: event.value}); }
change: function(event) { $.getJSON('/set_gain/' + event.value); }
});
$("#slider6").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide6_val: event.value}); }
change: function(event) { $.getJSON('/set_center_frequency/' + event.value); }
});
$("#slider7").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide7_val: event.value}); }
change: function(event) { $.getJSON('/set_USRPsamp_rate/' + event.value); }
});
$("#turn_off_button").click(function(){
// set sliders
$("#slider1").data("roundSlider").setValue(0);
$("#slider2").data("roundSlider").setValue(0);
$("#slider3").data("roundSlider").setValue(0);
$("#slider4").data("roundSlider").setValue(0);
$("#slider5").data("roundSlider").setValue(0);
$("#slider6").data("roundSlider").setValue(0);
$("#slider7").data("roundSlider").setValue(0);
// send to server
$.getJSON('/valueofslider', {
slide1_val: 0,
slide2_val: 0,
slide3_val: 0,
slide4_val: 0,
slide5_val: 0,
slide6_val: 0,
slide7_val: 0,
});
});
</script>
</body>
</html>'''
@app.route('/off')
def off():
"""Turn off sound."""
tb.turn_off()
#return jsonify({'val': 0})
return 'off'
@app.route('/set_sample_rate/<int:value>')
def set_sample_rate(value):
#sound(sample_rate=value)
tb.change_sample_rate(value)
#return jsonify({'sample_rate': value})
return str(value)
@app.route('/set_amplitude/<int:value>')
def set_amplitude(value):
#sound(amplitude=value)
tb.change_amplitude(value)
#return jsonify({'amplitude': value})
return str(value)
@app.route('/set_frequency/<int:value>')
def set_frequency(value):
#sound(frequency=value)
tb.change_frequency(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_bandwidth/<int:value>')
def set_bandwidth(value):
#sound(frequency=value)
tb.change_bandwidth(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_gain/<int:value>')
def set_gain(value):
#sound(frequency=value)
tb.change_gain(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_center_frequency/<int:value>')
def set_center_frequency(value):
#sound(frequency=value)
tb.change_center_frequency(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_USRPsamp_rate/<int:value>')
def set_USRPsamp_rate(value):
#sound(frequency=value)
tb.change_USRPsamp_rate(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/valueofslider')
def slide():
sample_rate = request.args.get('slide1_val', None)
amplitude = request.args.get('slide2_val', None)
frequency = request.args.get('slide3_val', None)
bandwidth = request.args.get('slide4_val', None)
gain = request.args.get('slide5_val', None)
center_frequency = request.args.get('slide6_val', None)
USRPsamp_rate = request.args.get('slide7_val', None)
sound(
sample_rate=sample_rate,
amplitude=amplitude,
frequency=frequency,
bandwidth=bandwidth,
gain=gain,
center_frequency=center_frequency,
USRPsamp_rate=USRPsamp_rate,
)
#return jsonify({
# 'sample_rate': sample_rate,
# 'amplitude': amplitude,
# 'frequency ': frequency ,
# 'bandwidth': bandwidth,
# 'gain': gain,
# 'center_frequency ': center_frequency ,
# 'USRPsamp_rate ': USRPsamp_rate ,
# })
return 'sample_rate: {}, amplitude: {}, frequency: {}, bandwidth: {}, gain: {}, center_frequency: {}, USRPsamp_rate: {}'.format(sample_rate, amplitude, frequency, bandwidth )
def sound(sample_rate=None, amplitude=None, frequency=None, bandwidth=None, gain=None, center_frequency=None, USRPsamp_rate=None):
"""version which uses `change()`"""
if sample_rate is not None:
sample_rate = int(sample_rate)
tb.change_sample_rate(sample_rate)
if amplitude is not None:
amplitude = int(amplitude)
tb.change_amplitude(amplitude)
if frequency is not None:
frequency = int(frequency )
tb.change_frequency(frequency )
if bandwidth is not None:
bandwidth = int(bandwidth )
tb.change_bandwidth(bandwidth )
if gain is not None:
gain = int(gain )
tb.change_gain(gain )
if center_frequency is not None:
center_frequency = int(center_frequency )
tb.change_center_frequency(center_frequency )
if USRPsamp_rate is not None:
USRPsamp_rate = int(USRPsamp_rate )
tb.change_USRPsamp_rate(USRPsamp_rate )
print('[sound] sample_rate:', sample_rate)
print('[sound] amplitude:', amplitude)
print('[sound] frequency:', frequency)
print('[sound] bandwidth:', bandwidth)
print('[sound] gain:', gain)
print('[sound] center_frequency:', center_frequency)
print('[sound] center_frequency:', USRPsamp_rate)
#if tb: # if tb is not None
# tb.change(sample_rate, amplitude, frequency, bandwidth, gain, center_frequency, USRPsamp_rate)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
更新:
这是可以正常工作的 USRP 代码:
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import time
import wx
class broadband_noise(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Broadband Noise")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 16000000
self.gain = gain = 50
self.center_frequency = center_frequency = 88e6
self.bandwidth = bandwidth = 75000
##################################################
# Blocks
##################################################
self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
self.GetWin(),
baseband_freq=0,
y_per_div=10,
y_divs=10,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=1024,
fft_rate=15,
average=False,
avg_alpha=None,
title='FFT Plot',
peak_hold=False,
)
self.Add(self.wxgui_fftsink2_0.win)
self.uhd_usrp_sink_0 = uhd.usrp_sink(
",".join(("", "")),
uhd.stream_args(
cpu_format="sc16",
channels=range(1),
),
)
self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
self.uhd_usrp_sink_0.set_center_freq(center_frequency, 0)
self.uhd_usrp_sink_0.set_gain(gain, 0)
self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
self.uhd_usrp_sink_0.set_bandwidth(bandwidth, 0)
self.blocks_add_xx_0 = blocks.add_vff(1)
self.audio_sink_0 = audio.sink(samp_rate, '', True)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.audio_sink_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.uhd_usrp_sink_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.wxgui_fftsink2_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate)
self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain = gain
self.uhd_usrp_sink_0.set_gain(self.gain, 0)
def get_center_frequency(self):
return self.center_frequency
def set_center_frequency(self, center_frequency):
self.center_frequency = center_frequency
self.uhd_usrp_sink_0.set_center_freq(self.center_frequency, 0)
def get_bandwidth(self):
return self.bandwidth
def set_bandwidth(self, bandwidth):
self.bandwidth = bandwidth
self.uhd_usrp_sink_0.set_bandwidth(self.bandwidth, 0)
def main(top_block_cls=broadband_noise, options=None):
tb = top_block_cls()
tb.Start(True)
tb.Wait()
if __name__ == '__main__':
main()
更新:
uhd_find_devices 输出:
fit-pc@fitpc-fitlet2:~$ uhd_find_devices
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
-- UHD Device 0
Device Address:
type: b200
name: B200mini
serial: 3164B8E
product: B200mini
更新:
uhd_find_devices 输出 from/within Flask 环境:
fit-pc@fitpc-fitlet2:~/my_flask_app/virtualenv$ uhd_find_devices
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
--------------------------------------------------
-- UHD Device 0
--------------------------------------------------
Device Address:
type: b200
name: B200mini
serial: 3164B8E
product: B200mini
更新:
Image of Error location
b200
不是有效的设备地址。您正在寻找 type=b200
作为地址。
仔细检查后,控制台输出表明您正在尝试在创建第一个 USRP 处理程序后创建另一个 USRP 处理程序,并保留对 USRP 的访问权限。
这很容易发生在服务器系统中,其中发出多个可能并发的请求。
我不知道 flask 的工作原理有多亲密,但您只需要与 USRP 接收器(或源)的 一个 实例进行交互。它说了一些关于 "restarting with..." 的内容,但那是行不通的。
您需要构造一次 USRP 处理对象,并在请求之间保留它。
(另外,您的采样率不起作用,但您可能已经知道,它也在控制台输出中)
当我尝试通过 Flask 网络服务器 运行 我的 gnuradio python 程序时遇到此错误。当我将我的 USRP b200 代码行添加到我的原始 "working/healthy" 代码中时,我遇到了这个错误。在这个程序中,我试图通过我的 Flask 网络服务器中的滑块小部件来控制我的代码的变量。
同样,每当我 运行 我的 GnuRadio 软件本身中的任何应用程序时,我使用的 USRP 都可以正常工作。但是当我通过 Flask 尝试它时,它 运行s 一两秒钟然后崩溃。
如有任何帮助,我们将不胜感激。
错误回溯:
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
[top_block_22] __init__: sample_rate: 0
[top_block_22] __init__: amplitude: 0
[top_block_22] __init__: frequency: 0
[top_block_22] __init__: bandwidth: 0
[top_block_22] __init__: USRPsamp_rate: 0
[top_block_22] __init__: gain: 0
[top_block_22] __init__: center_frequency: 0
-- Detected Device: B200mini
-- Operating over USB 3.
-- Initialize CODEC control...
-- Initialize Radio control...
-- Performing register loopback test... pass
-- Performing CODEC loopback test... pass
-- Setting master clock rate selection to 'automatic'.
-- Asking for clock rate 16.000000 MHz...
-- Actually got clock rate 16.000000 MHz.
-- Performing timer loopback test... pass
gr::log :INFO: audio source - Audio sink arch: alsa
UHD Warning:
The hardware does not support the requested TX sample rate:
Target sample rate: 0.000000 MSps
Actual sample rate: 0.031250 MSps
-- Asking for clock rate 32.000000 MHz...
-- Actually got clock rate 32.000000 MHz.
-- Performing timer loopback test... pass
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU * Serving Flask app "app" (lazy loading)
U * Environment: production
UU WARNING: This is a development server. Do not use it in a production deployment.
UU Use a production WSGI server instead.
UU * Debug mode: on
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
UUUU * Restarting with stat
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUlinux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU[top_block_22] __init__: sample_rate: 0
[top_block_22] __init__: amplitude: 0
[top_block_22] __init__: frequency: 0
[top_block_22] __init__: bandwidth: 0
[top_block_22] __init__: USRPsamp_rate: 0
[top_block_22] __init__: gain: 0
[top_block_22] __init__: center_frequency: 0
Traceback (most recent call last):
File "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py", line 175, in <module>
tb = top_block_22(0, 0, 0, 0, 0, 0, 0)
File "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py", line 48, in __init__
channels=range(1),
File "/usr/lib/python2.7/dist-packages/gnuradio/uhd/__init__.py", line 122, in constructor_interceptor
return old_constructor(*args)
File "/usr/lib/python2.7/dist-packages/gnuradio/uhd/uhd_swig.py", line 3012, in make
return _uhd_swig.usrp_sink_make(*args)
RuntimeError: LookupError: KeyError: No devices found for ----->
Device Address:
b200:
[Finished in 85.7s with exit code 1]
[shell_cmd: python -u "/home/fit-pc/my_flask_app/virtualenv/Slider/app.py"]
[dir: /home/fit-pc/my_flask_app/virtualenv/Slider]
[path: /home/fit-pc/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
app.py代码:
from __future__ import print_function
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from gnuradio import uhd
import time
class top_block_22(gr.top_block): # PEP8: CamelCaseName for classes
def __init__(self, sample_rate=0, amplitude=0, frequency=0, bandwidth=0, gain=0, center_frequency=0, USRPsamp_rate=0):
gr.top_block.__init__(self, "Top Block 22")
##################################################
# Variables
##################################################
self.sample_rate = sample_rate
print('[top_block_22] __init__: sample_rate:', self.sample_rate)
self.amplitude = amplitude
print('[top_block_22] __init__: amplitude:', self.amplitude)
self.frequency = frequency
print('[top_block_22] __init__: frequency:', self.frequency)
self.bandwidth = bandwidth
print('[top_block_22] __init__: bandwidth:', self.bandwidth)
self.USRPsamp_rate = USRPsamp_rate
print('[top_block_22] __init__: USRPsamp_rate:', self.USRPsamp_rate)
self.gain = gain
print('[top_block_22] __init__: gain:', self.gain)
self.center_frequency = center_frequency
print('[top_block_22] __init__: center_frequency:', self.center_frequency)
##################################################
# Blocks
##################################################
self.uhd_usrp_sink_0 = uhd.usrp_sink(
",".join(("b200", "")),
uhd.stream_args(
cpu_format="sc16",
channels=range(1),
),
)
# for mute_on, mute_off
#self.old_sample_rate = self.sample_rate
#self.old_ampliture = self.ampliture
#self.old_frequency = self.frequency
#self.old_bandwidth = self.bandwidth
##################################################
# Blocks
##################################################
self.blocks_add_xx = blocks.add_vff(1)
self.audio_sink = audio.sink(32000, '', True)
self.analog_sig_source_x_0 = analog.sig_source_f(sample_rate, analog.GR_COS_WAVE, frequency, amplitude, 0)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, amplitude, -42)
self.uhd_usrp_sink_0.set_samp_rate(USRPsamp_rate)
self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
self.uhd_usrp_sink_0.set_center_freq(center_frequency, 0)
self.uhd_usrp_sink_0.set_gain(gain, 0)
self.uhd_usrp_sink_0.set_bandwidth(bandwidth, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 1))
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
self.connect((self.analog_noise_source_x_0, 0), (self.uhd_usrp_sink_0, 0))
def change_sample_rate(self, value=None):
if value is not None:
self.sample_rate = value
print('[top_block_22] change: sample_rate:', value)
self.analog_sig_source_x_0.set_sampling_freq(value)
def change_amplitude(self, value=None):
if value is not None:
value /= 10000.
self.amplitude = value
print('[top_block_22] change: amplitude:', value)
self.analog_sig_source_x_0.set_amplitude(value)
self.analog_noise_source_x_0.set_amplitude(value)
def change_frequency(self, value=None):
if value is not None:
self.frequency = value
print('[top_block_22] change: frequency:', value)
self.analog_sig_source_x_0.set_frequency(value)
#TODO: change some values
def change_bandwidth(self, value=None):
if value is not None:
self.bandwidth = value
print('[top_block_22] change: bandwidth:', value)
self.uhd_usrp_sink_0.set_bandwidth(value)
def change_gain(self, value=None):
if value is not None:
self.gain = value
print('[top_block_22] change: gain:', value)
self.uhd_usrp_sink_0.set_gain(value)
def change_center_frequency(self, value=None):
if value is not None:
self.center_frequency = value
print('[top_block_22] change: center_frequency:', value)
self.uhd_usrp_sink_0.set_center_freq(value)
def change_USRPsamp_rate(self, value=None):
if value is not None:
self.USRPsamp_rate = value
print('[top_block_22] change: USRPsamp_rate:', value)
self.uhd_usrp_sink_0.set_USRPsamp_rate(value)
def change(self, sample_rate=None, amplitude=None, frequency=None, bandwidth=None, gain=None, center_frequency=None, USRPsamp_rate=None):
#self.change_sample_rate(sample_rate)
#self.change_amplitude(amplitude)
#self.change_frequency(frequency)
#self.change_bandwidth(bandwidth)
#self.change_gain(gain)
#self.change_center_frequency(center_frequency)
#self.change_USRPsamp_rate(center_USRPsamp_rate)
if sample_rate is not None:
self.change_sample_rate(sample_rate)
if amplitude is not None:
self.change_amplitude(amplitude)
if frequency is not None:
self.change_frequency(frequency)
if bandwidth is not None:
self.change_bandwidth(bandwidth)
if gain is not None:
self.change_gain(gain)
if center_frequency is not None:
self.change_center_frequency(center_frequency)
if USRPsamp_rate is not None:
self.change_USRPsamp_rate(USRPsamp_rate)
def turn_off(self):
self.change(0, 0, 0, 0, 0, 0, 0)
#def mute_on(self):
# # remember values
# self.old_sample_rate = self.sample_rate
# self.old_ampliture = self.ampliture
# self.old_frequency = self.frequency
# self.old_ampliture = self.gain
# self.old_center_frequency = self.center_frequency
# self.old_USRPsamp_rate = self.USRPsamp_rate
# # turn off sound
# self.change(0, 0, 0, 0, 0, 0, 0)
#def mute_off(self):
# # set old values
# self.change(self.old_sample_rate, self.old_ampliture, self.old_frequency, self.old_gain, self.old_center_frequency, self.old_USRPsamp_rate)
# -----------------------------------------------------------------------------
from flask import Flask, request, jsonify
app = Flask(__name__)
# start with default values
#tb = top_block_22()
tb = top_block_22(0, 0, 0, 0, 0, 0, 0)
tb.start(True)
@app.route('/')
def index():
return '''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GNURadio Slider Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>
<style>
.slider {
position: absolute;
align:center;
}
.row1 {top:100px;}
.row2 {top:450px;}
.row3 {top:750px;}
.col1 {left:75px;}
.col2 {left:470px;}
.col3 {left:870px;}
.col1 {left:75px;}
</style>
</head>
<body>
<div id="slider1" class='slider row1 col1'></div>
<!-- <p>Sample Rate Slider</p> -->
<div id="slider2" class='slider row1 col2'></div>
<!-- <p>Amplitude Slider2</p> -->
<div id="slider3" class='slider row1 col3'></div>
<!-- <p>Frequency Slider3</p> -->
<div id="slider4" class='slider row2 col1'></div>
<!-- <p>Bandwidth Slider4</p> -->
<div id="slider5" class='slider row2 col2'></div>
<!-- <p>Gain Slider5</p> -->
<div id="slider6" class='slider row2 col3'></div>
<!-- <p>Center Frequency Slider6</p> -->
<div id="slider7" class='slider row3 col1'></div>
<!-- <p>USRP Sample Rate Slider7</p> -->
<button id="turn_off_button">TURN OFF</button>
<script>
// create sliders
$("#slider1").roundSlider({
//sliderType: "min-range",
radius: 150,
min: 0,
max: 1000000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide1_val: event.value}); }
change: function(event) { $.getJSON('/set_sample_rate/' + event.value); }
});
$("#slider2").roundSlider({
//sliderType: "min-range",
radius: 150,
min: 0,
max: 1000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide2_val: event.value}); }
change: function(event) { $.getJSON('/set_amplitude/' + event.value); }
});
$("#slider3").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide3_val: event.value}); }
change: function(event) { $.getJSON('/set_frequency/' + event.value); }
});
$("#slider4").roundSlider({
radius: 150,
min: 0,
max: 10000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide4_val: event.value}); }
change: function(event) { $.getJSON('/set_bandwidth/' + event.value); }
});
$("#slider5").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide5_val: event.value}); }
change: function(event) { $.getJSON('/set_gain/' + event.value); }
});
$("#slider6").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide6_val: event.value}); }
change: function(event) { $.getJSON('/set_center_frequency/' + event.value); }
});
$("#slider7").roundSlider({
radius: 150,
min: 0,
max: 10000000000,
value: 0, // default value at start
//change: function(event) { $.getJSON('/valueofslider', {slide7_val: event.value}); }
change: function(event) { $.getJSON('/set_USRPsamp_rate/' + event.value); }
});
$("#turn_off_button").click(function(){
// set sliders
$("#slider1").data("roundSlider").setValue(0);
$("#slider2").data("roundSlider").setValue(0);
$("#slider3").data("roundSlider").setValue(0);
$("#slider4").data("roundSlider").setValue(0);
$("#slider5").data("roundSlider").setValue(0);
$("#slider6").data("roundSlider").setValue(0);
$("#slider7").data("roundSlider").setValue(0);
// send to server
$.getJSON('/valueofslider', {
slide1_val: 0,
slide2_val: 0,
slide3_val: 0,
slide4_val: 0,
slide5_val: 0,
slide6_val: 0,
slide7_val: 0,
});
});
</script>
</body>
</html>'''
@app.route('/off')
def off():
"""Turn off sound."""
tb.turn_off()
#return jsonify({'val': 0})
return 'off'
@app.route('/set_sample_rate/<int:value>')
def set_sample_rate(value):
#sound(sample_rate=value)
tb.change_sample_rate(value)
#return jsonify({'sample_rate': value})
return str(value)
@app.route('/set_amplitude/<int:value>')
def set_amplitude(value):
#sound(amplitude=value)
tb.change_amplitude(value)
#return jsonify({'amplitude': value})
return str(value)
@app.route('/set_frequency/<int:value>')
def set_frequency(value):
#sound(frequency=value)
tb.change_frequency(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_bandwidth/<int:value>')
def set_bandwidth(value):
#sound(frequency=value)
tb.change_bandwidth(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_gain/<int:value>')
def set_gain(value):
#sound(frequency=value)
tb.change_gain(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_center_frequency/<int:value>')
def set_center_frequency(value):
#sound(frequency=value)
tb.change_center_frequency(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/set_USRPsamp_rate/<int:value>')
def set_USRPsamp_rate(value):
#sound(frequency=value)
tb.change_USRPsamp_rate(value)
#return jsonify({'frequency': value})
return str(value)
@app.route('/valueofslider')
def slide():
sample_rate = request.args.get('slide1_val', None)
amplitude = request.args.get('slide2_val', None)
frequency = request.args.get('slide3_val', None)
bandwidth = request.args.get('slide4_val', None)
gain = request.args.get('slide5_val', None)
center_frequency = request.args.get('slide6_val', None)
USRPsamp_rate = request.args.get('slide7_val', None)
sound(
sample_rate=sample_rate,
amplitude=amplitude,
frequency=frequency,
bandwidth=bandwidth,
gain=gain,
center_frequency=center_frequency,
USRPsamp_rate=USRPsamp_rate,
)
#return jsonify({
# 'sample_rate': sample_rate,
# 'amplitude': amplitude,
# 'frequency ': frequency ,
# 'bandwidth': bandwidth,
# 'gain': gain,
# 'center_frequency ': center_frequency ,
# 'USRPsamp_rate ': USRPsamp_rate ,
# })
return 'sample_rate: {}, amplitude: {}, frequency: {}, bandwidth: {}, gain: {}, center_frequency: {}, USRPsamp_rate: {}'.format(sample_rate, amplitude, frequency, bandwidth )
def sound(sample_rate=None, amplitude=None, frequency=None, bandwidth=None, gain=None, center_frequency=None, USRPsamp_rate=None):
"""version which uses `change()`"""
if sample_rate is not None:
sample_rate = int(sample_rate)
tb.change_sample_rate(sample_rate)
if amplitude is not None:
amplitude = int(amplitude)
tb.change_amplitude(amplitude)
if frequency is not None:
frequency = int(frequency )
tb.change_frequency(frequency )
if bandwidth is not None:
bandwidth = int(bandwidth )
tb.change_bandwidth(bandwidth )
if gain is not None:
gain = int(gain )
tb.change_gain(gain )
if center_frequency is not None:
center_frequency = int(center_frequency )
tb.change_center_frequency(center_frequency )
if USRPsamp_rate is not None:
USRPsamp_rate = int(USRPsamp_rate )
tb.change_USRPsamp_rate(USRPsamp_rate )
print('[sound] sample_rate:', sample_rate)
print('[sound] amplitude:', amplitude)
print('[sound] frequency:', frequency)
print('[sound] bandwidth:', bandwidth)
print('[sound] gain:', gain)
print('[sound] center_frequency:', center_frequency)
print('[sound] center_frequency:', USRPsamp_rate)
#if tb: # if tb is not None
# tb.change(sample_rate, amplitude, frequency, bandwidth, gain, center_frequency, USRPsamp_rate)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
更新:
这是可以正常工作的 USRP 代码:
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import time
import wx
class broadband_noise(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Broadband Noise")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 16000000
self.gain = gain = 50
self.center_frequency = center_frequency = 88e6
self.bandwidth = bandwidth = 75000
##################################################
# Blocks
##################################################
self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
self.GetWin(),
baseband_freq=0,
y_per_div=10,
y_divs=10,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=1024,
fft_rate=15,
average=False,
avg_alpha=None,
title='FFT Plot',
peak_hold=False,
)
self.Add(self.wxgui_fftsink2_0.win)
self.uhd_usrp_sink_0 = uhd.usrp_sink(
",".join(("", "")),
uhd.stream_args(
cpu_format="sc16",
channels=range(1),
),
)
self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
self.uhd_usrp_sink_0.set_center_freq(center_frequency, 0)
self.uhd_usrp_sink_0.set_gain(gain, 0)
self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)
self.uhd_usrp_sink_0.set_bandwidth(bandwidth, 0)
self.blocks_add_xx_0 = blocks.add_vff(1)
self.audio_sink_0 = audio.sink(samp_rate, '', True)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.audio_sink_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.uhd_usrp_sink_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.wxgui_fftsink2_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate)
self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain = gain
self.uhd_usrp_sink_0.set_gain(self.gain, 0)
def get_center_frequency(self):
return self.center_frequency
def set_center_frequency(self, center_frequency):
self.center_frequency = center_frequency
self.uhd_usrp_sink_0.set_center_freq(self.center_frequency, 0)
def get_bandwidth(self):
return self.bandwidth
def set_bandwidth(self, bandwidth):
self.bandwidth = bandwidth
self.uhd_usrp_sink_0.set_bandwidth(self.bandwidth, 0)
def main(top_block_cls=broadband_noise, options=None):
tb = top_block_cls()
tb.Start(True)
tb.Wait()
if __name__ == '__main__':
main()
更新:
uhd_find_devices 输出:
fit-pc@fitpc-fitlet2:~$ uhd_find_devices
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
-- UHD Device 0
Device Address:
type: b200
name: B200mini
serial: 3164B8E
product: B200mini
更新:
uhd_find_devices 输出 from/within Flask 环境:
fit-pc@fitpc-fitlet2:~/my_flask_app/virtualenv$ uhd_find_devices
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown
--------------------------------------------------
-- UHD Device 0
--------------------------------------------------
Device Address:
type: b200
name: B200mini
serial: 3164B8E
product: B200mini
更新:
Image of Error location
b200
不是有效的设备地址。您正在寻找 type=b200
作为地址。
仔细检查后,控制台输出表明您正在尝试在创建第一个 USRP 处理程序后创建另一个 USRP 处理程序,并保留对 USRP 的访问权限。
这很容易发生在服务器系统中,其中发出多个可能并发的请求。
我不知道 flask 的工作原理有多亲密,但您只需要与 USRP 接收器(或源)的 一个 实例进行交互。它说了一些关于 "restarting with..." 的内容,但那是行不通的。
您需要构造一次 USRP 处理对象,并在请求之间保留它。
(另外,您的采样率不起作用,但您可能已经知道,它也在控制台输出中)