New python block gr_modtool - When no inputs/outputs, which parent should I use?

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

On Tue, Feb 24, 2015 at 4:36 AM, Jorge G. [email protected] 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

Tom

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