Problem with new blocks

Hi everybody!

I try to create my own block in a current project (rfid). So there are
currently other blocks which works correctly.
I had create my file.cc, my file.h and add the part that i need to add
in
the file rfid.i

After that, I enter the following command line:

./configure
make
make configure

But when i use my application.py i have this error:

*Traceback (most recent call last):
File “./test.py”, line 215, in
main ()
File “./test.py”, line 65, in main
tb = my_top_block()
File “./test.py”, line 43, in init
d1 = rfid.test()
AttributeError: ‘module’ object has no attribute ‘test’
*
Someone know why?

Thank you a lot for your time!

Loic -

That is a Python error, telling you that your class ‘rfid’ doesn’t have
the
member ‘test’. This is an error in your code.

How familiar are you with Python? You may want to read up on some
Python
documentation to help you understand how that all works.

Cheers,
Ben

Hi Ben

Thank you for your help.
I am really familiar with Python, i think is more an error with the file
.i
or another error but i don’t find my error :frowning:

Le 14 mars 2012 21:34, Ben H. [email protected] a crit :

On 03/16/2012 02:37 PM, Loic D. wrote:

    need to add in the file rfid.i
      File "./test.py", line 215, in <module>

Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page
Did you change your Makefile.am? You should add your .i, .h and .cc file
into the Makefile.am.

Aha - you suspect a SWIG error? That may indeed be the issue.

Check out Martin’s advice, and let us know how it goes. Have you
generally
tested the SWIG for your class?

Cheers,
Ben

On Tue, Mar 13, 2012 at 01:37:48PM -0300, Loic D. wrote:

make
make configure

Just making sure here, but do you also do ‘make install’ or at least
bend the PYTHONPATH to your temporary libraries?

MB

AttributeError: ‘module’ object has no attribute ‘test’

Someone know why?

Thank you a lot for your time!


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


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

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

Sorry, last e-mail should have said, “Check out Martin’s and Zhonghua’s
advice…”

Cheers,
Ben

Hi Ben,

Did you solve the problem I am facing the same problem

Hi Ben,

I didn’t find my error, so i decide to proceed with another method:

I use a project which works.
I create the file : rfid_file.cc and rfid_file.h
I modify the file rfid.i

I use the command: ./boostrap
./configure
./make
./make configure

And i have no errors :-),

But i have an error after that, when i import my block in my file .py.
*
Traceback (most recent call last):
File “./test.py”, line 20, in
from gnuradio import rfid
File “/usr/local/lib/python2.7/dist-packages/gnuradio/rfid.py”, line
24,
in
_rfid = swig_import_helper()
File “/usr/local/lib/python2.7/dist-packages/gnuradio/rfid.py”, line
20,
in swig_import_helper
_mod = imp.load_module(‘_rfid’, fp, pathname, description)
ImportError: /usr/local/lib/python2.7/dist-packages/gnuradio/_rfid.so:
undefined symbol: _Z14rfid_make_fileiP5state
*

Do you know why?

  • This is my file: rfid_file.cc

*#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <rfid_file.h>
#include <gr_io_signature.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#ifndef READER_VARS
#include “reader_vars.h”
#endif

#include <sys/time.h>
#include <float.h>
#include <signal.h>
#include <math.h>

bool trigger_next_cycle = false;

static itimerval timer;

rfid_file_sptr
rfid_make_file(int dec2, state * reader_state2)
{
return rfid_file_sptr(new rfid_file(dec2, reader_state2));
}

rfid_file::rfid_file(int dec2, state * reader_state2):
gr_block(“rfid_file”, gr_make_io_signature (1, 1, sizeof(float)),
gr_make_io_signature (1,1,sizeof(float)))
{

printf(“test1”);

}

rfid_file::~rfid_file()
{

}

int
rfid_file::general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)

{
const float * in = (const float *)input_items[0];
float * out = (float * )output_items[0];
int nout = 0;
int debug_out_cnt = 0;

out[0] = in[0];
consume_each(noutput_items);
printf(“test2”);

return nout;
}

void
rfid_file::forecast (int noutput_items, gr_vector_int
&ninput_items_required)
{
unsigned ninputs = ninput_items_required.size ();
for (unsigned i = 0; i < ninputs; i++){
ninput_items_required[i] = noutput_items;
}
}*

  • This is my file rfid_file.h

*#ifndef INCLUDED_RFID_FILE_H
#define INCLUDED_RFID_FILE_H

#include <gr_block.h>
#include <gr_message.h>
#include <gr_msg_queue.h>

#include “reader_vars.h”

class rfid_file;
typedef boost::shared_ptr<rfid_file> rfid_file_sptr;

rfid_file_sptr
rfid_make_file (int dec2, state * reader_state2 );

class rfid_file : public gr_block
{
private:
friend rfid_file_sptr rfid_make_file(int dec2, state * reader_state2);

rfid_file(int dec2, state * reader_state2);

state * d_reader_state2;

void forecast (int noutput_items, gr_vector_int
&ninput_items_required);

public:
~rfid_file();
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);

};

#endif*

  • And this is my file: rfid.i

*%include “exception.i”
%include “gnuradio.i” // the common stuff

%{
#include “gnuradio_swig_bug_workaround.h” // mandatory bug fix
#include “rfid_clock_recovery_zc_ff.h”
#include “rfid_cmd_gate.h”
#include “rfid_gen2_reader.h”
#include “rfid_reader_decoder.h”
#include “rfid_file.h”
%}

//-----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(rfid, reader_decoder);

rfid_reader_decoder_sptr
rfid_make_reader_decoder (float us_per_sample, float tari);

class rfid_reader_decoder: public gr_sync_block{

rfid_reader_decoder (float us_per_sample, float tari);

public:
~rfid_reader_decoder();
gr_msg_queue_sptr get_log() const;

};

//-----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(rfid, cmd_gate);

rfid_cmd_gate_sptr rfid_make_cmd_gate (int dec, state * reader_state);

class rfid_cmd_gate: public gr_block{

rfid_cmd_gate (int dec, state * reader_state);

public:
~rfid_cmd_gate();

};

//-----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(rfid, file);

rfid_file_sptr rfid_make_file (int dec2, state * reader_state2);

class rfid_file: public gr_block{

rfid_file (int dec2, state * reader_state2);

public:
~rfid_file();

};

//-----------------------------------------------------------------

GR_SWIG_BLOCK_MAGIC(rfid, gen2_reader);

rfid_gen2_reader_sptr rfid_make_gen2_reader (int dec, int interp, int
miller, bool elg, int dev_corr);

class rfid_gen2_reader: public gr_block{

rfid_gen2_reader (int dec, int interp, int miller, bool elg, int
dev_corr);

public:
~rfid_gen2_reader();
state * STATE_PTR;
gr_msg_queue_sptr get_log() const;

};

//-----------------------------------------------------------------
GR_SWIG_BLOCK_MAGIC(rfid, clock_recovery_zc_ff);

rfid_clock_recovery_zc_ff_sptr
rfid_make_clock_recovery_zc_ff(int samples_per_pulse, int interp_factor,
float us_per_sample, float blf, bool elg);

class rfid_clock_recovery_zc_ff: public gr_block{
rfid_clock_recovery_zc_ff(int samples_per_pulse, int interp_factor,
float
us_per_sample, float blf, bool elg);

public:
~rfid_clock_recovery_zc_ff();

};
*

Btw, thank you a lot for your help!

Le 16 mars 2012 14:18, Ben H. [email protected] a crit :