def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined") AttributeError: No constructor defined

StackOverflow https://stackoverflow.com/questions/18092242

Question

I am trying to create a new DSP block in gnuradio using gr_modtool.py. gnuradio version is 3.3.0. I have following code in abc.h file in include folder

 ifndef INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H
 #define INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H
 #include <gr_block.h>

 namespace gr {
   namespace energydetector {
 class ENERGYDETECTOR_API local_sensing_ff : virtual public gr_block
 {
  private:

  public:
    typedef boost::shared_ptr<local_sensing_ff> sptr;
    float d_pfa; int d_L; int d_samples;    
    static sptr make(float pfa=0.01,int L=16,int samples=1000);
    virtual void set_pfa(float input_a) { d_pfa = input_a; }  
    virtual int get_pfa() { return d_pfa; } 
    virtual void set_L(int input_b) { d_L = input_b; }  
    virtual int get_L() { return d_L; } 
    virtual void set_samples(int input_c) { d_samples = input_c; }  
   virtual int get_samples() { return d_samples; } 
     };
    } // namespace energydetector
  } // namespace gr
  #endif /* INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H */

Implementation class for above header file is as:

 #ifndef INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H
 #define INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H

 #include <energy-detector/local_sensing_ff.h>

 namespace gr {
  namespace energydetector {
   class local_sensing_ff_impl : public local_sensing_ff
   {
   private:
      float d_pfa; int d_L; int d_samples;  
  public:
    local_sensing_ff_impl(float pfa,int L,int samples);
    ~local_sensing_ff_impl();
    void set_pfa(float input_a) { d_pfa = input_a; }  
    int get_pfa() { return d_pfa; } 
    void set_L(int input_b) { d_L = input_b; }  
    int get_L() { return d_L; } 
    void set_samples(int input_c) { d_samples = input_c; } 
    int get_samples() { return d_samples; }
        int general_work(int noutput_items,
           gr_vector_int &ninput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
   };
  } // namespace energy-detector
 } // namespace gr
#endif /* INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H */

And SWIG file is abc.i as

 #define ENERGY_DETECTOR_API
 %include "gnuradio.i"          // the common stuff
 %include "energydetector_swig_doc.i"
 %{
    #include "energydetector/local_sensing_ff.h"
  %}

  %include "energydetector/local_sensing_ff.h"
  GR_SWIG_BLOCK_MAGIC2(energydetector, local_sensing_ff);

It build successfully but while executing I get following error :

def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
AttributeError: No constructor defined

Please help me out to debug this.

Was it helpful?

Solution

Finally i get to know that it was due to version not supported. gr_modtool.py was only supported by GNURadio 3.6 or above.

Although we can build the block and use it in GRC but not sure why it can't work. It must be the code structure that is generated by gr_modtool.py is not works with version 3.3.0

so anyone who came to this question make sure you have GNURadio 3.6 and above. But if anyone has solved this either modifying gr_modtool.py or any code, then please let us know within this question.

OTHER TIPS

when I remove "from gnuradio.gr import *" from my code this problem goes away

SWIG won't produce a constructor for a class that doesn't have a public constructor or is abstract.

See http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_nn9

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top