Is it possible to access work function's varia

2019-09-05 14:41发布

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):
        ................

2条回答
Lonely孤独者°
2楼-- · 2019-09-05 15:38

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.

查看更多
祖国的老花朵
3楼-- · 2019-09-05 15:41

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__.

查看更多
登录 后发表回答