Sure. I don't know if you need an explanation about it (since the code is really ugly), but if you do, I'll gladly explain what I'm doing.
class detector(grc_wxgui.top_block_gui): def __init__(self, options): grc_wxgui.top_block_gui.__init__(self, title="Detector22") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.type = options['type'] if self.type=="CAL": print "##############################CALIBRATING##################################" elif self.type=="THR": print "#############GOING THROUGH THRESHOLD####################" self.threshold=options['threshold'] self.sensingSamples = options['sensingSamples'] self.fftSize = options['fftSize'] self.sampleRate = options['sampleRate'] self.packetSize = options['packetSize'] self.averageSize = self.sensingSamples #options['averageSize']=self.sensingSamples # SEMPRE IGUAL ATM self.emitterGain = options['emitterGain'] self.receiverGain = options['receiverGain'] self.frequency = options['frequency'] self.signalType = options['signalType'] self.fileName = options['fileName'] self.signalAmplitude = options['signalAmplitude'] self.primarySignalType = options['primarySignal'] ################################################## # Blocks ################################################## self.USRP_SOURCE = uhd.usrp_source( device_addr="serial=EBR11Y4B1", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.USRP_SOURCE.set_samp_rate(self.sampleRate) self.USRP_SOURCE.set_center_freq(self.frequency, 0) self.USRP_SOURCE.set_gain(self.receiverGain, 0) self.USRP_SOURCE.set_antenna("RX2", 0) if self.signalType=="SIGNAL": self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, self.sampleRate) self.USRP_SINK = uhd.usrp_sink(device_addr="serial=EBR11Y3B1",stream_args=uhd.stream_args(cpu_format="fc32",channels=range(1),),) self.USRP_SINK.set_samp_rate(self.sampleRate) self.USRP_SINK.set_center_freq(self.frequency, 0) self.USRP_SINK.set_gain(self.emitterGain, 0) self.USRP_SINK.set_antenna("TX/RX", 0) if self.primarySignalType == 0: self.primarySignal = analog.fastnoise_source_c(analog.GR_GAUSSIAN, self.signalAmplitude, 0, 8192) elif self.primarySignalType == 1: self.primarySignal = analog.sig_source_c(self.sampleRate, analog.GR_SIN_WAVE, 1000, self.signalAmplitude,0) ## elif self.primarySignalType == 2: ## self.primarySignal = analog.fastnoise_source_c(analog.GR_GAUSSIAN, self.signalAmplitude, 0, 8192) ## self.options[' = (self.signalAmplitude, self.sampleRate/2) ## self.OFDMMod = digital.ofdm_mod(self.options,msgq_limit=4,pad_for_usrp=True) self.DCBlocker = filter.dc_blocker_cc(16, True) self.keepMinN = blocks.keep_m_in_n(gr.sizeof_gr_complex, self.sensingSamples, self.packetSize, 0) self.stream2Vector = blocks.stream_to_vector(gr.sizeof_gr_complex*1, self.fftSize) self.FFTBlock = fft.fft_vcc(self.fftSize, True, (window.blackmanharris(self.fftSize)), True, 1) self.complex2MagSquared = blocks.complex_to_mag_squared(self.fftSize) self.integrateBlock = blocks.integrate_ff(self.sensingSamples) self.constantForDivision = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, self.sensingSamples) self.divideBlock = blocks.divide_ff(1) self.vector2Stream = blocks.vector_to_stream(gr.sizeof_float*1, self.fftSize) if self.type=="THR": self.thresholdFloat = blocks.threshold_ff(self.threshold, self.threshold, 0) self.fileSink = blocks.file_sink(gr.sizeof_float*1, str(self.fileName)) self.fileSink.set_unbuffered(False) ################################################## # Connections ################################################## self.connect((self.FFTBlock, 0), (self.complex2MagSquared, 0)) self.connect((self.USRP_SOURCE, 0), (self.DCBlocker, 0)) self.connect((self.complex2MagSquared, 0), (self.vector2Stream, 0)) self.connect((self.vector2Stream, 0), (self.integrateBlock, 0)) self.connect((self.integrateBlock, 0), (self.divideBlock, 0)) self.connect((self.constantForDivision, 0), (self.divideBlock, 1)) self.connect((self.DCBlocker, 0), (self.keepMinN, 0)) self.connect((self.keepMinN, 0), (self.stream2Vector, 0)) self.connect((self.stream2Vector, 0), (self.FFTBlock, 0)) if self.type=="CAL": self.connect((self.divideBlock, 0), (self.fileSink, 0)) elif self.type=="THR": self.connect((self.thresholdFloat, 0), (self.fileSink, 0)) self.connect((self.divideBlock, 0), (self.thresholdFloat, 0)) if(self.signalType=="SIGNAL"): if self.primarySignalType==0 or self.primarySignalType == 1: self.connect((self.primarySignal, 0), (self.throttle, 0)) self.connect((self.throttle, 0), (self.USRP_SINK, 0)) if self.primarySignalType==2: self.connect((self.primarySignal, 0), (self.OFDMMod, 0)) self.connect((self.OFDMMod, 0), (self.throttle, 0)) self.connect((self.throttle, 0), (self.USRP_SINK, 0)) def get_threshold(self): return self.threshold def set_threshold(self, threshold): self.threshold = threshold def get_sensingSamples(self): return self.sensingSamples def set_sensingSamples(self, sensingSamples): self.sensingSamples = sensingSamples def get_sampleRate(self): return self.sampleRate def set_sampleRate(self, sampleRate): self.sampleRate = sampleRate self.USRP_SOURCE.set_samp_rate(self.sampleRate) self.USRP_SINK.set_samp_rate(self.sampleRate) def get_packetSize(self): return self.packetSize def set_packetSize(self, packetSize): self.packetSize = packetSize def get_averageSize(self): return self.averageSize def set_averageSize(self, averageSize): self.averageSize = averageSize 2013/12/20 Marcus Müller <mar...@hostalia.de> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Actually, if it worked reliably before, then there might actually be a > regression or something that should be better documented. Can you > share the top_block's source? > Greetings, > Marcus > > On 20.12.2013 13:36, Miguel Duarte wrote: > > It worked. > > > > I don't think it's about file opening permissions, it must be > > something else, but it did the trick. The reason I don't think it's > > about permissions is that the files are different, therefore the > > handle shouldn't even be the same, or am I wrong in thinking so? > > > > Don't know why I need to take this care now, I've used this script > > a LOT of times before and this was the first time this happened > > (fresh GR install on a new computer). > > > > Thanks a lot Marcus, > > > > Best Regards, > > > > Miguel > > > > > > > > > > > > 2013/12/20 Marcus Müller <mar...@hostalia.de> > > > > Hi Miguel, don't shame yourself too much. We all make mistakes. > > > > It could be that B can't open the file it wants to write, because > > the file_sink of A still has it open. After the A.stop() have an > > A.wait() and an A = None. The wait call should let your program > > wait until all blocks are finished and no samples are left stuck in > > the flowgraph somewhere. The None-assignment should cause Python to > > deconstruct A, causing Swig to call the destructor of the C++ > > blocks and thus in turn should close the file_sink's file. Sadly, > > Python is a modern language/runtime and has lazy garbage > > collection. So in some cases, it might happen that python decides > > that it should clean up later instead of instantly at the A=None; > > then we still have a problem. To solve that, you might overload > > your top_block's stop() method, making sure that it calls > > miguels_file_sink.close() after stopping the flowgraph: > > > > class detector(grc_wxgui.top_block): ... def stop(self): > > grc_wxgui.top_block.stop(self) self.miguels_file_sink.close() > > > > Hopefully, that helps. > > > > Greetings, Marcus > > > > On 20.12.2013 00:10, Miguel Duarte wrote: > >>>> I hope this doesn't start a new thread. I wanted to answer on > >>>> my thread but I didn't get my own message on my inbox so.. I > >>>> hope it works. > >>>> > >>>> > >>>> I ended up getting what was wrong, and I feel ashamed on so > >>>> many levels, I'm sorry. I was using complex data. Damn. > >>>> > >>>> Anyway, after changing everything, it all works as expected. > >>>> So I delved a little into what was causing my troubles > >>>> initially. > >>>> > >>>> It seems that my top block class "refuses" to be instanced > >>>> twice, with two different identifiers. > >>>> > >>>> So let's say I have a > >>>> > >>>> > >>>> class detector(grc_wxgui.top_block_gui) def __init__(self, > >>>> options): > >>>> > >>>> Where I start an instance A with a certain set of options and > >>>> an instance B with other options. > >>>> > >>>> I do: A = detector(options) A.start() time.sleep(x) A.stop() > >>>> > >>>> change options > >>>> > >>>> B = detector(options) B.start() time.sleep(x) B.stop() > >>>> > >>>> I have a file sink in the flow graph. With instance A it > >>>> writes everything, with instance B it doesn't. Nothing is > >>>> changing the top block, and even with the options parameter > >>>> switched only A works. > >>>> > >>>> Is there something in this new release which prevents this > >>>> from working? > >>>> > >>>> Thanks in advance, > >>>> > >>>> Miguel. > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org > >>>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > >>>> > >> > >> _______________________________________________ Discuss-gnuradio > >> mailing list Discuss-gnuradio@gnu.org > >> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > >> > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.15 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iQEcBAEBAgAGBQJStDtYAAoJEAFxB7BbsDrL5HkIAJ5A1uOcoB1A9Zi7t0R6Fwz1 > HMBrq3cTgq+j+RLA1FsxAN4vuihOudpuI1TWldsK9AI2H7O5Is9GzlT53V/XCBi6 > ugx5qH4WewgxrZjdqJ/EftJ/VIHLEb4hOFARA7Aq4v1N7fosxeOqBMX4wu7nLD0P > UuKIS2hWi97/yUVfBM8s+WKN+3SiNY0zziQs+oc8WfhgiRVK3SRLMPYjWJYoRAAY > PQsdr8GNRYQah7bqAqrRxX2wneZyAje7mHvfR/5fqk+DxrFlAaPnAyycaz0MAOtM > qJTWI89LdFmdoPIAf7+GAj7RBKDtcgeOOKU4JZv2/dhAcrGy1bVuC5+9BuWpwR0= > =4qYc > -----END PGP SIGNATURE----- >
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio