Editing Guided Tutorial GNU Radio in Python

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 319: Line 319:
  
 
<syntaxhighlight lang="python" line="line">
 
<syntaxhighlight lang="python" line="line">
#!/usr/bin/env python3
+
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8 -*-
 
+
##################################################
#
 
# SPDX-License-Identifier: GPL-3.0
 
#
 
 
# GNU Radio Python Flow Graph
 
# GNU Radio Python Flow Graph
# Title: if_else
+
# Title: If Else
# GNU Radio version: 3.8.0.0
+
# Generated: Thu Sep 13 11:39:57 2018
 
+
##################################################
from distutils.version import StrictVersion
 
  
 
if __name__ == '__main__':
 
if __name__ == '__main__':
Line 339: Line 335:
 
             x11.XInitThreads()
 
             x11.XInitThreads()
 
         except:
 
         except:
             print("Warning: failed to XInitThreads()")
+
             print "Warning: failed to XInitThreads()"
  
from PyQt5 import Qt
+
from PyQt4 import Qt
 +
from gnuradio import analog
 +
from gnuradio import blocks
 
from gnuradio import eng_notation
 
from gnuradio import eng_notation
 +
from gnuradio import gr
 
from gnuradio import qtgui
 
from gnuradio import qtgui
 +
from gnuradio.eng_option import eng_option
 
from gnuradio.filter import firdes
 
from gnuradio.filter import firdes
 +
from optparse import OptionParser
 
import sip
 
import sip
from gnuradio import analog
 
from gnuradio import blocks
 
from gnuradio import gr
 
 
import sys
 
import sys
import signal
+
import threading
from argparse import ArgumentParser
 
from gnuradio.eng_arg import eng_float, intx
 
 
import time
 
import time
import threading
 
 
from gnuradio import qtgui
 
from gnuradio import qtgui
 +
  
 
class if_else(gr.top_block, Qt.QWidget):
 
class if_else(gr.top_block, Qt.QWidget):
  
 
     def __init__(self):
 
     def __init__(self):
         gr.top_block.__init__(self, "if_else")
+
         gr.top_block.__init__(self, "If Else")
 
         Qt.QWidget.__init__(self)
 
         Qt.QWidget.__init__(self)
         self.setWindowTitle("if_else")
+
         self.setWindowTitle("If Else")
 
         qtgui.util.check_set_qss()
 
         qtgui.util.check_set_qss()
 
         try:
 
         try:
Line 381: Line 377:
  
 
         self.settings = Qt.QSettings("GNU Radio", "if_else")
 
         self.settings = Qt.QSettings("GNU Radio", "if_else")
 +
        self.restoreGeometry(self.settings.value("geometry").toByteArray())
  
        try:
 
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
 
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
 
            else:
 
                self.restoreGeometry(self.settings.value("geometry"))
 
        except:
 
            pass
 
  
 
         ##################################################
 
         ##################################################
Line 403: Line 393:
 
         self.probe = blocks.probe_signal_f()
 
         self.probe = blocks.probe_signal_f()
 
         self._freq_tool_bar = Qt.QToolBar(self)
 
         self._freq_tool_bar = Qt.QToolBar(self)
         self._freq_tool_bar.addWidget(Qt.QLabel('freq' + ": "))
+
         self._freq_tool_bar.addWidget(Qt.QLabel("freq"+": "))
 
         self._freq_line_edit = Qt.QLineEdit(str(self.freq))
 
         self._freq_line_edit = Qt.QLineEdit(str(self.freq))
 
         self._freq_tool_bar.addWidget(self._freq_line_edit)
 
         self._freq_tool_bar.addWidget(self._freq_line_edit)
 
         self._freq_line_edit.returnPressed.connect(
 
         self._freq_line_edit.returnPressed.connect(
            lambda: self.set_freq(int(str(self._freq_line_edit.text()))))
+
        lambda: self.set_freq(int(str(self._freq_line_edit.text().toAscii()))))
 
         self.top_grid_layout.addWidget(self._freq_tool_bar)
 
         self.top_grid_layout.addWidget(self._freq_tool_bar)
 
         self._ampl_tool_bar = Qt.QToolBar(self)
 
         self._ampl_tool_bar = Qt.QToolBar(self)
         self._ampl_tool_bar.addWidget(Qt.QLabel('ampl' + ": "))
