On Tue, Feb 24, 2015 at 4:36 AM, Jorge Gallo <jmiggal@gmail.com> wrote:
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
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.
Tom
No comments:
Post a Comment