GNU Radio ValueError: Unable to coerce endpoint
<p>I'm using GNU Radio Companion to build my OOT block to do sequential energy detection. I installed it successfully, but when I run it in my flowgraph there are an error: </p>

<p>ValueError: Unable to coerce endpoint</p>

<p>But after I connect the flow graph again, it come up with another error:</p>

<pre><code>Using Volk machine: avx_64_mmx_orc

Traceback (most recent call last):

  File "/home/mint/Documents/test_sensor/energy_de/seq_energy.py", line 92, in &lt;module&gt;

    tb = seq_energy()

  File "/home/mint/Documents/test_sensor/energy_de/seq_energy.py", line 62, in __init__

    self.sensing_seq_energy_0 = sensing.seq_energy(256, 20, 0.01, 0.1, 0.084)
AttributeError: 'module' object has no attribute 'seq_energy'
</code></pre>

<p>seq_energy.py:</p>

<pre><code>from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import sensing
import wx

class seq_energy(grc_wxgui.top_block_gui):

    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Seq Energy")
        _icon_path = "/home/mint/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2000000
        self.freq = freq = 250000

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_scopesink2_1_0_0_0 = scopesink2.scope_sink_f(
            self.GetWin(),
            title="Scope Plot2",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_1_0_0_0.win)
        self.sensing_seq_energy_0 = sensing.seq_energy(256, 20, 0.01, 0.1, 0.084)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.sensing_seq_energy_0, 0))    
        self.connect((self.sensing_seq_energy_0, 0), (self.wxgui_scopesink2_1_0_0_0, 0))    


    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
        self.wxgui_scopesink2_1_0_0_0.set_sample_rate(self.samp_rate)

    def get_freq(self):
        return self.freq

    def set_freq(self, freq):
        self.freq = freq

if __name__ == '__main__':
    parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
    (options, args) = parser.parse_args()
    tb = seq_energy()
    tb.Start(True)
    tb.Wait()
</code></pre>

<p>I create the block 'seq_energy' which contain four files:</p>

<p>1.seq_energy.h</p>

<pre><code>#ifndef INCLUDED_SENSING_SEQ_ENERGY_H
#define INCLUDED_SENSING_SEQ_ENERGY_H

#include &lt;sensing/api.h&gt;
#include &lt;gnuradio/sync_block.h&gt;

namespace gr {
  namespace sensing {

    /*!
     * \brief &lt;+description of block+&gt;
     * \ingroup sensing
     *
     */
    class SENSING_API seq_energy : virtual public gr::sync_block
    {
     public:
      typedef boost::shared_ptr&lt;seq_energy&gt; sptr;

      /*!
       * \brief Return a shared_ptr to a new instance of sensing::seq_energy.
       *
       * To avoid accidental use of raw pointers, sensing::seq_energy's
       * constructor is in a private implementation
       * class. sensing::seq_energy::make is the public interface for
       * creating new instances.
       */
      static sptr make(size_t number, int slots,float beta,float alpha, float noise);

      virtual float beta() const = 0;
      virtual void set_beta(float beta) = 0;
      virtual float alpha() const = 0;
      virtual void set_alpha(float alpha) = 0;
      virtual float noise() const = 0;
      virtual void set_noise(float noise) = 0;
    };

  } // namespace sensing
} // namespace gr
</code></pre>

<p>2.seq_energy_impl.h</p>

<pre><code>#ifndef INCLUDED_SENSING_SEQ_ENERGY_IMPL_H
#define INCLUDED_SENSING_SEQ_ENERGY_IMPL_H

#include &lt;sensing/seq_energy.h&gt;

namespace gr {
  namespace sensing {

    class seq_energy_impl : public seq_energy
    {
     private:
      size_t d_number;
      int d_slots;
      float d_beta, d_alpha, d_noise;

     public:
      seq_energy_impl(size_t number, int slots,float beta,float alpha, float noise);
      ~seq_energy_impl();

      void forecast (int noutput_items, gr_vector_int &amp;ninput_items_required);
      float beta() const { return d_beta; }
      void set_beta(float beta) { d_beta = beta; }
      float alpha() const { return d_alpha; }
      void set_alpha(float alpha) { d_alpha = alpha; }
      float noise() const { return d_noise; }
      void set_noise(float noise) { d_noise = noise; }

      // Where all the action really happens
      int work(int noutput_items,
           gr_vector_const_void_star &amp;input_items,
           gr_vector_void_star &amp;output_items);
    };

  } // namespace sensing
} // namespace gr
</code></pre>