+
         self._ampl_tool_bar.addWidget(Qt.QLabel("ampl"+": "))
 
         self._ampl_line_edit = Qt.QLineEdit(str(self.ampl))
 
         self._ampl_line_edit = Qt.QLineEdit(str(self.ampl))
 
         self._ampl_tool_bar.addWidget(self._ampl_line_edit)
 
         self._ampl_tool_bar.addWidget(self._ampl_line_edit)
 
         self._ampl_line_edit.returnPressed.connect(
 
         self._ampl_line_edit.returnPressed.connect(
            lambda: self.set_ampl(int(str(self._ampl_line_edit.text()))))
+
        lambda: self.set_ampl(int(str(self._ampl_line_edit.text().toAscii()))))
 
         self.top_grid_layout.addWidget(self._ampl_tool_bar)
 
         self.top_grid_layout.addWidget(self._ampl_tool_bar)
 +
 
         def _variable_function_probe_0_probe():
 
         def _variable_function_probe_0_probe():
 
             while True:
 
             while True:
 
+
                 val = self.probe.level()
                 val = self.probe.get_number()
 
 
                 try:
 
                 try:
 
                     self.set_variable_function_probe_0(val)
 
                     self.set_variable_function_probe_0(val)
Line 430: Line 420:
  
 
         self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
 
         self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024, #size
+
        1024, #size
            samp_rate, #samp_rate
+
        samp_rate, #samp_rate
            "", #name
+
        'QT GUI Plot', #name
            1 #number of inputs
+
        1 #number of inputs
 
         )
 
         )
 
         self.qtgui_time_sink_x_0.set_update_time(0.10)
 
         self.qtgui_time_sink_x_0.set_update_time(0.10)
Line 440: Line 430:
 
         self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
 
         self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
  
         self.qtgui_time_sink_x_0.enable_tags(True)
+
         self.qtgui_time_sink_x_0.enable_tags(-1, True)
 
         self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
 
         self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
 
         self.qtgui_time_sink_x_0.enable_autoscale(False)
 
         self.qtgui_time_sink_x_0.enable_autoscale(False)
Line 448: Line 438:
 
         self.qtgui_time_sink_x_0.enable_stem_plot(False)
 
         self.qtgui_time_sink_x_0.enable_stem_plot(False)
  
 +
        if not True:
 +
          self.qtgui_time_sink_x_0.disable_legend()
  
         labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
+
         labels = ['', '', '', '', '',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
+
                  '', '', '', '', '']
 
         widths = [1, 1, 1, 1, 1,
 
         widths = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
+
                  1, 1, 1, 1, 1]
         colors = ['blue', 'red', 'green', 'black', 'cyan',
+
         colors = ["blue", "red", "green", "black", "cyan",
            'magenta', 'yellow', 'dark red', 'dark green', 'dark blue']
+
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
 
            1.0, 1.0, 1.0, 1.0, 1.0]
 
 
         styles = [1, 1, 1, 1, 1,
 
         styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
+
                  1, 1, 1, 1, 1]
 
         markers = [-1, -1, -1, -1, -1,
 
         markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]
+
                  -1, -1, -1, -1, -1]
 
+
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
 +
                  1.0, 1.0, 1.0, 1.0, 1.0]
  
         for i in range(1):
+
         for i in xrange(1):
 
             if len(labels[i]) == 0:
 
             if len(labels[i]) == 0:
 
                 self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
 
                 self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
Line 477: Line 468:
 
         self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
 
         self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
 
         self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
 
         self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
         self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, freq, ampl, 0, 0)
+
         self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, freq, ampl, 0)
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0, 0)
+
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0)
  
  
Line 486: Line 477:
 
         ##################################################
 
         ##################################################
 
         self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
 
         self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
         self.connect((self.analog_sig_source_x_0_0, 0), (self.qtgui_time_sink_x_0, 0))
