|
From: | Ali Dormiani |
Subject: | Re: [Discuss-gnuradio] Question on PMT boolean messages |
Date: | Tue, 30 Apr 2019 12:56:44 -0700 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |