簡體   English   中英

Python 中的 GNU Radio 回調不起作用

[英]GNU Radio callbacks in Python are not Working

我正在嘗試創建一個 GNU Radio 3.10 OOT 模塊來測試回調,但我無法在參數更改觸發時獲得 Python 回調。

我已經閱讀了Python GNU Radio OOT 教程,並使用有關如何根據此文檔向 YAML 添加回調的信息對其進行了修改。

我添加的回調稱為“set_selector”。 我假設每當我在流程圖運行時更改 GNU Radio GUI 中的選擇器參數時,Python 中的 set_selector 回調就會觸發並打印一些東西。 但它永遠不會。

為什么回調沒有觸發? 我錯過了注冊回調的一些步驟,還是我理解錯了?

為了確認,我在更改后使用 make、sudo make install、sudo ldconfig 重新編譯。 GRC 中的塊確實在選擇器參數上顯示了下划線,表明它確實有回調。

Python代碼

import numpy as np
from gnuradio import gr

class addSubSelect(gr.sync_block):
    """
    docstring for block addSubSelect
    """
    def __init__(self, selector=True):
        gr.sync_block.__init__(self,
            name="addSubSelect",
            in_sig=[np.complex64, np.complex64],
            out_sig=[np.complex64])

        self.selector = selector

    def set_selector(self, selector):
        print("IN CALLBACK")

    def work(self, input_items, output_items):
        in0 = input_items[0]
        in1 = input_items[1]

        if (self.selector):
            output_items[0][:] = in0 + in1
        else:
            output_items[0][:] = in0 - in1

        return len(output_items[0])

YAML 代碼

id: callbackTest_addSubSelect
label: addSubSelect
category: '[callbackTest]'

templates:
  imports: from gnuradio import callbackTest
  make: callbackTest.addSubSelect(${selector})
  callbacks:
  - set_selector(${selector})
#  Make one 'parameters' list entry for every parameter you want settable from the GUI.
#     Keys include:
#     * id (makes the value accessible as keyname, e.g. in the make entry)
#     * label (label shown in the GUI)
#     * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
#     * default
parameters:
- id: selector
  label: Add (True) or Subtract (False) selector
  dtype: bool
  default: True
#- id: ...
#  label: ...
#  dtype: ...

#  Make one 'inputs' list entry per input and one 'outputs' list entry per output.
#  Keys include:
#      * label (an identifier for the GUI)
#      * domain (optional - stream or message. Default is stream)
#      * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
#      * vlen (optional - data stream vector length. Default is 1)
#      * optional (optional - set to 1 for optional inputs. Default is 0)
inputs:
- label: in0
  domain: stream
  dtype: complex
- label: in1
  domain: stream
  dtype: complex


#  vlen: ...
#  optional: ...

outputs:
- label: out0
  domain: stream
  dtype: complex
#  vlen: ...
#  optional: ...

#  'file_format' specifies the version of the GRC yml format used in the file
#  and should usually not be changed.
file_format: 1

我想到了。

顯然,您雙擊塊本身更改的參數不會觸發任何回調,即使在單擊“應用”之后也是如此。 它們只是啟動流程圖時使用的默認值。

如果您添加 QT GUI 元素(如按鈕或文本輸入),並使用相同的 ID 將其綁定到帶有回調的變量,那么當您進行更改時,回調將按預期調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM