【问题标题】:GNU-Radio Companion: enable/disable a block with variableGNU-Radio Companion:启用/禁用带有变量的块
【发布时间】:2020-05-12 18:25:23
【问题描述】:

我有一个具有多种功能的 GRC 项目,但并非所有功能都必须同时调用。将它分成几个独立的项目是一种解决方案,但我更喜欢更灵活的解决方案,它可以动态激活/停用顶级流程图中的某些块。

所以我的想法是根据变量的值启用/禁用块。这可能吗?或者有没有其他类似的解决方案?

【问题讨论】:

    标签: gnuradio gnuradio-companion


    【解决方案1】:


    编辑如果您使用的是 GNU Radio 3.7(并且有充分理由不使用任何更新的版本,您确实应该这样做!):请不要使用选择器。它的“停止一切,在内部重新连接块,继续一切”具有可怕的副作用。

    如果您使用的是 GNU Radio 3.8.0.0 或更高版本:我们已将上述机制替换为简单的点对点复制,这种复制更加健壮(但会产生复制开销)。因此,从 3.8-techpreview 开始,选择器可以安全使用。


    试试“选择器”块。您可以使用两个变量设置活动输​​入/输出端口。

    在内部,选择器是一个分层块,它会暂停你的流程图,断开之前活跃的输入和输出块连接现在活跃的块,然后继续流程图的操作。

    以这种方式,它不是样本精确的,并且可能不是首选工具。您可能想研究消息传递而不是使用变量,然后选择“乘(与)矩阵”块。

    【讨论】:

    • 至少在 3.8.1.0 中,Selector 块上的四年多时间仍然存在。但我肯定会阅读乘法矩阵。谢谢!
    • @bazza 你说得对,我有点老了,让我来修正答案。
    • 我现在正在使用它,它正在发挥作用:-)
    【解决方案2】:

    您可以使用具有一个输入和 n 个输出的 epy 块。在工作函数中,您可以根据需要映射输入。 example_parameter(可以由流程图中的变量设置)可以确定输出索引。 在流程图中插入一个 python 块,双击它,在编辑器中打开,ctrl+a ,ctrl+v。 祝你好运!

     import numpy as np
     from gnuradio import gr
     import time
    
     class blk(gr.sync_block):  # other base classes are basic_block, 
     decim_block, 
     interp_block
    """Embedded Python Block example - a simple multiply const"""
    
    def __init__(self, example_param=1.0):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        gr.sync_block.__init__(
            self,
            name='EPY demux',   # will show up in GRC
            in_sig=[np.complex64],
            out_sig=[np.complex64,np.complex64] # ADD HERE HOW MANY OUTPUTS YOU WANT
        )
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
        self.example_param = example_param
    
    def work(self, input_items, output_items):
        """example: multiply with constant"""
        output_items[int(self.example_param)][:] = input_items[0]
        return len(input_items[0])`
    

    【讨论】:

      猜你喜欢
      • 2017-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2018-01-01
      • 2020-06-14
      • 2020-10-07
      • 2018-02-27
      • 2016-06-15
      相关资源
      最近更新 更多