Gr-howto-write-a-block


#1

Hi,

I have been trying to create a new block
“howto_ren_bin_statistics_mean_f” using the howto example as the base.

I have created a .cc, .h, edited the howto.i and edited the Makefile.am.
The block successfully “compiles” after calling automake -> ./configure
-> make, and .la, howto.cc, howto.py files are successfully generated.

However when I run a test program with:

from gnuradio import howto

stats = howto.ren_bin_statistics_mean_f(self.fft_size, self.msgq,
self._tune_callback, tune_delay, dwell_delay)

It says it can’t find the module,

Traceback (most recent call last):
File “qa_spectrum_sense.py”, line 481, in
tb = my_top_block()
File “qa_spectrum_sense.py”, line 380, in init
stats = howto.ren_bin_statistics_mean_f(self.fft_size, self.msgq,
AttributeError: ‘module’ object has no attribute
‘ren_bin_statistics_mean_f’

How do I build howto correctly or get gnuradio to recognise and use this
new block ren_bin_statistics_mean_f?

I am concerned in _howto.la that the “directory this library needs to be
installed under”
libdir=’/u/students/sherman/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio’

is not the same as I am using,
libdir=’/u/students/sherman/ren_static/gr-howto-write-a-block-3.1.3’

I believe the whole thing is building correctly because in the generated
howto.py there is an entry:

howto_ren_bin_statistics_mean_f_sptr_swigregister =
_howto.howto_ren_bin_statistics_mean_f_sptr_swigregister
howto_ren_bin_statistics_mean_f_sptr_swigregister(howto_ren_bin_statistics_mean_f_sptr)

def howto_ren_bin_statistics_mean_f_block(*args):
“”“howto_ren_bin_statistics_mean_f_block(howto_ren_bin_statistics_mean_f_sptr
r) -> gr_block_sptr”""
return _howto.howto_ren_bin_statistics_mean_f_block(*args)
howto_ren_bin_statistics_mean_f_sptr.block = lambda self:
howto_ren_bin_statistics_mean_f_block (self)
howto_ren_bin_statistics_mean_f_sptr.repr = lambda self: “<gr_block
%s (%d)>” % (self.name(), self.unique_id ())

def ren_bin_statistics_mean_f(*args):
“”"
ren_bin_statistics_mean_f(unsigned int vlen, gr_msg_queue_sptr msgq,
gr_feval_dd tune,
size_t tune_delay, size_t dwell_delay) ->
howto_ren_bin_statistics_mean_f_sptr
“”"
return _howto.ren_bin_statistics_mean_f(*args)

Just to make clear what is my question:
How do I build howto correctly or get gnuradio to recognise and use this
new block ren_bin_statistics_mean_f?


#2

On Thu, Apr 02, 2009 at 04:55:39AM +0200, William Sherman wrote:

However when I run a test program with:

from gnuradio import howto

There’s several places where this can go wrong, but my guess is you’re
trying to run the line above in one of your qa_* files through make
check - right?

If so, change the line to ‘import howto’, as in the examples. the
run_tests script will change all the path stuff for you.

Once make check passes, see what ‘make install’ tells you; all make
processes are pretty verbose. It might be putting your module in the
wrong position. To see if that worked, you have to use your ‘from
gnuradio …’ line above.

Hope this is what you were looking for…

MB


#3

I did not run make install before.

When I ran make install I get the following messages:

curve: [~/Masters/ren_static/gr-howto-ren-3.1.3] % make install
Making install in config
Making install in src
Making install in lib
make install-am
test -z
“/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/include/gnuradio”
|| …/…/./install-sh -c -d
“/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/include/gnuradio”
/usr/bin/install -c -m 644 ‘howto_square_ff.h’
‘/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/include/gnuradio/howto_square_ff.h’
/usr/bin/install -c -m 644 ‘howto_square2_ff.h’
‘/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/include/gnuradio/howto_square2_ff.h’
/usr/bin/install -c -m 644 ‘howto_ren_bin_statistics_mean_f.h’
‘/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/include/gnuradio/howto_ren_bin_statistics_mean_f.h’
test -z
“/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio”
|| …/…/./install-sh -c -d
“/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio”
/bin/bash …/…/libtool --mode=install /usr/bin/install -c
‘_howto.la’
‘/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio/_howto.la’
libtool: install: /usr/bin/install -c .libs/_howto.so
/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio/_howto.so
libtool: install: /usr/bin/install -c .libs/_howto.lai
/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio/_howto.la
libtool: install: warning: remember to run `libtool --finish
/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3’
make: don’t know how to make howto_square_ff.py. Stop

make: stopped in
/am/state-opera/home1/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/src/lib
*** Error code 2

make install begins to fail here,
/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3/lib/python2.5/site-packages/gnuradio/_howto.la
libtool: install: warning: remember to run `libtool --finish
/u/students/renyu/Masters/ren_static/gr-howto-write-a-block-3.1.3’
make: don’t know how to make howto_square_ff.py. Stop

I did not modify howto_square_ff so I am unsure why it is complaining
that it can’t make howto_square_ff.

This warning, “install: warning: remember to run `libtool --finish” is
interesting. Googling this it appears to be related with where make
tries to locate libraries / directory it makes the library to?

Does anyone know why the make install fails and I can’t make a new
block?

Martin B. wrote:

On Thu, Apr 02, 2009 at 04:55:39AM +0200, William Sherman wrote:

However when I run a test program with:

from gnuradio import howto

There’s several places where this can go wrong, but my guess is you’re
trying to run the line above in one of your qa_* files through make
check - right?

If so, change the line to ‘import howto’, as in the examples. the
run_tests script will change all the path stuff for you.

Once make check passes, see what ‘make install’ tells you; all make
processes are pretty verbose. It might be putting your module in the
wrong position. To see if that worked, you have to use your ‘from
gnuradio …’ line above.

Hope this is what you were looking for…

MB


#4

On Fri, Apr 17, 2009 at 1:09 AM, William Sherman
removed_email_address@domain.invalidwrote:

Do I need to building gr-howto-write-a-block-3.1.3 from inside the
gnuradio directory instead of just some random directory where it is
currently located?

The point of the standalone (random) tree is so that it doesn’t need to
be
inside the GNU Radio tree to work :wink:

Did you do a “sudo make install” also?

  • George

#5

OK I fixed the error in my Makefile which was giving me the make error.

However I have run into another problem. python doesn’t pick up the new
block when I try to run a python program.

I use,
from gnuradio import howto
but the new block is not recognised.

Why would this be?
Do I need to building gr-howto-write-a-block-3.1.3 from inside the
gnuradio directory instead of just some random directory where it is
currently located?


#6

George N. wrote:

On Fri, Apr 17, 2009 at 1:09 AM, William Sherman
removed_email_address@domain.invalidwrote:

Do I need to building gr-howto-write-a-block-3.1.3 from inside the
gnuradio directory instead of just some random directory where it is
currently located?

The point of the standalone (random) tree is so that it doesn’t need to
be
inside the GNU Radio tree to work :wink:

Did you do a “sudo make install” also?

  • George

I did a make install at the end. I do not have sudo privileges. Is sudo
necessary?

The full sequence I am executing is,

automake
env LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" CPPFLAGS="-I/usr/pkg/include" ./configure --prefix=/u/students/renyu/Masters/ren_static/installdir
make
make install

make install creates a lib and include folder in installdir with
howtoren.pyo, pyc, py, so la (my new block is a howtoren module with the
one block bin_statistics_mean_f.

I read on the howto write your own block tutorial that you need to get
python to “see” where your new module is:

"The build tree is everything from topdir (the one containing
configure.ac) down. The path to the install tree is
prefix/lib/pythonversion/site-packages, where prefix is the --prefix
argument to configure (default /usr/local) and version is the installed
version of python. A typical value is
/usr/local/lib/python2.3/site-packages.

We normally set our PYTHONPATH environment variable to point at the
install tree, and do this in ~/.bash_profile or ~/.profile. This allows
our python apps to access all the standard python libraries, plus our
locally installed stuff like GNU Radio."

I created ~/.bash_profile and ~/.profile, with contents:

setenv PYTHONPATH
/u/students/renyu/Masters/ren_static/installdir/lib/python2.5/site-packages/

However I still can’t from gnuradio import howtoren.

Any advice?

This is my howtoren.py for verification:

This file was automatically generated by SWIG (http://www.swig.org).

Version 1.3.31

Don’t modify this file, modify the SWIG interface instead.

import _howtoren
import new
new_instancemethod = new.instancemethod
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn’t have ‘property’.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == “thisown”): return self.this.own(value)
if (name == “this”):
if type(value).name == ‘PySwigObject’:
self.dict[name] = value
return
method = class_type.swig_setmethods.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.dict[name] = value
else:
raise AttributeError(“You cannot add attributes to %s” % self)

def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
if (name == “thisown”): return self.this.own()
method = class_type.swig_getmethods.get(name,None)
if method: return method(self)
raise AttributeError,name

def _swig_repr(self):
try: strthis = "proxy of " + self.this.repr()
except: strthis = “”
return “<%s.%s; %s >” % (self.class.module,
self.class.name, strthis,)

import types
try:
_object = types.ObjectType
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
del types

def _swig_setattr_nondynamic_method(set):
def set_attr(self,name,value):
if (name == “thisown”): return self.this.own(value)
if hasattr(self,name) or (name == “this”):
set(self,name,value)
else:
raise AttributeError(“You cannot add attributes to %s” %
self)
return set_attr

class howtoren_bin_statistics_mean_f_sptr(object):
“”“Proxy of C++ howtoren_bin_statistics_mean_f_sptr class”""
thisown = _swig_property(lambda x: x.this.own(), lambda x, v:
x.this.own(v), doc=‘The membership flag’)
repr = _swig_repr
def init(self, *args):
“”"
init(self) -> howtoren_bin_statistics_mean_f_sptr
init(self, p) -> howtoren_bin_statistics_mean_f_sptr
“”"
this = howtoren.new_howtoren_bin_statistics_mean_f_sptr(*args)
try: self.this.append(this)
except: self.this = this
def deref(*args):
“”“deref(self)”""
return
howtoren.howtoren_bin_statistics_mean_f_sptr___deref
(*args)

__swig_destroy__ = 

_howtoren.delete_howtoren_bin_statistics_mean_f_sptr
del = lambda self : None;
def history(*args):
“”“history(self) -> unsigned int”""
return
_howtoren.howtoren_bin_statistics_mean_f_sptr_history(*args)

def output_multiple(*args):
    """output_multiple(self) -> int"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_output_multiple(*args)

def relative_rate(*args):
    """relative_rate(self) -> double"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_relative_rate(*args)

def start(*args):
    """start(self) -> bool"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_start(*args)

def stop(*args):
    """stop(self) -> bool"""
    return _howtoren.howtoren_bin_statistics_mean_f_sptr_stop(*args)

def detail(*args):
    """detail(self) -> gr_block_detail_sptr"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_detail(*args)

def set_detail(*args):
    """set_detail(self, gr_block_detail_sptr detail)"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_set_detail(*args)

def name(*args):
    """name(self) -> string"""
    return _howtoren.howtoren_bin_statistics_mean_f_sptr_name(*args)

def input_signature(*args):
    """input_signature(self) -> gr_io_signature_sptr"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_input_signature(*args)

def output_signature(*args):
    """output_signature(self) -> gr_io_signature_sptr"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_output_signature(*args)

def unique_id(*args):
    """unique_id(self) -> long"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_unique_id(*args)

def basic_block(*args):
    """basic_block(self) -> gr_basic_block_sptr"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_basic_block(*args)

def check_topology(*args):
    """check_topology(self, int ninputs, int noutputs) -> bool"""
    return 

_howtoren.howtoren_bin_statistics_mean_f_sptr_check_topology(*args)

howtoren_bin_statistics_mean_f_sptr_swigregister =
_howtoren.howtoren_bin_statistics_mean_f_sptr_swigregister
howtoren_bin_statistics_mean_f_sptr_swigregister(howtoren_bin_statistics_mean_f_sptr)

def howtoren_bin_statistics_mean_f_block(*args):
“”“howtoren_bin_statistics_mean_f_block(howtoren_bin_statistics_mean_f_sptr
r) -> gr_block_sptr”""
return _howtoren.howtoren_bin_statistics_mean_f_block(*args)
howtoren_bin_statistics_mean_f_sptr.block = lambda self:
howtoren_bin_statistics_mean_f_block (self)
howtoren_bin_statistics_mean_f_sptr.repr = lambda self: “<gr_block
%s (%d)>” % (self.name(), self.unique_id ())

def bin_statistics_mean_f(*args):
“”"
bin_statistics_mean_f(unsigned int vlen, gr_msg_queue_sptr msgq,
gr_feval_dd tune,
size_t tune_delay, size_t dwell_delay) ->
howtoren_bin_statistics_mean_f_sptr
“”"
return _howtoren.bin_statistics_mean_f(*args)