Custom Block Issue

I am trying to create a custom block that does energy detection. I used
the
gr-modtool.py to generate the appropriate directory and files and added
my
algorithm and necessary code to the header and cc. I also added the XML
file for the GRC It compiled without error but when I tried testing it
out,
I got this error:

linux; GNU C++ version 4.6.3; Boost_104601;
UHD_003.004.002-181-g25649781

Traceback (most recent call last):
File “/home/jonfox/spectrum_sensing_test.py”, line 21, in
import specsense
File “/usr/local/lib/python2.7/dist-packages/specsense/init.py”,
line
45, in
from specsense_swig import *
File
“/usr/local/lib/python2.7/dist-packages/specsense/specsense_swig.py”,
line
26, in
_specsense_swig = swig_import_helper()
File
“/usr/local/lib/python2.7/dist-packages/specsense/specsense_swig.py”,
line
22, in swig_import_helper
_mod = imp.load_module(’_specsense_swig’, fp, pathname, description)
ImportError: libgnuradio-specsense.so: cannot open shared object file:
No
such file or directory

specsense is the module I created with the modtool but I did not modify
the
swig file. Any ideas on what I did wrong here?

Also, it seems that my code for having a vector input does not hold up
and
I have to manually change the input type in the appropriate python
script
despite setting it in GRC already. Is there any documentation on adding
vector inputs and outputs?

Thanks,

-Jon Fox

On 07/27/2012 02:01 PM, Jonathan F. wrote:

import specsense
_mod = imp.load_module('_specsense_swig', fp, pathname, description)

ImportError: libgnuradio-specsense.so: cannot open shared object file: No
such file or directory

First off, does the file really exist, if not is it installed, but under
the wrong name or wrong directory?

If its there, sometimes running sudo ldconfig fixes issues like this.

specsense is the module I created with the modtool but I did not modify the
swig file. Any ideas on what I did wrong here?

Also, it seems that my code for having a vector input does not hold up and
I have to manually change the input type in the appropriate python script
despite setting it in GRC already. Is there any documentation on adding
vector inputs and outputs?

any code snippets with the problem that you can post?
-josh

On Fri, Jul 27, 2012 at 6:12 PM, Josh B. [email protected] wrote:

I got this error:
File
such file or directory


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page

Sudo ldconfig worked. Now I get this:

Traceback (most recent call last):
File “/home/jonfox/gnuradio/spectrum_sensing_test.py”, line 214, in

tb.Run(True)
File
“/usr/local/lib/python2.7/dist-packages/grc_gnuradio/wxgui/top_block_gui.py”,
line 76, in Run
self.start()
File
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/top_block.py”,
line 97, in start
self._tb.start(max_noutput_items)
File
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gnuradio_core_runtime.py”,
line 1768, in start
return _gnuradio_core_runtime.gr_top_block_sptr_start(self,
max_noutput_items)
RuntimeError: gr_buffer_add_reader: nzero_preload must be >= 0

I have looked up the last line in Google and found an email requesting
the
flow graph be attached (although it was a differenet user) so see
attached.

For the code snippets, let me start with this error.

File “/home/jonfox/gnuradio/spectrum_sensing_test.py”, line 213, in

tb = spectrum_sensing_test(freq=options.freq,
address=options.address,
samp_rate=options.samp_rate, gain=options.gain,
fft_vector=options.fft_vector)
File “/home/jonfox/gnuradio/spectrum_sensing_test.py”, line 142, in
init
self.connect((self.blks2_logpwrfft_x_0, 0),
(self.specsense_edetect_cl_ff_0, 0))
File
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/top_block.py”,
line 124, in connect
self._connect(points[i-1], points[i])
File
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/top_block.py”,
line 130, in _connect
dst_block.to_basic_block(), dst_port)
File
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gnuradio_core_runtime.py”,
line 1836, in primitive_connect
return
_gnuradio_core_runtime.gr_top_block_sptr_primitive_connect(self,
*args)
ValueError: itemsize mismatch: logpwrfft_c(17):0 using 2048,
edetect_cl_ff(13):0 using 4

