# Message Passing

**URL:** <https://www.ruby-forum.com/t/message-passing/241127>\
**Category:** GNU Radio\
**Created:** [May 14, 2014, 8:13am UTC](https://www.ruby-forum.com/t/message-passing/241127 "2014-05-14T08:13:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 14, 2014, 8:13am UTC](https://www.ruby-forum.com/t/message-passing/241127/1 "2014-05-14T08:13:29Z")

</div>

Dear gurus,

I am learning gnuradio Message Passing feature, but couldn’t get  
desirable  
result.  
The Message seems published successfully, but not subscribed by the  
Message  
receiver.  
How to correct the error …?

The message sender block:

```
// constructor
    message_source1_impl::message_source1_impl()
      : gr::sync_block("message_source1",
              gr::io_signature::make(0, 0, 0),
              gr::io_signature::make( 1, 1, sizeof(int)) )
    {
        message_port_register_out( pmt::mp("print") );
    }

    // send_message1
    void
    message_source1_impl::send_message1()
    {
        std::cout << "message_source1_impl::send_message(): 

```

invoked"  
\<\< std::endl;  
pmt::pmt\_t str0 = pmt::string\_to\_symbol(  
std::string(“Welcome  
2014”));  
message\_port\_pub( pmt::mp(“print”), str0 );  
}

```
    // work
    int
    message_source1_impl::work(int noutput_items,
              gr_vector_const_void_star &input_items,
              gr_vector_void_star &output_items)
    {
        int *out = (int *) output_items[0];
        for (int i=0; i < noutput_items; i++)
            out[i] = (i+1) * (i+1);

        send_message1();
        return noutput_items;
    }

```

The message receiver block:

```
// constructor
    message_sink1_impl::message_sink1_impl()
      : gr::sync_block("message_sink1",
              gr::io_signature::make(0, 0, 0),
              gr::io_signature::make( 1, 1, sizeof(int)) )
    {
        message_port_register_in( pmt::mp("print") );
        set_msg_handler( pmt::mp("print"), boost::bind(

```

&message\_sink1\_impl::handler1, this, \_1 ) );  
}

```
    // message handler
    void
    message_sink1_impl::handler1( pmt::pmt_t myMessage )
    {
        std::cout << "message_sink1_impl::handler1(): invoked" <<

```

std::endl;  
pmt::print( myMessage );  
}

```
    // work
    int
    message_sink1_impl::work(int noutput_items,
              gr_vector_const_void_star &input_items,
              gr_vector_void_star &output_items)
    {
        int *out = (int *) output_items[0];
        for (int i=0; i < noutput_items; i++)
            out[i] = i+1;

        return noutput_items;
    }

```

Flow graph execution output:  
Executing: “/home/mmkk/gnuradio/gr-activecat/apps/top\_block.py”  
message\_source1\_impl::send\_message(): invoked  
message\_source1\_impl::send\_message(): invoked  
message\_source1\_impl::send\_message(): invoked  
message\_source1\_impl::send\_message(): invoked  
message\_source1\_impl::send\_message(): invoked

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 10:27am UTC](https://www.ruby-forum.com/t/message-passing/241127/2 "2014-05-14T10:27:30Z")

</div>

On 14.05.2014 08:11, Activecat wrote:

> Dear gurus,
> 
> I am learning gnuradio Message Passing feature, but couldn’t get  
> desirable result.  
> The Message seems published successfully, but not subscribed by the  
> Message receiver.  
> How to correct the error ..?

Just to make sure: You did connect the ports in your flow graph?

That said, I’ve seen something like this recently. Maybe there’s a  
bug… needs investigating.

M

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 11:16am UTC](https://www.ruby-forum.com/t/message-passing/241127/3 "2014-05-14T11:16:45Z")

</div>

On Wed, May 14, 2014 at 4:26 PM, Martin B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Just to make sure: You did connect the ports in your flow graph?  
> That said, I’ve seen something like this recently. Maybe there’s a bug…  
> needs investigating.  
> M

Both blocks (message sender block, message receiver block) are source  
blocks, both are directly connected to the inputs of a divider blocks,  
i.e. the message receiver block is not at the downstream of the message  
sender block. I guess this is ok because Message Passing is for  
downstream  
blocks to communicate to upstream blocks. Is this correct?

This is part of the top\_block.py generated by GRC, to illustrate the  
flowgraph.

```
    ##################################################
    # Blocks
    ##################################################
    self.blocks_head_0 = blocks.head(gr.sizeof_int*1, 10)
    self.blocks_divide_xx_0 = blocks.divide_ii(1)
    self.activecat_message_source1_0 = activecat.message_source1()
    self.activecat_message_sink1_0 = activecat.message_sink1()
    self.activecat_integer_sink3_0 = activecat.integer_sink3(False,

```

True, “Integer1”)

