I am trying to create a GNU Radio 3.10 OOT module to test callbacks, but I'm unable to get a Python callback on parameter change firing.
I've gone through the Python GNU Radio OOT tutorial and modified it with the information on how to add a callback to the YAML based on this documentation.
The callback I added is called "set_selector". I would assume that whenever I change the selector paramter in the GNU Radio GUI while the flowgraph is running that the set_selector call back in Python would fire and print something. But it never does.
Why isn't the callback firing? Did I miss some step to register the callback, or am I understanding this wrong?
And just to confirm, I have recompiled with make, sudo make install, sudo ldconfig after the changes. The block in the GRC does show the underline on the selector parameter, indicating that it does have a callback.
Python Code
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 Code
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
I figured it out.
Apparently the parameters you change on the block itself with you double click it don't trigger any callbacks, even after clicking 'Apply'. They are only default values that are used when you start the flowgraph.
If you add a QT GUI element like a button or text input, and tie it to the variable with callback by using the same ID, then when you make a change the callback is called as expected.