discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Question on PMT boolean messages


From: Ben Hilburn
Subject: Re: [Discuss-gnuradio] Question on PMT boolean messages
Date: Tue, 7 May 2019 16:00:44 -0400

Excellent! So glad you got it working, Ali, and thanks for sharing the solution to your issue!

Cheers,
Ben

On Wed, May 1, 2019 at 3:45 PM Ali Dormiani <address@hidden> wrote:
I figured this out today. I used a handle_msg and simply connected a message strobe to the 'junk' msg input. My custom block works as expected now.

On Tue, Apr 30, 2019 at 12:56 PM Ali Dormiani <address@hidden> wrote:
Hello,

Thank you for the advice. I went back to the tutorials and now I have a better grasp of what is going on.

Regarding 'work' vs 'handle_msg', which situations fit each of these?

Is 'handle_msg' supposed to be for passing messages through multiple internal msg ports?

Is 'work' for dealing with streams or can I do message related things in 'work'?

It appears that handle_msg is for passing from inputs to outputs (which I do not need as I want a block with only a message out).


In short, if one wants to make a block with a single msg output and nothing else, should s/he use a message handler (and leave work empty with a pass) or use work? If so, what should work return, given there are no data-streams involved?

Thank you for your time,

Ali

On Mon, Apr 29, 2019 at 2:49 PM Marcus Müller <address@hidden> wrote:
Hi Ali,
causality, our old foe, strikes again!

You're trying to emit a message in the constructor.  Messages will be
delivered to all message acceptors connected to that message port.
However, you can't possibly connect the block before the block-holding
object exists, i.e. before the constructor returns.

So, necessarily, the messages are sent before anything is connected to
the msg_out port, and thus into the void and simply get dropped by the
scheduler.

Best regards,
Marcus

PS: I'd strongly recommend having a `self.port = pmt.intern('msg_out')`
in the constructor and using that whenever you need the port if you're
doing that within the work() function often. Constructing PMT interns
is relatively expensive.

On Mon, 2019-04-29 at 14:39 -0700, Ali Dormiani wrote:
> Hello everyone,
>
> I have been attempting to make my own block that sends out a boolean
> message if certain time related conditions are met.
>
> I am unable to figure out why my block does not work. This seems to
> be the line of interest:
>
> self.message_port_pub(pmt.intern('msg_out'), pmt.PMT_T)
>
> This line should cause the block to output a PMT true through port
> msg_out right?
>
> My full block is attached bellow. Any help would be greatly
> appreciated.
>
> Thank you all for your time,
>
> Ali
>
> ======================
> import numpy as np
> from gnuradio import gr
> import pmt
> import datetime
>
> class msg_block(gr.basic_block):  # other base classes are
> basic_block, decim_block, interp_block
>     """This block checks time and sends true or false if capture
> period is desired"""
>
>     def __init__(self, minutes=15, seconds=10):  # only default
> arguments here
>         """arguments to this function show up as parameters in GRC"""
>         gr.basic_block.__init__(
>             self,
>             name='Time Enable',   # will show up in GRC
>             in_sig=None,
>             out_sig=None
>         )
>         self.message_port_register_out(pmt.intern('msg_out'))
>         now = datetime.datetime.now()
>         #P_true = pmt.PMT_T
>         #P_false = pmt.PMT_F
>         if ((now.minute % minutes) == 0): #check if minute is ok
>             if (now.second < seconds): #check if capture period is ok
>                 self.message_port_pub(pmt.intern('msg_out'),
> pmt.PMT_T)
>             else:
>                 self.message_port_pub(pmt.intern('msg_out'),
> pmt.PMT_F)
>         else:
>             self.message_port_pub(pmt.intern('msg_out'), pmt.PMT_F)

>     def work(self, input_items, output_items):
>         pass
> =====================================
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

reply via email to

[Prev in Thread] Current Thread [Next in Thread]