```
    ##################################################
    # Connections
    ##################################################
    self.connect((self.blocks_divide_xx_0, 0), (self.blocks_head_0, 

```

0))  
self.connect((self.blocks\_head\_0, 0),  
(self.activecat\_integer\_sink3\_0, 0))  
self.connect((self.activecat\_message\_source1\_0, 0),  
(self.blocks\_divide\_xx\_0, 0))  
self.connect((self.activecat\_message\_sink1\_0, 0),  
(self.blocks\_divide\_xx\_0, 1))

System info:  
Gnuradio version = 3.7.3  
OS = Debian jessie/sid, SMP Debian 3.13.10-1 x86\_64 GNU/Linux

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 11:37am UTC](https://www.ruby-forum.com/t/message-passing/241127/4 "2014-05-14T11:37:04Z")

</div>

On Wed, May 14, 2014 at 5:26 PM, Martin B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> There’s no msg\_connect() call here – that would be your problem.  
> M

I build the flowgraph using GRC. How to make correction?  
The complete top\_block.py is as follows.

#!/usr/bin/env python  
##################################################

# Gnuradio Python Flow Graph

# Title: Top Block

# Generated: Wed May 14 17:30:37 2014

##################################################

from gnuradio import blocks  
from gnuradio import eng\_notation  
from gnuradio import gr  
from gnuradio.eng\_option import eng\_option  
from gnuradio.filter import firdes  
from grc\_gnuradio import wxgui as grc\_wxgui  
from optparse import OptionParser  
import activecat  
import wx

class top\_block(grc\_wxgui.top\_block\_gui):

```
def __init__ (self):
    grc_wxgui.top_block_gui. __init__ (self, title="Top Block")
    _icon_path = 

```

“/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png”  
self.SetIcon(wx.Icon(\_icon\_path, wx.BITMAP\_TYPE\_ANY))

```
    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 32000

    ##################################################
    # Blocks
    ##################################################
    self.blocks_head_0 = blocks.head(gr.sizeof_int*1, 10)
    self.blocks_divide_xx_0 = blocks.divide_ii(1)
    self.activecat_message_source1_0 = activecat.message_source1()
    self.activecat_message_sink1_0 = activecat.message_sink1()
    self.activecat_integer_sink3_0 = activecat.integer_sink3(False,

```

True, “Integer1”)

```
    ##################################################
    # Connections
    ##################################################
    self.connect((self.blocks_divide_xx_0, 0), (self.blocks_head_0, 

```

0))  
self.connect((self.blocks\_head\_0, 0),  
(self.activecat\_integer\_sink3\_0, 0))  
self.connect((self.activecat\_message\_source1\_0, 0),  
(self.blocks\_divide\_xx\_0, 0))  
self.connect((self.activecat\_message\_sink1\_0, 0),  
(self.blocks\_divide\_xx\_0, 1))

# QT sink close method reimplementation

```
def get_samp_rate(self):
    return self.samp_rate

def set_samp_rate(self, samp_rate):
    self.samp_rate = samp_rate

```

if **name** == ‘ **main** ’:  
import ctypes  
import sys  
if sys.platform.startswith(‘linux’):  
try:  
x11 = ctypes.cdll.LoadLibrary(‘libX11.so’)  
x11.XInitThreads()  
except:  
print “Warning: failed to XInitThreads()”  
parser = OptionParser(option\_class=eng\_option, usage=“%prog:  
[options]”)  
(options, args) = parser.parse\_args()  
tb = top\_block()  
tb.Start(True)  
tb.Wait()

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 11:28am UTC](https://www.ruby-forum.com/t/message-passing/241127/5 "2014-05-14T11:28:27Z")

</div>

On 14.05.2014 11:14, Activecat wrote:

> Both blocks (message sender block, message receiver block) are source  
> blocks, both are directly connected to the inputs of a divider blocks,  
> i.e. the message receiver block is not at the downstream of the message  
> sender block. I guess this is ok because Message Passing is for  
> downstream blocks to communicate to upstream blocks. Is this correct?

The message passing API doesn’t really care about who’s upstream for the  
streaming API.

> ```
> self.activecat_integer_sink3_0 = activecat.integer_sink3(False,
> self.connect((self.activecat_message_sink1_0, 0),
> 
> ```
> 
> (self.blocks\_divide\_xx\_0, 1))

