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 Islam
<address@hidden> wrote:
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 Islam
Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.
--
Muhammad Nazmul Islam
Graduate Student
Electrical & Computer Engineering
Wireless Information & Networking Laboratory
Rutgers, USA.