Dynamic flow graph control

Hello,

I have an application where I need to collect the data for 5 seconds
from
the USRP source and do offline processing for 5 seconds in a repeated
manner. I am planning to use the lock & unlock features of the gnuradio
to
obtain my goals. The major part of my code is given below:

class SingleSource(grc_wxgui.top_block_gui):

self.source =

Source block

self.throttle =

throttle

self.file_sink = gr.file_sink(gr.sizeof_gr_complex*1,
“Data.dat”) # File Sink
self.null_sink =

Null sink

self.connect((self.source, 0), (self.throttle,
0))
self.connect((self.throttle, 0), (self.sink, 0))

def reconf1(self):
self.disconnect((self.gr_throttle_0,
0),(self.gr_file_sink_0, 0)) # Disconnecting the throttle &
the
file sink
self.connect((self.gr_throttle_0, 0),
(self.gr_null_sink_0,
0)) # re-connecting the throttle & the null sink

def reconf2(self):
self.disconnect((self.gr_throttle_0,
0),(self.gr_null_sink_0, 0)) # disconnecting the throttle &
the
null sink
self.connect((self.gr_throttle_0,
0),(self.gr_file_sink_0,
0)) # re-connecting the throttle & the file sink

if name == ‘main’:

tb = SingleSource()
    var = 1

tb.start()

Flow graph starts

    for loop in range(0,2):

sleep(5)

Collects the data in the file sink

tb.lock()

tb.reconf1() #
Flowgraph gets locked & reconfigured and unlocked

tb.unlock() #
Now,
data is going to the null sink. I don’t need this data
sleep(5)

… #
Offline
processing
open(“SineData.dat”,‘w’).close() #
I
WANT TO ERASE THE DATA IN THE FILE SINK AFTER PROCESSING

SO THAT THE FILE SIZE DOES NOT BIGGER

            tb.lock()
            tb.reconf2()                                       # 

File
sink is getting reconnected so that I can collect the data in the next
run

            tb.unlock()

Now, the problem is: the file size of “SineData.dat” should not grow
with
each loop since I am using open(“SineData.dat”,‘w’).close() . In each
new
loop, I expect the file to only contain the latest information and not
the
previous ones. However, I am finding that the file size keeps growing
with
each loop, i.e., the open(“SineData.dat”,‘w’).close() command is not
working.

Any suggestion will be very appreciated.

Thanks,

Nazmul


Muhammad Nazmul I.

Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.

Hi,

I am trying to simplify my previous email for clarification. I am
looking
to resolve the following issue:

I have two flowgraphs:

  1. USRP Source --> File Sink # self.file_sink =
    gr.file_sink(gr.sizeof_gr_complex*1, “Data.dat”)
  2. USRP Source --> Null Sink

I have defined both of them inside a class. I use unlock --> disconnect
–>
connect --> lock to switch from one flow graph to the other. When I
connect
USRP–>Null, I work on the stored data of “Data.dat” file. Thereafter, I
want to clear the data of the “Data.dat” file. I use the following line
of
code to obtain my goal:

open(“Data.dat”,‘w’).close()

However, this command does not seem to erase the data of “Data.dat”
file,
i.e., when I run flow graph 1 again, the previous file does not get
erased.
The file size of “Data.dat” keeps growing with each run of flow graph.

How can I erase the contents of the file sink before I switch to flow
graph
#1?

Any suggestion will be very appreciated. Sorry for sending two emails on
the same matter.

Thanks,

Nazmul

On Sun, Aug 5, 2012 at 6:46 PM, Nazmul I.
[email protected]wrote:

Null sink

(self.gr_null_sink_0, 0)) # re-connecting the throttle & the

sleep(5)

            tb.unlock()

Thanks,
Rutgers, USA.


Muhammad Nazmul I.

Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.

This might be happening because “gr.file_sink” is not closing the passed
file handle until its destructed. I checked “gr_file_sink_base”'s source
and various functions like open, close and unbuffered writes are
supported. Try playing around with these(I haven’t used these things
yet).

http://www.reynwar.net/gnuradio/sphinx/gr/sink_blk.html (Check
gr.file_sink section)


Regards
Sreeraj Rajendran
http://home.iitb.ac.in/~rsreeraj


From: Nazmul I. [email protected]
To: GNURadio D.ion List [email protected]
Sent: Monday, 6 August 2012 8:52 PM
Subject: Re: [Discuss-gnuradio] Dynamic flow graph control

Hi,

I am trying to simplify my previous email for clarification. I am
looking to resolve the following issue:

I have two flowgraphs:

  1. USRP Source --> File Sink # self.file_sink =
    gr.file_sink(gr.sizeof_gr_complex*1, “Data.dat”)
  2. USRP Source --> Null Sink

I have defined both of them inside a class. I use unlock --> disconnect
–> connect --> lock to switch from one flow graph to the other. When I
connect USRP–>Null, I work on the stored data of “Data.dat” file.
Thereafter, I want to clear the data of the “Data.dat” file. I use the
following line of code to obtain my goal:

open(“Data.dat”,‘w’).close()

However, this command does not seem to erase the data of “Data.dat”
file, i.e., when I run flow graph 1 again, the previous file does not
get erased. The file size of “Data.dat” keeps growing with each run of
flow graph.

How can I erase the contents of the file sink before I switch to flow
graph #1?

Any suggestion will be very appreciated. Sorry for sending two emails on
the same matter.

Thanks,

Nazmul

On Sun, Aug 5, 2012 at 6:46 PM, Nazmul I.
[email protected] wrote:

Hello,

self.null_sink = … # Null sink
self.connect((self.gr_throttle_0, 0),(self.gr_file_sink_0, 0)) # re-connecting
the throttle & the file sink
sleep(5) # Collects the data in the file sink

Muhammad Nazmul I.

Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.


Muhammad Nazmul I.

Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.

Thanks a lot, Sreeraj!! You are right. I made it work using
file_sink.close() and file_sink.open() command.

Best,

Nazmul

On Mon, Aug 6, 2012 at 12:39 PM, sreeraj r [email protected]
wrote:

Sreeraj Rajendran
I am trying to simplify my previous email for clarification. I am looking
connect USRP–>Null, I work on the stored data of “Data.dat” file.
graph #1?

“Data.dat”) # File Sink
0),(self.gr_file_sink_0, 0)) # Disconnecting the throttle & the
0)) # re-connecting the throttle & the file sink

Flow graph starts

tb.unlock() # Now,
tb.reconf2() # File

Graduate Student
Graduate Student


Muhammad Nazmul I.

Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.

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