There’s no msg\_connect() call here – that would be your problem.

M

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 12:20pm UTC](https://www.ruby-forum.com/t/message-passing/241127/6 "2014-05-14T12:20:09Z")

</div>

On Wed, May 14, 2014 at 5:50 PM, Sylvain M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Then they should show as message port in the GRC UI and you need to  
> connect them in the GUI.

This works: (this add additional port in gray color)  
  
print  
message  
1

Whereas this doesn’t work: (the block becomes disappeared in the GRC)  
  
print  
message  
1

Then how to define the message sink port?

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 12:05pm UTC](https://www.ruby-forum.com/t/message-passing/241127/7 "2014-05-14T12:05:22Z")

</div>

Hi,

> > There’s no msg\_connect() call here – that would be your problem.  
> > M
> 
> I build the flowgraph using GRC. How to make correction?  
> The complete top\_block.py is as follows.

Did you define the message port in the .grc XML file for your blocks ?

Something like :

 portname message 1 

Then they should show as message port in the GRC UI and you need to  
connect them in the GUI.

Cheers,

Sylvain

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 12:29pm UTC](https://www.ruby-forum.com/t/message-passing/241127/8 "2014-05-14T12:29:24Z")

</div>

On 14.05.2014 11:35, Activecat wrote:

> On Wed, May 14, 2014 at 5:26 PM, Martin B. \<[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:
> 
> ```
> There's no msg_connect() call here -- that would be your problem.
> M
> 
> ```
> 
> I build the flowgraph using GRC. How to make correction?

To correct this, connect the message ports.

M

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 12:31pm UTC](https://www.ruby-forum.com/t/message-passing/241127/9 "2014-05-14T12:31:15Z")

</div>

On Wed, May 14, 2014 at 6:18 PM, Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> Whereas this doesn’t work: (the block becomes disappeared in the GRC)  
>   
> print  
> message  
> 1
> 
> Then how to define the message sink port?

I have then tested few combinations, it seems that a source block cannot  
have a message sink port.  
Is there such a restriction ..?

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 12:51pm UTC](https://www.ruby-forum.com/t/message-passing/241127/10 "2014-05-14T12:51:32Z")

</div>

On 05/14/2014 12:29 PM, Activecat wrote:

> I have then tested few combinations, it seems that a source block cannot  
> have a message sink port.  
> Is there such a restriction ..?

Not that I know of…

\<?xml version='1.0' encoding='ASCII'?\> Test message\_sink\_complex\_source\_test Custom None in message True out complex 

Works here (GR version: recent master).

(This is a dummy block. The generated FG wont run)

Sebastian

–  
Karlsruhe Institute of Technology (KIT)  
Communications Engineering Lab (CEL)

Dipl.-Ing. Sebastian Koslowski  
Research Associate

Kaiserstrae 12  
Building 05.01  
76131 Karlsruhe, Germany

Phone: +49 721 608-46275  
Fax: +49 721 608-46071  
Email: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Web: [http://www.cel.kit.edu/](http://www.cel.kit.edu/)

KIT University of the State of Baden-Wuerttemberg and National  
Research Center of the Helmholtz Association

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 4:26pm UTC](https://www.ruby-forum.com/t/message-passing/241127/11 "2014-05-14T16:26:55Z")

</div>

On Wed, May 14, 2014 at 7:06 AM, Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> Problem solved, thank everyone !

Yes, this is the strictness of the XML DTD. Glad you got it working.

Tom

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 16, 2014, 7:03am UTC](https://www.ruby-forum.com/t/message-passing/241127/12 "2014-05-16T07:03:00Z")

</div>

On Wed, May 14, 2014 at 10:25 PM, Tom R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> Yes, this is the strictness of the XML DTD. Glad you got it working.  
> Tom

Thank you very much.

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [May 14, 2014, 1:08pm UTC](https://www.ruby-forum.com/t/message-passing/241127/13 "2014-05-14T13:08:09Z")

</div>

On Wed, May 14, 2014 at 6:49 PM, Koslowski, Sebastian (CEL) \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> message\_sink\_complex\_source\_test

I retried by putting the definition of on top of  
 in the xml file, it works.  
It seems that the “sink” definition must be placed on top of “source” ..

Problem solved, thank everyone !