+
         self.connect((self.analog_sig_source_x_1, 0), (self.qtgui_time_sink_x_0, 0))
 
         self.connect((self.blocks_throttle_0, 0), (self.probe, 0))
 
         self.connect((self.blocks_throttle_0, 0), (self.probe, 0))
  
Line 505: Line 496:
 
     def set_samp_rate(self, samp_rate):
 
     def set_samp_rate(self, samp_rate):
 
         self.samp_rate = samp_rate
 
         self.samp_rate = samp_rate
 +
        self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate)
 +
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
 +
        self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
 
         self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
 
         self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
        self.analog_sig_source_x_0_0.set_sampling_freq(self.samp_rate)
 
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
 
        self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate)
 
  
 
     def get_freq(self):
 
     def get_freq(self):
Line 516: Line 507:
 
         self.freq = freq
 
         self.freq = freq
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
         self.analog_sig_source_x_0_0.set_frequency(self.freq)
+
         self.analog_sig_source_x_1.set_frequency(self.freq)
  
 
     def get_ampl(self):
 
     def get_ampl(self):
Line 524: Line 515:
 
         self.ampl = ampl
 
         self.ampl = ampl
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
         self.analog_sig_source_x_0_0.set_amplitude(self.ampl)
+
         self.analog_sig_source_x_1.set_amplitude(self.ampl)
 
 
  
  
 
def main(top_block_cls=if_else, options=None):
 
def main(top_block_cls=if_else, options=None):
  
     if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
+
    from distutils.version import StrictVersion
 +
     if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
 
         style = gr.prefs().get_string('qtgui', 'style', 'raster')
 
         style = gr.prefs().get_string('qtgui', 'style', 'raster')
 
         Qt.QApplication.setGraphicsSystem(style)
 
         Qt.QApplication.setGraphicsSystem(style)
Line 538: Line 529:
 
     tb.start()
 
     tb.start()
 
     tb.show()
 
     tb.show()
 
    def sig_handler(sig=None, frame=None):
 
        Qt.QApplication.quit()
 
 
    signal.signal(signal.SIGINT, sig_handler)
 
    signal.signal(signal.SIGTERM, sig_handler)
 
 
    timer = Qt.QTimer()
 
    timer.start(500)
 
    timer.timeout.connect(lambda: None)
 
  
 
     def quitting():
 
     def quitting():
 
         tb.stop()
 
         tb.stop()
 
         tb.wait()
 
         tb.wait()
     qapp.aboutToQuit.connect(quitting)
+
     qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
 
     qapp.exec_()
 
     qapp.exec_()
  
Line 564: Line 545:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
        def _variable_function_probe_0_probe():
+
      def _variable_function_probe_0_probe():
 
             while True:
 
             while True:
 
 
                 val = self.probe.level()
 
                 val = self.probe.level()
 
                 try:
 
                 try:
Line 577: Line 557:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
    def set_freq(self, freq):
+
  def set_freq(self, freq):
 
         self.freq = freq
 
         self.freq = freq
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
         self.analog_sig_source_x_0_0.set_frequency(self.freq)
+
         self.analog_sig_source_x_1.set_frequency(self.freq)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 586: Line 566:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
    def set_ampl(self, ampl):
+
  def set_ampl(self, ampl):
 
         self.ampl = ampl
 
         self.ampl = ampl
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
         self.analog_sig_source_x_0_0.set_amplitude(self.ampl)
+
         self.analog_sig_source_x_1.set_amplitude(self.ampl)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
We can see that the functions set_ampl and set_freq can be used for just that - setting the amplitude and the frequency. Thus we can go back and modify our probe function with the if-else statement to give power to our friend.
 
We can see that the functions set_ampl and set_freq can be used for just that - setting the amplitude and the frequency. Thus we can go back and modify our probe function with the if-else statement to give power to our friend.
Line 595: Line 575:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
        def _variable_funct ion_probe_0_probe():
+
      def _variable_function_probe_0_probe():
 
             while True:
 
             while True:
 
 
                 val = self.probe.level()
 
                 val = self.probe.level()
 
                 print val
 
                 print val