<p>3.seq_energy_impl.cc</p>

<pre><code>#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include &lt;gnuradio/io_signature.h&gt;
#include "seq_energy_impl.h"

namespace gr {
  namespace sensing {

    seq_energy::sptr
    seq_energy::make(size_t number, int slots,float beta,float alpha, float noise)
    {
      return gnuradio::get_initial_sptr
        (new seq_energy_impl(number, slots, beta, alpha, noise));
    }

    /*
     * The private constructor
     */
    seq_energy_impl::seq_energy_impl(size_t number, int slots,float beta,float alpha, float noise)
      : gr::sync_block("seq_energy",
              gr::io_signature::make(1, 1, number*sizeof(float)),
              gr::io_signature::make(1, 1, sizeof(float))),
        d_number(number),d_slots(slots),d_beta(beta),d_alpha(alpha),d_noise(noise)
    {}

    /*
     * Our virtual destructor.
     */
    seq_energy_impl::~seq_energy_impl()
    {
    }

    int
    seq_energy_impl::work(int noutput_items,
              gr_vector_const_void_star &amp;input_items,
              gr_vector_void_star &amp;output_items)
    {
        const float *in = (const float *) input_items[0];
        float *out = (float *) output_items[0];


        for(int i = 0; i &lt; noutput_items; i++){
            float sum[i];
            for(int j = 0; j &lt; (int)d_number;j++){
                sum[i] += in[i*d_number];
            }
            if(sum[i] &gt; d_alpha){
              out[i] =1.0;
            }
            else if(sum[i] &lt; d_beta){
              out[i] = 0.0;
            }
            else if(sum[i] &gt; d_noise){
              out[i] = 1.0;
            }
            else{
              out[i] = 0.0;
            }
        }
        return noutput_items;
    }

  } /* namespace sensing */
} /* namespace gr */
</code></pre>

<p>4.enery_impl.xml</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;block&gt;
  &lt;name&gt;seq_energy&lt;/name&gt;
  &lt;key&gt;sensing_seq_energy&lt;/key&gt;
  &lt;category&gt;sensing&lt;/category&gt;
  &lt;import&gt;import sensing&lt;/import&gt;
  &lt;make&gt;sensing.seq_energy($number, $slots, $beta, $alpha, $noise)&lt;/make&gt;
  &lt;callback&gt;set_beta($beta)&lt;/callback&gt;
  &lt;callback&gt;set_alpha($alpha)&lt;/callback&gt;
  &lt;callback&gt;set_noise($noise)&lt;/callback&gt;

  &lt;param&gt;
    &lt;name&gt;Number of samples&lt;/name&gt;
    &lt;key&gt;number&lt;/key&gt;
    &lt;type&gt;int&lt;/type&gt;
  &lt;/param&gt;
 &lt;param&gt;
    &lt;name&gt;Maximum sensing slots&lt;/name&gt;
    &lt;key&gt;slots&lt;/key&gt;
    &lt;type&gt;int&lt;/type&gt;
  &lt;/param&gt;
 &lt;param&gt;
    &lt;name&gt;Beta threshold&lt;/name&gt;
    &lt;key&gt;beta&lt;/key&gt;
    &lt;type&gt;float&lt;/type&gt;
  &lt;/param&gt;
 &lt;param&gt;
    &lt;name&gt;Alpha threshold&lt;/name&gt;
    &lt;key&gt;alpha&lt;/key&gt;
    &lt;type&gt;float&lt;/type&gt;
  &lt;/param&gt;
 &lt;param&gt;
    &lt;name&gt;Estimated noise power&lt;/name&gt;
    &lt;key&gt;noise&lt;/key&gt;
    &lt;type&gt;float&lt;/type&gt;
  &lt;/param&gt;

  &lt;sink&gt;
    &lt;name&gt;in&lt;/name&gt;
    &lt;type&gt;float&lt;/type&gt;
  &lt;/sink&gt;


  &lt;source&gt;
    &lt;name&gt;out&lt;/name&gt;
    &lt;type&gt;float&lt;/type&gt;
  &lt;/source&gt;
&lt;/block&gt;
</code></pre>

<p>Besides,I want to know </p>

<ul>
<li><p>whether do I need to add this part in impl.h file:</p>

<p>float beta() const { return d_beta; }</p>

<p>void set_beta(float beta) { d_beta = beta; }</p>

<p>Why we need to add this part? only because beta is a private variable and   we  need to use it in impl.cc file?</p></li>
<li><p>Is there any difference between int and size_t? Can I change 'size_t number 'to 'int number'?</p></li>
</ul>