This is the vector mismatch error despite the fact I have looked up
other
blocks and followed their code for vector implementation.

The .cc

specsense_edetect_cl_ff_sptr
specsense_make_edetect_cl_ff (size_t vlen)
{
return specsense_edetect_cl_ff_sptr (new specsense_edetect_cl_ff
(vlen));
}

static const int MIN_IN = 1; // mininum number of input streams
static const int MAX_IN = 1; // maximum number of input streams
static const int MIN_OUT = 1; // minimum number of output streams
static const int MAX_OUT = 1; // maximum number of output streams

specsense_edetect_cl_ff::specsense_edetect_cl_ff (size_t vlen)
: gr_block (“edetect_cl_ff”,
gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float) * vlen),
gr_make_io_signature (MIN_IN, MAX_OUT, sizeof (float) * vlen)),
d_vlen (vlen)
{
}

the .h

class specsense_edetect_cl_ff;
typedef boost::shared_ptr<specsense_edetect_cl_ff>
specsense_edetect_cl_ff_sptr;

SPECSENSE_API specsense_edetect_cl_ff_sptr specsense_make_edetect_cl_ff
(size_t vlen = 1);

/*!

  • \brief <+description+>

*/
class SPECSENSE_API specsense_edetect_cl_ff : public gr_block
{
friend SPECSENSE_API specsense_edetect_cl_ff_sptr
specsense_make_edetect_cl_ff (size_t vlen);

specsense_edetect_cl_ff (size_t vlen);

    size_t d_vlen;

the .xml

<?xml version="1.0"?> edetect_cl_ff specsense_edetect_cl_ff specsense import specsense specsense.edetect_cl_ff() Vec Length vlen 1 int $vlen > 0 in float $vlen out float $vlen

Anything else I should post?

On 07/30/2012 11:20 AM, Jonathan F. wrote:

file for the GRC It compiled without error but when I tried testing it
45, in
_mod = imp.load_module(’_specsense_swig’, fp, pathname, description)
the
-josh
File “/home/jonfox/gnuradio/spectrum_sensing_test.py”, line 214, in
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gnuradio_core_runtime.py”,
line 1768, in start
return _gnuradio_core_runtime.gr_top_block_sptr_start(self,
max_noutput_items)
RuntimeError: gr_buffer_add_reader: nzero_preload must be >= 0

Looks like thats what happens when history is initialized to something
<= 0. Perhaps something is not initialized in your app or defaulted to
zero?

Perhaps a set of filter taps is empty, they often affect how history()
is set

-josh

~/src/gnuradio/gnuradio-core/src/lib/runtime$ grep gr_buffer_add_reader
*
gr_buffer.cc:gr_buffer_add_reader (gr_buffer_sptr buf, int
nzero_preload, gr_block_sptr link)
gr_buffer.cc: throw std::invalid_argument(“gr_buffer_add_reader:
nzero_preload must be >= 0”);
gr_buffer.h: friend GR_CORE_API gr_buffer_reader_sptr
gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload,
gr_block_sptr link);
gr_buffer.h:gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload,
gr_block_sptr link=gr_block_sptr());
gr_buffer.h: gr_buffer_add_reader (gr_buffer_sptr buf, int
nzero_preload, gr_block_sptr link);
gr_buffer.i:%rename(buffer_add_reader) gr_buffer_add_reader;
gr_buffer.i:gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr
buf, int nzero_preload, gr_block_sptr link);
gr_flat_flowgraph.cc: detail->set_input(dst_port,
gr_buffer_add_reader(src_buffer, grblock->history()-1, grblock));
gr_flat_flowgraph.cc: detail->set_input(i,
gr_buffer_add_reader(src_buffer, block->history()-1, block));

Thanks. I completely forgot about the filters in the front of the
flowgraph. Removing them fixed the problem.

I still have not figured out the vector thing though.

-Jon

Mark this one resolved. I was just missing something from my XML file.