Python message ports

Hi list,

I tried to use message ports with python blocks but I can’t find
something like “register_msg_port_in” or similar. And asking google
didn’t give me any results as well. So I can’t register a message port.
This rises the question if it is possible to use message ports with
python blocks.
In my case it would be very useful as I want to create a block which is
only called a few times.

Also, I wanted to create QA code for my block and tried to use a
“message_sink” block. This block does not use the msg_connect method to
connect to a message queue. It demands a msg_queue object. Is there a
reason for this block not to use the msg_connect method?

GRC uses
self.blocks_message_sink_0=blocks.message_sink(gr.sizeof_gr_complex*1,
blocks_message_sink_0_msgq_out, False)

but this raises another error
NameError: global name ‘blocks_message_sink_0_msgq_out’ is not defined
That’s not surprising as the variable is never declared.

I hope someone can clear things up.

  • Johannes

What version of GNU Radio are you using? Message ports with Python
blocks
are supported as of 3.6.4:

class message_consumer(gr.sync_block):
def init(self):
gr.sync_block.init(
self,
name = “message consumer”,
in_sig = None,
out_sig = None
)
self.message_port_register_in(pmt.pmt_intern(‘in_port’))
self.set_msg_handler(pmt.pmt_intern(‘in_port’), self.handle_msg)

def handle_msg(self, msg):
    # Handle the message here