执行python代码时出现属性错误

时间:2014-04-16 06:07:51

标签: python-2.7 gnuradio

我是一名学生并在GNU Radio工作。

我有一个python代码,我想在GNU无线电伴侣中运行,但我无法搜索正确的块来执行该代码...任何人都可以帮助我吗??当我执行相同的python代码(不在GNU中,我收到以下错误:

AttributeError:' top_block_sptr'对象没有属性' wxgui _'

代码如下所示:

#!/usr/bin/env python
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
#from gnuradio import window
from gnuradio.eng_option import eng_option
#from gnuradio.gr import firdes
from gnuradio.wxgui import forms
from gnuradio.wxgui import waterfallsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx

class top_block(grc_wxgui.top_block_gui):
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
        ##################################################
        # Variables
        ###
        ###############################################
        self.variable_slider_1 = variable_slider_1 = 32
        self.variable_slider_0 = variable_slider_0 = 0
        self.samp_rate = samp_rate = 21e6
        self.gain = gain = variable_slider_1
        self.delay_length = delay_length= variable_slider_0
        ##################################################
        # Blocks
        ##################################################
        self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c(
        self.GetWin(),
        baseband_freq=0,
        dynamic_range=100,
        ref_level=0,
        ref_scale=2.0,
        sample_rate=samp_rate,
        fft_size=512,
        fft_rate=15,
        average=False,
        avg_alpha=None,
        title="Output Waterfall Plot",
        )
        self.GridAdd(self.wxgui_waterfallsink2_0_0.win, 0, 10, 10, 10)
        self.wxgui_
        waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        self.GetWin(),
        baseband_freq=0,
        dynamic_range=100,
        ref_level=0,
        ref_scale=2.0,
        sample_rate=samp_rate,
        fft_size=512,
        fft_rate=15,
        average=False,
        avg_alpha=None,
        title="Input Waterfall Plot",
        )
        self.GridAdd(self.wxgui_waterfallsink2_0.win, 0, 0, 10, 10)
        _variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL)
        self._variable_slider_1_text_box = forms.text_box(
        parent=self.GetWin(),
        sizer=_variable_slider_1_sizer,
        value=self.variable_slider_1,
        callback=self.set_variable_slider_1,
        label="Output Gain",
        converter=forms.float_converter(),
        proportion=0,
        )
        self._variable_slider_1_slider = forms.slider(
        parent=self.GetWin(),
        sizer=_variable_slider_1_sizer,
        value=self.variable_slider_1,
        callback=self.set_variable_slider_1,
        minimum=0,
        maximum=32,
        num_steps=31,
        style=wx.SL_HORIZONTAL,
        cast=float,
        proportion=1,
        )
        self.GridAdd(_variable_slider_1_sizer, 12, 10, 1, 9)
        _variable_sl
        ider_0_sizer = wx.BoxSizer(wx.VERTICAL)
        self._variable_slider_0_text_box = forms.text_box(
        parent=self.GetWin(),
        sizer=_variable_slider_0_sizer,
        value=self.variable_slider_0,
        callback=self.set_variable_slider_0,
        label="Delay Length",
        converter=forms.int_converter(),
        proportion=0,
        )
        self._variable_slider_0_slider = forms.slider(
        parent=self.GetWin(),
        sizer=_variable_slider_0_sizer,
        value=self.variable_slider_0,
        callback=self.set_variable_slider_0,
        minimum=0,
        maximum=710000,
        num_steps=1000,
        style=wx.SL_HORIZONTAL,
        cast=int,
        proportion=1,
        )
        self.GridAdd(_variable_slider_0_sizer, 10, 10, 1, 9)
        self.uhd_usrp_source_0 = uhd.usrp_source(
        device_addr="",
        stream_args=uhd.stream_args(
        cpu_format="fc32",
        channels=range(1),
        ),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(2.28e9, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        device_addr="",
        stream_args
        =uhd.stream_args(
        cpu_format="fc32",
        channels=range(1),
        ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(2.28e9, 0)
        self.uhd_usrp_sink_0.set_gain(gain, 0)
        self.gr_file_source_0_0 = gr.file_source(
        gr.sizeof_gr_complex*1,
"/home/ubuntu/radar-rx3.capture", True)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1,
"/home/ubuntu/radar-rx3.capture", True)
        self.gr_delay_0_0 = gr.delay(gr.sizeof_gr_complex*1, delay_length)
        self.blocks_mult
        iply_xx_0 = blocks.multiply_vcc(1)
        ##################################################
        # Connections
        ##################################################
        self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.gr_file_source_0_0, 0), (self.gr_delay_0_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.gr_delay_0_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_waterfallsink2_0_0, 0))
    def get_variable_slider_1(self):
        return self.variable_slider_1
    def set_variable_slider_1(self, variable_slider_1):
        self.variable_slider_1 = variable_slider_1
        self.set_gain(self.variable_slider_1)
        self._variable_slider_1_slider.set_value(self.variable_slider_1)
        self._variable_slider_1_text_box.set_value(self.variable_slider_1)

    def get_variable_slider_0(self):
        return self.variable_slider_0
    def set_variable_slider_0(self, variable_slider_0):
        self.variable_slider_0 = variable_slider_0
        self.set_delay_length(self.variable_slider_0)
        self._variable_slider_0_slider.set_value(self.variable_slider_0)
        self._variable_slider_0_text_box.set_value(self.variable_slider_0)
    def get_samp_rate(self):
        return self.samp_rate
    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate)
        self.wxgui_waterfallsink2_0_0.set_sample_rate(self.samp_rate)
        self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
        self.uhd_usrp_source_0.set_samp_rate(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_delay_length(self):
        return self.delay_length
    def set_delay_length(self, delay_length):
        self.delay_length = delay_length
        self.gr_delay_0_0.set_delay(self.delay_length)
if __name__ == '__main__':
    parser = OptionParser(option_class=eng_option,usage="%prog: [options]")
    (options, args) = parser.parse_args()
    tb = top_block()
    tb.Run(True)

1 个答案:

答案 0 :(得分:1)

中存在错误的换行符
  self.wxgui_
    waterfallsink2_0 = waterfallsink2.waterfall_sink_c(...

删除错误的换行符,它应该可以正常工作。如果有疑问,请使用GNU Radio Companion重新生成python文件。确保你的编辑不会在他不应该的地方添加换行符。