Line 613: Line 592:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now there is one more thing we need to take care of. GRC has compiled the python file in the order of creation of the elements, which was okay as long as there were no crossreferences. With the introduced adaptation (calling set_ampl and set_freq inside the _variable_function_probe_0_probe()) we need to fix the order of declarations. As set_ampl and set_freq both modify parameters of analog_sig_source_x_0_0 but analog_sig_source_x_0_0 is not instantiated before line  150, we have to move the declaration of the _variable_function_probe_0_probe() and everything related below that.
+
Now there is one more thing we need to take care of. GRC has compiled the python file in the order of creation of the elements, which was okay as long as there were no crossreferences. With the introduced adaptation (calling set_ampl and set_freq inside the _variable_function_probe_0_probe()) we need to fix the order of declarations. As set_ampl and set_freq both modify parameters of analog_sig_source_x_1 but analog_sig_source_x_1 is not instantiated before line  150, we have to move the declaration of the _variable_function_probe_0_probe() and everything related below that.
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 627: Line 606:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
#!/usr/bin/env python3
+
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8 -*-
 
+
##################################################
#
 
# SPDX-License-Identifier: GPL-3.0
 
#
 
 
# GNU Radio Python Flow Graph
 
# GNU Radio Python Flow Graph
# Title: if_else
+
# Title: If Else
# GNU Radio version: 3.8.0.0
+
# Generated: Thu Sep 13 11:39:57 2018
 
+
##################################################
from distutils.version import StrictVersion
 
  
 
if __name__ == '__main__':
 
if __name__ == '__main__':
Line 647: Line 622:
 
             x11.XInitThreads()
 
             x11.XInitThreads()
 
         except:
 
         except:
             print("Warning: failed to XInitThreads()")
+
             print "Warning: failed to XInitThreads()"
  
from PyQt5 import Qt
+
from PyQt4 import Qt
 +
from gnuradio import analog
 +
from gnuradio import blocks
 
from gnuradio import eng_notation
 
from gnuradio import eng_notation
 +
from gnuradio import gr
 
from gnuradio import qtgui
 
from gnuradio import qtgui
 +
from gnuradio.eng_option import eng_option
 
from gnuradio.filter import firdes
 
from gnuradio.filter import firdes
 +
from optparse import OptionParser
 
import sip
 
import sip
from gnuradio import analog
 
from gnuradio import blocks
 
from gnuradio import gr
 
 
import sys
 
import sys
import signal
+
import threading
from argparse import ArgumentParser
 
from gnuradio.eng_arg import eng_float, intx
 
 
import time
 
import time
import threading
 
 
from gnuradio import qtgui
 
from gnuradio import qtgui
 +
  
 
class if_else(gr.top_block, Qt.QWidget):
 
class if_else(gr.top_block, Qt.QWidget):
  
 
     def __init__(self):
 
     def __init__(self):
         gr.top_block.__init__(self, "if_else")
+
         gr.top_block.__init__(self, "If Else")
 
         Qt.QWidget.__init__(self)
 
         Qt.QWidget.__init__(self)
         self.setWindowTitle("if_else")
+
         self.setWindowTitle("If Else")
 
         qtgui.util.check_set_qss()
 
         qtgui.util.check_set_qss()
 
         try:
 
         try:
Line 689: Line 664:
  
 
         self.settings = Qt.QSettings("GNU Radio", "if_else")
 
         self.settings = Qt.QSettings("GNU Radio", "if_else")
 +
        self.restoreGeometry(self.settings.value("geometry").toByteArray())
  
        try:
 
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
 
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
 
            else:
 
                self.restoreGeometry(self.settings.value("geometry"))
 
        except:
 
            pass
 
  
 
         ##################################################
 
         ##################################################
Line 711: Line 680:
 
         self.probe = blocks.probe_signal_f()
 
         self.probe = blocks.probe_signal_f()
 
         self._freq_tool_bar = Qt.QToolBar(self)
 
         self._freq_tool_bar = Qt.QToolBar(self)
         self._freq_tool_bar.addWidget(Qt.QLabel('freq' + ": "))
