# Calling functions from flowgraph?

**URL:** <https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225>\
**Category:** GNU Radio\
**Created:** [June 5, 2014, 11:09am UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225 "2014-06-05T11:09:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 5, 2014, 11:09am UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/1 "2014-06-05T11:09:03Z")

</div>

Hi everybody,

well,I had a python script which works with gnuradio and outputs results  
on  
the terminal.To make it more visual,I made all the blocks on the  
gnuradio-comapnion but now I would like to output the results on the  
terminal which means I have to call the main loop in the python script  
from  
the flowgraph to get the job done.In other words,when I hit the button  
execute the flowgraph,I want to see the porgram running.I hope you  
understood what I’m trying to do.So,how can I do that?

regards,  
-Yassine

---

<div class="post-metadata">

**Author:** ![Abouda\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Abouda\_Y](https://www.ruby-forum.com/u/Abouda_Y)\
**Post date:** [June 5, 2014, 11:40am UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/2 "2014-06-05T11:40:54Z")

</div>

Hi Abouda,

in GNU Radio, there’s no real main loop; I don’t really know what you’re  
trying to do.

The python files GNU Radio generates are executables, you can just run  
them in a terminal without GRC 🙂

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Abouda\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Abouda\_Y](https://www.ruby-forum.com/u/Abouda_Y)\
**Post date:** [June 5, 2014, 4:52pm UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/3 "2014-06-05T16:52:13Z")

</div>

On Thu, Jun 5, 2014 at 5:07 PM, Abouda Y.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi everybody,
> 
> well,I had a python script which works with gnuradio and outputs results  
> on the terminal.To make it more visual,I made all the blocks on the  
> gnuradio-comapnion but now I would like to output the results on the  
> terminal which means I have to call the main loop in the python script from  
> the flowgraph to get the job done.In other words,when I hit the button  
> execute the flowgraph,I want to see the porgram running.I hope you  
> understood what I’m trying to do.So,how can I do that?

I think I understand your requirements. You just need to perform these  
steps:

Step 1:  
In GRC (gnuradio-companion), open the flowgraph and then press F5 (or,  
click menu Build → Generate)  
This will generate a new file: “top\_block.py”  
The file is located at the same directory where your \*.grc file is  
located.

Step 2:  
Open a terminal, cd to directory of the top\_block.py, execute it:  
python top\_block.py

With this you will see all python outputs at this terminal.

Is this exactly what you asking for..?

P/S: In fact Marcus M. had already answered your question in above  
message.

---

<div class="post-metadata">

**Author:** ![Abouda\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Abouda\_Y](https://www.ruby-forum.com/u/Abouda_Y)\
**Post date:** [June 6, 2014, 11:11am UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/4 "2014-06-06T11:11:53Z")

</div>

Please stay on the list.

On Thu, Jun 5, 2014 at 11:42 PM, Abouda Y.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> regards,  
> yassine

The top\_block.py is a valid python file, you could amend it accordingly  
to  
include additional “import XXX” statement, as long as it is valid in  
python  
language.

In this case you have to edit the top\_block.py by hand, this cannot be  
done  
from the GRC.

Hope this answers your question.

---

<div class="post-metadata">

**Author:** ![Abouda\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Abouda\_Y](https://www.ruby-forum.com/u/Abouda_Y)\
**Post date:** [June 5, 2014, 2:23pm UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/5 "2014-06-05T14:23:01Z")

</div>

2014-06-05 11:07 GMT+02:00 Abouda Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Abouda\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Abouda\_Y](https://www.ruby-forum.com/u/Abouda_Y)\
**Post date:** [June 6, 2014, 11:17am UTC](https://www.ruby-forum.com/t/calling-functions-from-flowgraph/230225/6 "2014-06-06T11:17:47Z")

</div>

On Fri, Jun 6, 2014 at 12:07 AM, Activecat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > terminal.So I am going to need a small function containing an if  
> > The top\_block.py is a valid python file, you could amend it accordingly to  
> > include additional “import XXX” statement, as long as it is valid in python  
> > language.
> 
> In this case you have to edit the top\_block.py by hand, this cannot be  
> done from the GRC.
> 
> Hope this answers your question.

Nevertheless this won’t gain you any benefit, because you won’t be able  
to  
use your function directly in the flowgraph.  
The correct way is explained in [1].

1. [http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules](http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules)
