Writing a block in Python (+XML)

Have been trying to write a block in Python. Did not use the modtool.py,
since my understanding is it may not yet support that.

The block has only one output, no inputs. Also wrote the corresponding
XML file. the block shows up correctly in GRC when I select it and add
it to the flowgraph.

I’ve defined the output signature in the work function ( 1, 1,
gr.sizeof_float). My work function writes to output_items[0][ some
indexes] and returns with a count of the number of written output items.

Initially I derived the block from gr.block, but it complained about no
connection to the output, so I changed it to derive from gr.hier_block2.
When running the flowgraph with my block in it, gnuradio complains that
there is no output connection inside my block.

The question is ‘what’ internally connects my output_items to the
block’s output?

I tried self.connect(myblockname, (self, 0)) to satisfy the connection,
but myblockname apparently needs some sort of modifier in order to be a
valid output that can be connected to the block’s output. Tried looking
through python blocks in the source, and the 3.7.2 API, but no luck so
far…

Any advice?

– Tom, N5EG

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Tom,

Have been trying to write a block in Python. Did not use the
modtool.py, since my understanding is it may not yet support that.
Luckily, you’re wrong.
gr_modtool -l python add
works like a charm.

The block has only one output, no inputs. Also wrote the
corresponding XML file. the block shows up correctly in GRC when I
select it and add it to the flowgraph.
It’s a source :slight_smile:
I’ve defined the output signature in the work function ( 1, 1,
gr.sizeof_float). My work function writes to output_items[0][ some
indexes] and returns with a count of the number of written output
items.
very well :slight_smile:

Initially I derived the block from gr.block, but it complained
about no connection to the output, so I changed it to derive from
gr.hier_block2. When running the flowgraph with my block in it,
gnuradio complains that there is no output connection inside my
block.
Oh, that’s wrong. A hier_block is a hierarchical block, that is, only
a set of connections between other blocks and maybe some logic.
You can’t have “work” in a hier_block; well, you can, but it won’t be
called by the GNU Radio scheduler.

Any advice?
A hier block can’t be used here. I don’t know about your flowgraph,
but: did you really connect your gr.block-subclass’ output to let’s
say a null sink or a vector sink?

My advice is: Use gr_modtool, it really makes life easier and failsafer.

Greetings,
Marcus

– Tom, N5EG

_______________________________________________ Discuss-gnuradio
mailing list [email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJS6fumAAoJEAFxB7BbsDrLQmMIAIEgeZgSM8UI8BfUyMnzoJWb
nc3oczsdrevBnprIsjAOfXgReU7gwYexASRBoEO4WFSsriVC5lf1bRMK6xRmbV+v
kaVvrGWurIHWrkt0NWtktwUc0oWWE1fUTvk146V1LR41nUg6vYIw9qMwM3rwf2zV
MeovU47+tsh3scyE9CEnGJxxiB7NGv7EaQ5EiuSXIFv+I8zrq/X2kFkX6K77oyhS
VUmVkOS4U+fYaMzk90Efk06ehm5yaRrrDQoZq0oNUeRTyLYzz7rLSmI2wPOvBYeW
uIhlHYTC0EYYmJy3WK+KggzhfUrw9yE547SkqUnKm2RFXxwfkzJqCwl0hsJ/Z/g=
=aQ50
-----END PGP SIGNATURE-----