+
         self._freq_tool_bar.addWidget(Qt.QLabel("freq"+": "))
 
         self._freq_line_edit = Qt.QLineEdit(str(self.freq))
 
         self._freq_line_edit = Qt.QLineEdit(str(self.freq))
 
         self._freq_tool_bar.addWidget(self._freq_line_edit)
 
         self._freq_tool_bar.addWidget(self._freq_line_edit)
 
         self._freq_line_edit.returnPressed.connect(
 
         self._freq_line_edit.returnPressed.connect(
            lambda: self.set_freq(int(str(self._freq_line_edit.text()))))
+
        lambda: self.set_freq(int(str(self._freq_line_edit.text().toAscii()))))
 
         self.top_grid_layout.addWidget(self._freq_tool_bar)
 
         self.top_grid_layout.addWidget(self._freq_tool_bar)
 
         self._ampl_tool_bar = Qt.QToolBar(self)
 
         self._ampl_tool_bar = Qt.QToolBar(self)
         self._ampl_tool_bar.addWidget(Qt.QLabel('ampl' + ": "))
+
         self._ampl_tool_bar.addWidget(Qt.QLabel("ampl"+": "))
 
         self._ampl_line_edit = Qt.QLineEdit(str(self.ampl))
 
         self._ampl_line_edit = Qt.QLineEdit(str(self.ampl))
 
         self._ampl_tool_bar.addWidget(self._ampl_line_edit)
 
         self._ampl_tool_bar.addWidget(self._ampl_line_edit)
 
         self._ampl_line_edit.returnPressed.connect(
 
         self._ampl_line_edit.returnPressed.connect(
            lambda: self.set_ampl(int(str(self._ampl_line_edit.text()))))
+
        lambda: self.set_ampl(int(str(self._ampl_line_edit.text().toAscii()))))
 
         self.top_grid_layout.addWidget(self._ampl_tool_bar)
 
         self.top_grid_layout.addWidget(self._ampl_tool_bar)
  
 
         self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
 
         self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024, #size
+
        1024, #size
            samp_rate, #samp_rate
+
        samp_rate, #samp_rate
            "", #name
+
        'QT GUI Plot', #name
            1 #number of inputs
+
        1 #number of inputs
 
         )
 
         )
 
         self.qtgui_time_sink_x_0.set_update_time(0.10)
 
         self.qtgui_time_sink_x_0.set_update_time(0.10)
Line 736: Line 705:
 
         self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
 
         self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
  
         self.qtgui_time_sink_x_0.enable_tags(True)
+
         self.qtgui_time_sink_x_0.enable_tags(-1, True)
 
         self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
 
         self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
 
         self.qtgui_time_sink_x_0.enable_autoscale(False)
 
         self.qtgui_time_sink_x_0.enable_autoscale(False)
Line 744: Line 713:
 
         self.qtgui_time_sink_x_0.enable_stem_plot(False)
 
         self.qtgui_time_sink_x_0.enable_stem_plot(False)
  
 +
        if not True:
 +
          self.qtgui_time_sink_x_0.disable_legend()
  
         labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
+
         labels = ['', '', '', '', '',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10']
+
                  '', '', '', '', '']
 
         widths = [1, 1, 1, 1, 1,
 
         widths = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
+
                  1, 1, 1, 1, 1]
         colors = ['blue', 'red', 'green', 'black', 'cyan',
+
         colors = ["blue", "red", "green", "black", "cyan",
            'magenta', 'yellow', 'dark red', 'dark green', 'dark blue']
+
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
 
            1.0, 1.0, 1.0, 1.0, 1.0]
 
 
         styles = [1, 1, 1, 1, 1,
 
         styles = [1, 1, 1, 1, 1,
            1, 1, 1, 1, 1]
+
                  1, 1, 1, 1, 1]
 
         markers = [-1, -1, -1, -1, -1,
 
         markers = [-1, -1, -1, -1, -1,
            -1, -1, -1, -1, -1]
+
                  -1, -1, -1, -1, -1]
 
+
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
 +
                  1.0, 1.0, 1.0, 1.0, 1.0]
  
         for i in range(1):
+
         for i in xrange(1):
 
             if len(labels[i]) == 0:
 
             if len(labels[i]) == 0:
 
                 self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
 
                 self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
Line 773: Line 743:
 
         self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
 
         self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
 
         self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
 
         self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
         self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, freq, ampl, 0, 0)
