# Minimal grc python block

**URL:** <https://www.ruby-forum.com/t/minimal-grc-python-block/225384>\
**Category:** GNU Radio\
**Created:** [January 4, 2013, 7:31pm UTC](https://www.ruby-forum.com/t/minimal-grc-python-block/225384 "2013-01-04T19:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [January 4, 2013, 7:31pm UTC](https://www.ruby-forum.com/t/minimal-grc-python-block/225384/1 "2013-01-04T19:31:17Z")

</div>

Evening all. I only recently (yesterday) started working with gnuradio  
and am  
having some trouble getting a minimal grc python block going. I’ve found  
a  
number of references in this mailing list and elsewhere (and lots of  
broken  
links) but just can’t seem to piece it all together. Some guidance would  
be  
greatly appreciated.

My current goal is just to create a block in grc, it doesn’t even have  
to do  
anything yet. Here’s what I’ve done so far. I’ve added these to .bashrc:

export PYTHONPATH=$PYTHONPATH:/home/user/mygnuradioblocks  
export GRC\_BLOCKS\_PATH=$GRC\_BLOCKS\_PATH:/home/user/mygnuradioblocks

As suggested by (I’ve tried the other two methods for specifying the  
.xml  
path as well):

[gnuradio.org/redmine/projects/gnuradio/wiki/GNURadioCompanion#Adding-Custom-Blocks](http://gnuradio.org/redmine/projects/gnuradio/wiki/GNURadioCompanion#Adding-Custom-Blocks)

And added the following two files to this folder (based on  
[Blocks Coding Guide · guruofquality/grextras Wiki · GitHub](https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide)):

## mytestblock.py

#!/usr/bin/env python

from gnuradio import gr  
import block\_gateway

class my\_first\_block(gr.block):  
def **init** (self):  
gr.block. **init** (self, name = “my first block”, in\_sig=None,  
out\_sig=None)

def work(self, input\_items, output\_items):  
return 0

## mytestblock.xml
\<?xml version="1.0"?\> MY: FIRST BLOCK MY my\_first\_block import mytestblock as mtb mtb.my\_first\_block()

```
    <name>my param1</name>
    <key>my_param_1</key>
    <value>False</value>
    <type>bool</type>
    <option><name>val_false</name><key>False</key></option>
    <option><name>val_true</name><key>True</key></option>

<doc>

```

MY TEST BLOCK: Bleh, hope this works!

I however can’t get grc to recognize this block, In addition I’ve tried  
moving these two files to the system xml and py directories  
respectively:

/usr/local/share/gnuradio/grc/blocks/  
/usr/local/lib/python2.7/dist-packages/gnuradio/extras/

And even modifying files in those two folders to a minimal form. In  
short,  
I’m having a fairly hard time to get my first python grc block going, if  
anyone could point me in the right direction for creating a minimal grc  
python block it would be much appreciated.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Minimal-grc-python-block-tp38838.html](http://gnuradio.4.n7.nabble.com/Minimal-grc-python-block-tp38838.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 4, 2013, 8:41pm UTC](https://www.ruby-forum.com/t/minimal-grc-python-block/225384/2 "2013-01-04T20:41:58Z")

</div>

FYI I just solved the problem. The and tag order was  
reversed. I didn’t know that the xml format was so strict. Well on my  
way  
now.

* * *

The blank lines in my xml data should have contained the tags, they  
were  
lost in copying the xml over for some reason.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Minimal-grc-python-block-tp38838p38840.html](http://gnuradio.4.n7.nabble.com/Minimal-grc-python-block-tp38838p38840.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).
