Is it possible to access work function's variable in __init__ of a GNU Radio block?

大城市里の小女人 提交于 2019-12-13 04:56:02

问题


In the following GNU Radio processing block, I can't figure out who/what passes the value of input_items to the work function in the first place. Is it possible to pass that value to the __init__ function instead?

I have a file xyz.py :

class xyz(gr.sync_block):
    """
    docstring for block add_python
    """
    def __init__(self, parent, title, order):
        gr.sync_block.__init__(self,
            name="xyz",
            in_sig=[numpy.float32,numpy.float32],
            out_sig=None)
            ................
           ................
           //I want to access the value of input_items here
           ...............
           ...............


    def work(self, input_items, output_items):
        ................

回答1:


The __init__ function is called only once to "initialize" the new instance of the class. It has nothing to do with moving data through the flowgraph, besides setting up input and output types so that the block can be successfully connected.

So, in top_block, you might have:

proc = xyz() # xyz's __init__ is called here
self.connect(source, proc, sink) # still no input_items, just connected flowgraph

And later on, you run the flowgraph:

tb = top_block()
tb.run() # 'input_items' are now passed to 'work' of each block in succession

When you run the flowgraph, the GNU Radio scheduler takes a number of samples from the source block and puts them in a buffer. It then passes that buffer to the work function of the next block in the flowgraph, along with an "empty" buffer for output items.

So the work function of each block is called automatically by the scheduler when there is data for it to process. __init__ can not have access to any of the parameters to work, because input_items has not even been passed to work at the time that __init__ is called.




回答2:


work is a function that is entirely seperate from __init__. Its parameters cannot be accessed outside of that function. If you want to access input_items, add it to the __init__ parameter list and pass it when you call __init__.



来源:https://stackoverflow.com/questions/30639668/is-it-possible-to-access-work-functions-variable-in-init-of-a-gnu-radio-blo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!