+
         self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, freq, ampl, 0)
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0, 0)
+
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 0.1, 1, 0)
  
 
         def _variable_function_probe_0_probe():
 
         def _variable_function_probe_0_probe():
 
             while True:
 
             while True:
 
 
                 val = self.probe.level()
 
                 val = self.probe.level()
                 print (val)
+
                 print val
 
                 if val == 1:
 
                 if val == 1:
 
                     self.set_ampl(1)
 
                     self.set_ampl(1)
Line 800: Line 769:
 
         ##################################################
 
         ##################################################
 
         self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
 
         self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
         self.connect((self.analog_sig_source_x_0_0, 0), (self.qtgui_time_sink_x_0, 0))
+
         self.connect((self.analog_sig_source_x_1, 0), (self.qtgui_time_sink_x_0, 0))
 
         self.connect((self.blocks_throttle_0, 0), (self.probe, 0))
 
         self.connect((self.blocks_throttle_0, 0), (self.probe, 0))
  
Line 819: Line 788:
 
     def set_samp_rate(self, samp_rate):
 
     def set_samp_rate(self, samp_rate):
 
         self.samp_rate = samp_rate
 
         self.samp_rate = samp_rate
 +
        self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate)
 +
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
 +
        self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
 
         self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
 
         self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
        self.analog_sig_source_x_0_0.set_sampling_freq(self.samp_rate)
 
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
 
        self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate)
 
  
 
     def get_freq(self):
 
     def get_freq(self):
Line 830: Line 799:
 
         self.freq = freq
 
         self.freq = freq
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
 
         Qt.QMetaObject.invokeMethod(self._freq_line_edit, "setText", Qt.Q_ARG("QString", str(self.freq)))
         self.analog_sig_source_x_0_0.set_frequency(self.freq)
+
         self.analog_sig_source_x_1.set_frequency(self.freq)
  
 
     def get_ampl(self):
 
     def get_ampl(self):
Line 838: Line 807:
 
         self.ampl = ampl
 
         self.ampl = ampl
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
 
         Qt.QMetaObject.invokeMethod(self._ampl_line_edit, "setText", Qt.Q_ARG("QString", str(self.ampl)))
         self.analog_sig_source_x_0_0.set_amplitude(self.ampl)
+
         self.analog_sig_source_x_1.set_amplitude(self.ampl)
 
 
  
  
 
def main(top_block_cls=if_else, options=None):
 
def main(top_block_cls=if_else, options=None):
  
     if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
+
    from distutils.version import StrictVersion
 +
     if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
 
         style = gr.prefs().get_string('qtgui', 'style', 'raster')
 
         style = gr.prefs().get_string('qtgui', 'style', 'raster')
 
         Qt.QApplication.setGraphicsSystem(style)
 
         Qt.QApplication.setGraphicsSystem(style)
Line 852: Line 821:
 
     tb.start()
 
     tb.start()
 
     tb.show()
 
     tb.show()
 
    def sig_handler(sig=None, frame=None):
 
        Qt.QApplication.quit()
 
 
    signal.signal(signal.SIGINT, sig_handler)
 
    signal.signal(signal.SIGTERM, sig_handler)
 
 
    timer = Qt.QTimer()
 
    timer.start(500)
 
    timer.timeout.connect(lambda: None)
 
  
 
     def quitting():
 
     def quitting():
 
         tb.stop()
 
         tb.stop()
 
         tb.wait()
 
         tb.wait()
     qapp.aboutToQuit.connect(quitting)
+
     qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
 
     qapp.exec_()
 
     qapp.exec_()
  
Line 878: Line 837:
  
 
<pre>
 
<pre>
$ python3 if_else_mod.py
+
$ python if_else_mod.py
 
</pre>
 
</pre>
 
We should be able to see the numbers 0 and 1 on the terminal and the sine wave changing amplitude and frequency as the numbers change.
 
We should be able to see the numbers 0 and 1 on the terminal and the sine wave changing amplitude and frequency as the numbers change.

Please note that all contributions to GNU Radio are considered to be released under the Creative Commons Attribution-ShareAlike (see GNU Radio:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)