Reconnecting Flowgraph with (self, 0) in a Hierarchical block

Hello, dear community,
Does somebody know how to reconnect (self,0) of a Hierarchical block,
after
call of disconnect_all()

Problem:::
The flowgraph with GRC looks as: gr_vector_source -> gr_multiply_const
->
Pad_Sink
For some reason I need to reconnect the gr_vector_source within my
python
script.

Case1: if I try to disconnect it alone by self.disconnect(…):
self.disconnect((self.data_vec_source, 0),
(self.gr_multiply_const_vxx_0_0, 0))
I get error:
return _gnuradio_swig_py_runtime.gr_hier_block2_sptr_disconnect(self,
*args)
ValueError: cannot disconnect edge vector_source_b(53):0-> ->[…], not
found

Case2: if I call disconnect_all() it does disconnect all, but afterward
when
trying to reconnect and call
self.connect((self.gr_multiply_const_vxx_0_0, 0), (self, 0))
I get error:
return _gnuradio_swig_py_runtime.gr_hier_block2_sptr_connect(self,
*args)
ValueError: output port 0 out of range for multiply_const_vcc(18)

How is it correct to reconnect (self,0) to Hierarchical flowgraph?

I hope very much somebody knows the answer,
With best regards from sunny Bremen,
AnDis

Hello, dear all
I just reproduced the case with very basic setup, found a way around
problem, post here so main developers can adopt the gnuradio source.

What I learned:

  1. in prior to disconnect() avoid to re-assign vector value, since
    otherwise
    the disconenct() dosn’t find the old pointer and fails
  2. the hier_block.disconnect_all() has an internal error, in that after
    its
    call, one cannot add itself to flowgraph any more (needed for
    hierarchical
    blocks). I guess within the file gr_hier_block2_detail.cc, function
    void
    gr_hier_block2_detail::disconnect_all()
    , the code
    d_outputs.clear();
    is deleting too much. It would be nice if somebody would fix it.

So now, as soon as I got the 1st point, I just skip using
disconnect_all(),
doing disconnect() to block by block.

P.S. if somebody has a better idea how to restart a flowgraph with new
vector_source data, not doing full disconnect+connect cycle, please
please
let me know. And as a nex-to-do feature it would be very comfortable to
have
in gnuradio :slight_smile:

Good luck,
Andis

====TEST_FILES====================================

==================================================

====showcase_hier_block_disconnect_w.py
#!/usr/bin/env python
##################################################

Gnuradio Python Flow Graph

Title: Hierarchical block sample

Author: Andis

Description: Hier block to disconnect to showcase problems

Generated: Wed Apr 13 12:09:16 2011

##################################################

from gnuradio import gr
from gnuradio.gr import firdes

class showcase_hier_block_disconnect(gr.hier_block2):

def __init__(self, parameter_multiply_const=1,

parameter_data_src=(1,1,1,1)):
gr.hier_block2.init(
self, “Hierarchical block sample”,
gr.io_signature(0, 0, 0),
gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
)

    ##################################################
    # Parameters
    ##################################################
    self.parameter_multiply_const = parameter_multiply_const
    self.parameter_data_src = parameter_data_src

    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 32000

    ##################################################
    # Blocks
    ##################################################
    self.gr_multiply_const_vxx_0 =

gr.multiply_const_vcc((parameter_multiply_const, ))

self.gr_vector_source_x_0 =

gr.vector_source_c((parameter_data_src), False, 1)
self.gr_vector_source_x_0 = gr.vector_source_c(range(1,64),
False,
1)

    ##################################################
    # Connections
    ##################################################
    self.connect((self.gr_multiply_const_vxx_0, 0), (self, 0))
    self.connect((self.gr_vector_source_x_0, 0),

(self.gr_multiply_const_vxx_0, 0))

def set_parameter_multiply_const(self, parameter_multiply_const):
    self.parameter_multiply_const = parameter_multiply_const
    self.gr_multiply_const_vxx_0.set_k((self.parameter_multiply_const,

))

def set_parameter_data_src(self, parameter_data_src):
    self.parameter_data_src = parameter_data_src

def set_samp_rate(self, samp_rate):
    self.samp_rate = samp_rate

