# Problems in locking and unlocking the flow-graph

**URL:** <https://www.ruby-forum.com/t/problems-in-locking-and-unlocking-the-flow-graph/210121>\
**Category:** GNU Radio\
**Created:** [July 31, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/problems-in-locking-and-unlocking-the-flow-graph/210121 "2011-07-31T15:39:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [July 31, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/problems-in-locking-and-unlocking-the-flow-graph/210121/1 "2011-07-31T15:39:59Z")

</div>

hi,  
I am designing a transmitter which needs to transmit two different types  
,  
tone (of 1k frequency) and data (2k & 3k frequency).Both of them take  
user  
input, does processing and produce output on sound card of the laptop  
(am  
not using usrp).

I have implemented this all in a single flow graph and used lock and  
unlock  
to reconfigure the flow-graph.But it gets to a hanging state and looks  
like  
it is waiting for something in queue. I did try to use gr.message(1)  
before  
locking , which locked and unlocked the flow-graph but the problem is  
that  
after using gr.message(1), self.src does not get further data from the  
queue and without using it, it is stucked.

plz find some way out for me to transmit tone and data as required.

class tx\_graph(gr.top\_block):

```
def __init__ (self):
    gr.top_block. __init__ (self)

    self.src = gr.message_source(gr.sizeof_char, msgq_limit)

#
# tone_blocks // tone processing blocks 

```

here  
#

```
#
# data_blocks // data processing blocks 

```

here  
#

```
self.sink = audio.sink(audio_rate,"plughw:0,0")
self.connect(self.src,//data_blocks//,self.sink) # assume that

```

initially data is being transmitted

```
def tone_transmit(self):
self.lock()
self.disconnect(self.src,//data_blocks//,self.sink)
self.connect(self.src,//tone_blocks//,self.sink)
self.unlock()

```

def main():

fg=tx\_graph()  
fg.start()

```
while True :
    // assume first only data is being tranmitted

        try:

        message = raw_input("Enter a message to transmit (Ctrl-D to

```

exit): ")  
msg64 = base64.standard\_b64encode(message)  
print “Encoding message= %s to base64= %s” %  
(message,msg64)

```
                payload = 

```

clock\_sync+sync+encode\_6b\_8b(msg64)+stop\_sync  
pkt = struct.pack(‘%iB’ % (len(payload)),\*payload)

```
                msg = gr.message_from_string(pkt)

                fg.src.msgq().insert_tail(msg)

        except EOFError:
            print "\nExiting."
            fg.src.msgq().insert_tail(gr.message(1))
            fg.wait()

// assume now only tone is being transmitted

        try:
        fg.tone_transmit()
                message = raw_input(" transmit a 5ms tone (Ctrl-D to

```

exit): ")  
pkt = struct.pack(‘B’, 0xff)

```
                msg = gr.message_from_string(pkt)
                fg.src.msgq().insert_tail(msg)

        except EOFError:
            print "\nExiting."
            fg.src.msgq().insert_tail(gr.message(1))
            fg.wait()

```

if **name** == ‘ **main** ’: # main python entry here  
try:  
main()  
except KeyboardInterrupt:  
pass

–  
_Niaz A._

We are always more anxious to be distinguished for a talent which we do  
not  
possess, than to be praised for the fifteen which we do possess\* :  
Mark  
Twain [http://thinkexist.com/quotes/mark\_twain/](http://thinkexist.com/quotes/mark_twain/)\*

- [http://thinkexist.com/quotes/mark\_twain/](http://thinkexist.com/quotes/mark_twain/)\*
