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.