def reconnect(self, iter_id):
    self.disconnect_all()
    #self.disconnect((self.gr_vector_source_x_0, 0),

(self.gr_multiply_const_vxx_0, 0))
#self.disconnect((self.gr_multiply_const_vxx_0, 0), (self, 0))
self.gr_vector_source_x_0 =
gr.vector_source_c(range(iter_id,iter_id+63), False, 1)
self.connect((self.gr_multiply_const_vxx_0, 0), (self, 0))
self.connect((self.gr_vector_source_x_0, 0),
(self.gr_multiply_const_vxx_0, 0))

===================================

======showcase_hier_block_disconnect_tb_w.py
#!/usr/bin/env python
##################################################

Gnuradio Python Flow Graph

Title: Showcase Hier Block Disconnect Tb

Generated: Wed Apr 13 12:09:56 2011

##################################################

execfile("/home/andis/.grc_gnuradio/showcase_hier_block_disconnect_w.py")
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.gr import firdes
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx

class showcase_hier_block_disconnect_tb(grc_wxgui.top_block_gui):

def __init__(self):
    grc_wxgui.top_block_gui.__init__(self, title="Showcase Hier 

Block
Disconnect Tb")
_icon_path =
“/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png”
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 32000

    ##################################################
    # Blocks
    ##################################################
    self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
    self.showcase_hier_block_disconnect_0 =

showcase_hier_block_disconnect(

parameter_data_src=(0,0,1),

        parameter_data_src=range(1,1,100000000),
    )
    self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
        self.GetWin(),
        title="Scope Plot",
        sample_rate=samp_rate,
        v_scale=0,
        v_offset=0,
        t_scale=0,
        ac_couple=False,
        xy_mode=False,
        num_inputs=1,
    )
    self.Add(self.wxgui_scopesink2_0.win)

    ##################################################
    # Connections
    ##################################################
    self.connect((self.showcase_hier_block_disconnect_0, 0),

(self.gr_multiply_const_vxx_0, 0))
self.connect((self.gr_multiply_const_vxx_0, 0),
(self.wxgui_scopesink2_0, 0))

def set_samp_rate(self, samp_rate):
    self.samp_rate = samp_rate
    self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)

def reconnect(self, iter_id):
    self.showcase_hier_block_disconnect_0.reconnect(iter_id)
    self.disconnect_all()
    self.connect((self.showcase_hier_block_disconnect_0, 0),

(self.gr_multiply_const_vxx_0, 0))
self.connect((self.gr_multiply_const_vxx_0, 0),
(self.wxgui_scopesink2_0, 0))

if name == ‘main’:
parser = OptionParser(option_class=eng_option, usage="%prog:
[options]")
(options, args) = parser.parse_args()
tb = showcase_hier_block_disconnect_tb()
tb.Run(True)

===================================

=====showcase_hier_block_disconnect_main.py
#!/usr/bin/env python
##################################################

Gnuradio Python Flow Graph

Title: Showcase Hier Block Disconnect Tb

Generated: Wed Apr 13 12:09:56 2011

##################################################

from showcase_hier_block_disconnect_tb_w import
showcase_hier_block_disconnect_tb

from gnuradio.eng_option import eng_option
from optparse import OptionParser
from threading import Thread
import time

##################################################

THREADS

##################################################

################## THREAD v2 Single AIS block #
class GUIapp(Thread):
def init (self):
Thread.init(self)
self.tb = showcase_hier_block_disconnect_tb()
def run(self):
self.tb.Run(False)
#self.tb.start()

##################################################

MAIN

##################################################

if name == ‘main’:
parser = OptionParser(option_class=eng_option, usage="%prog:
[options]")
(options, args) = parser.parse_args()

guiapp = GUIapp()

##initial run
print(“here”)
guiapp.start()
guiapp.tb.start()
guiapp.tb.wait()

#changing data vector source
for i in range(0,10000):
guiapp.tb.lock()
guiapp.tb.reconnect(i)
guiapp.tb.unlock()
guiapp.tb.start()
guiapp.tb.wait()
print ("done with case " + str(i) + “”)
#time.sleep(0.1)
print “Done”
guiapp.tb.stop(); guiapp.tb.wait(); guiapp.tb._frame.Destroy()

====================================

2011/4/12 Andis D.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs