# How to use values from the output of a block in GNURadio

I want to use the output values of the top_block as a way of directing my flowdiagram. So I want the flowdiagram to take one path if the output of my processing block is 0 and take a different path if it is non-zero. The if self.blocks_multiply_xx_0.out_sig != 0: statement is the condition I am having trouble with.

I have implemented an if statement within the top block which disconnects and connect parts of the diagram accordingly.

• I want the if statement to look at the output of the self.blocks_multiply_xx_0 block and send it to a file sink if it is non-zero, or otherwise send it to a null sink.
• I want this to be done for each and every value coming out of the self.blocks_multiply_xx_0 block.

However to do so I need a way of accessing that blocks output value.

1. How can I go about accessing that value, and assessing which path to take based upon that value, each and every time the self.blocks_multiply_xx_0 block produces an output value?

2. Is the location of the if statement correct?

3. Will it check each and every processed sample value or does it have to be moved to a different method?

4. If so where could it go?

from gnuradio import gr
from gnuradio import audio
from gnuradio import analog
from PyQt4 import Qt
from gnuradio import blocks
import time
class my_top_block(gr.top_block):
def init(self):
gr.top_block.init(self)
     samp_rate = 32000
amp = 0.1
# Blocks
##################################################
self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
self.audio_sink_0 = audio.sink(samp_rate, '', True)
self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*1, 'C:\SDR\GNU files\speed_test_SSD\speed_test_SSD.iq', False)
self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1)
self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 350, amp)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.5, 1)

##################################################
# Connections
##################################################
#connect square wave with multiply
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
# connect sine wave with multiply
self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1))
#connect multiply output with audio sink
self.connect((self.blocks_multiply_xx_0, 0), (self.audio_sink_0, 0))
#connect multiply out to with null sink
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_file_sink_0, 0))
#connect multiply out to with null sink
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_null_sink_0, 0))

#if its non-zero send to file sink, otherwise send to null sink
if  self.blocks_multiply_xx_0.out_sig != 0:
self.disconnect(self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_null_sink_0, 0)))
self.connect((self.blocks_mgetinultiply_xx_0, 0), (self.blocks_file_sink_0, 0))
else:
self.disconnect(self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_file_sink_0, 0)))
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_null_sink_0 ,0))

def d():
my_top_block().run()
def n():
t0 = time.time()
time.sleep(5)
t1 = time.time()
t = t1 - t0
print 'time = ', t
def ram2disk():
#take the contents in written to Q: drive
#write these to a new file in C: drive
#execute this in a new thread occurring simultaneously as the write to ram

if name == 'main':
d = threading.Thread(name='daemon', target=d)
d.setDaemon(True)

d.start()
t.start()</pre>


I want to use the output values of the top_block

A top_block has no output; a signal processing block in a flowgraph has.

So I want the flowdiagram to take one path if the output of my processing block is 0 and take a different path if it is non-zero.

Ah, you kind of want to "demux" something. So write a simple demux block that has two inputs and multiple outputs; copy from the first input to any of the outputs, depending on your second input.

I have implemented an if statement within the top block which disconnects and connect parts of the diagram accordingly.

Don't do that. Flow graph reconfiguration is asynchronous to signal processing in GNU Radio, i.e. this won't work, and especially not on a per-sample basis.

• Within GNUradio there are 4 demux blocks - Header/Payload, PBCH, PCFICH and Timeslot demux. Which one would be most accurate? Would there be synchronous so that there is no loss of data? – Zain Dec 9 '20 at 10:12
• "Write a simple demux block" means you write your own. So, none of these. – Marcus Müller Dec 9 '20 at 10:35