discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] message ports


From: Tom Rondeau
Subject: Re: [Discuss-gnuradio] message ports
Date: Sat, 27 Feb 2016 09:48:29 -0800

On Tue, Feb 23, 2016 at 8:18 PM, Dennis Glatting <address@hidden> wrote:
I'm having a problem with message ports. I am trying to have a separate
thread within within the block periodically post messages.

The block is defined as:

<block>
  <name>GenAudio</name>
  <key>acars_GenAudio_x</key>
  <category>acars</category>
  <import>import acars</import>

  <make>acars.GenAudio($rate,$rounding,$fake)</make>
  <callback>set_rate($rate)</callback>
  <callback>set_rounding($rounding)</callback>
  <callback>set_fake($fake)</callback>
...
  <sink>
    <name>in</name>
    <type>message</type>
    <optional>1</optional>
  </sink>
  
  <source>
    <name>out</name>
    <type>complex</type>
  </source>


Within the constructor of my block is the code:


      d_port_id = pmt::mp( "in" );
      message_port_register_in( d_port_id );
      set_msg_handler( d_port_id,
                       boost::bind( &GenAudio_impl::_msgh, this, _1 ));
...
      d_faker = std::thread([this](){ this->_thread_faker();});

The goal is other blocks may be connected to this block's input message
port to encode messages but for testing the periodic thread sends
messages to itself.

Within the periodic thread is the code:

    void
    GenAudio_impl::_thread_faker( void ) {
...
          pmt::pmt_t target = pmt::PMT_NIL;

          message_port_sub(   d_port_id, target );
          message_port_pub(   d_port_id, m );
          message_port_unsub( d_port_id, target );
...

The problem is the run time is throwing an exception with the message:

 what(): Port does not exist: "in" on block: ()


I dumped the block's message ports and there is one named "in" so I
don't understand the error message. Is my code snippet NOT how messages
work?


You need to start the flowgraph before the ports become valid. So starting your thread in the constructor will launch it before the schedules sets up the block_detail and the mechanisms behind the block's functionality. So before you say "tb.start()" (or tb.run()), that message port doesn't exist as far as the scheduler is concerned.

You should be able to overload the "start" function of your block (bool start()) and start the thread inside there instead of the constructor.

Tom
 

reply via email to

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