# New python block gr\_modtool - When no inputs/outputs, which parent should I use?

**URL:** <https://www.ruby-forum.com/t/new-python-block-gr-modtool-when-no-inputs-outputs-which-parent-should-i-use/234321>\
**Category:** GNU Radio\
**Created:** [February 24, 2015, 10:37am UTC](https://www.ruby-forum.com/t/new-python-block-gr-modtool-when-no-inputs-outputs-which-parent-should-i-use/234321 "2015-02-24T10:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [February 24, 2015, 10:37am UTC](https://www.ruby-forum.com/t/new-python-block-gr-modtool-when-no-inputs-outputs-which-parent-should-i-use/234321/1 "2015-02-24T10:37:23Z")

</div>

Hello,

I tried to implement a python block which generates tuning commands  
every 5  
seconds.  
Python block: 0 inputs, 0 outputs, 1 out\_msg port which must be  
declared in the constructor.

I used gr\_modtool. I got some trouble that I think can be easily solved.

New python block:

#!/usr/bin/env python  
import numpy  
from gnuradio import gr  
import time

class generador\_NN(SOMETHING\_1):  
def **init** (self):  
SOMETHING\_1. **init** (SOMETHING\_2)  
self.message\_port\_register\_out(pmt.intern(“ppm”))

```
def general_work(self):
while True:
    time.sleep(5)
    self.message_port_pub(pmt.intern("ppm"), pmt.to_pmt("freq",

```

float(915e6)))  
time.sleep(5)  
self.message\_port\_pub(pmt.intern(“ppm”), pmt.to\_pmt(“freq”,  
float(916e6)))

My trouble comes where the “SOMETHING” is:

SOMETHING\_1: gr.sync\_block, gr.basic\_block, gr.noblock ¿?  
When using gr\_mod tool, which kind of block must specify? If I use sync  
or  
basic it complaints there are missing input/outputs. On the other hand  
if I  
write noblock there is no message\_port\_register\_out method available.  
How can I solve that?

SOMETHING\_2: Depends which kind of block is the parent. Since there is  
no  
input/output it must be empty (self). Correct?

Many thanks,  
Jorge

---

<div class="post-metadata">

**Author:** ![jorgegetafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jorgegetafe](https://www.ruby-forum.com/u/jorgegetafe)\
**Post date:** [February 24, 2015, 4:29pm UTC](https://www.ruby-forum.com/t/new-python-block-gr-modtool-when-no-inputs-outputs-which-parent-should-i-use/234321/2 "2015-02-24T16:29:37Z")

</div>

On Tue, Feb 24, 2015 at 4:36 AM, Jorge G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> New python block:
> 
> input/output it must be empty (self). Correct?
> 
> Many thanks,  
> Jorge

You can do it just as a gr.basic\_block:

class newblock(gr.basic\_block):  
“”"  
What the block does.  
“”"  
def **init** (self, args):  
gr.basic\_block. **init** (self,  
name=“newblock”,  
in\_sig=, # No streaming ports!  
out\_sig=)  
# Register the message port  
self.message\_port\_register\_out(pmt.intern(‘portname’))

You should take a look at our Guided Tutorials. The above code comes  
straight from one of the example blocks we create in there that I made  
more  
generic here.

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorials](http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorials)

Tom

---

<div class="post-metadata">

**Author:** ![jorgegetafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jorgegetafe](https://www.ruby-forum.com/u/jorgegetafe)\
**Post date:** [February 24, 2015, 4:42pm UTC](https://www.ruby-forum.com/t/new-python-block-gr-modtool-when-no-inputs-outputs-which-parent-should-i-use/234321/3 "2015-02-24T16:42:55Z")

</div>

On 02/24/2015 10:36 AM, Jorge G. wrote:

> My trouble comes where the “SOMETHING” is:
> 
> SOMETHING\_1: gr.sync\_block, gr.basic\_block, gr.noblock ?  
> When using gr\_mod tool, which kind of block must specify? If I use sync  
> or basic it complaints there are missing input/outputs. On the other  
> hand if I write noblock there is no message\_port\_register\_out method  
> available.  
> How can I solve that?

Maybe a hier block is the right choice. modtool can do those, so follow  
its lead as closely as possible. It will have zero in- and outputs, but  
registers message ports.

See qa\_hier\_block2\_message\_connections.py for an example.

Cheers,  
Martin
