I am trying to implement this discussion:[Discuss-gnuradio] Change frequency in USRPsource automatically(https://lists.gnu.org/archive/html/discuss-gnuradio/2016-03/msg00402.html). My objective is to create a block which changes the frequency automatically in steps of 2e6, starting from 2.37e9.
My block has a code given below: import stringimport numpy import pmt from gnuradio import gr from gnuradio import digital class frew_sweep_v1_f(gr.sync_block): """ docstring for block frew_sweep_v1_f """ def __init__(self,initial_freq=2.37e9, step=2e6): gr.sync_block.__init__(self, name="frew_sweep_v1_f", in_sig=[], out_sig=[]) self.message_port_register_in(pmt.intern('clock')) self.message_port_register_out(pmt.intern('sync')) self.set_msg_handler(pmt.intern('clock'),self.handler) self.freq=initial_freq self.step=step def handler(self,pdu): self.message_port_pub(pmt.intern('sync'),pmt.cons(pmt.intern("freq"),pmt.to_pmt(self.freq))) self.freq+=self.step the xml file has a code given below: <?xml version="1.0"?> <block> <name>frew_sweep_v1_f</name> <key>tutorial_frew_sweep_v1_f</key> <category>[tutorial]</category> <import>import tutorial</import> <import>from gnuradio.digital import packet_utils</import> <make>tutorial.frew_sweep_v1_f($initial_freq, $step)</make> <callback>post_message($msg)</callback> <param> <name>message</name> <key>msg</key> <type>string</type> </param> <sink> <name>in</name> <type>message</type> </sink> <source> <name>out</name> <type>message</type> </source> </block> I inserted this new block between a message block and message debug block.The new top_block code generated is given below: if __name__ == '__main__': import ctypes import sys if sys.platform.startswith('linux'): try: x11 = ctypes.cdll.LoadLibrary('libX11.so') x11.XInitThreads() except: print "Warning: failed to XInitThreads()" from PyQt4 import Qt from gnuradio import digital from gnuradio import blocks from gnuradio import eng_notation from gnuradio import gr from gnuradio.digital import packet_utils from gnuradio.eng_option import eng_option from gnuradio.filter import firdes from optparse import OptionParser import pmt import sys import tutorial from gnuradio import qtgui class top_blockRSM_frew_sweepv1(gr.top_block, Qt.QWidget): def __init__(self): gr.top_block.__init__(self, "Top Blockrsm Frew Sweepv1") Qt.QWidget.__init__(self) self.setWindowTitle("Top Blockrsm Frew Sweepv1") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_blockRSM_frew_sweepv1") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.tutorial_frew_sweep_v1_f_0 = Template error: tutorial.frew_sweep_v1_f($initial_freq, $step) cannot find 'initial_freq' self.blocks_message_strobe_0 = blocks.message_strobe(pmt.intern("freq"), 10000) self.blocks_message_debug_0 = blocks.message_debug() ################################################## # Connections ################################################## self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.tutorial_frew_sweep_v1_f_0, 'in')) self.msg_connect((self.tutorial_frew_sweep_v1_f_0, 'out'), (self.blocks_message_debug_0, 'print')) def closeEvent(self, event): self.settings = Qt.QSettings("GNU Radio", "top_blockRSM_frew_sweepv1") self.settings.setValue("geometry", self.saveGeometry()) event.accept() def get_samp_rate(self): return self.samp_rate def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate def main(top_block_cls=top_blockRSM_frew_sweepv1, options=None): from distutils.version import StrictVersion if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): style = gr.prefs().get_string('qtgui', 'style', 'raster') Qt.QApplication.setGraphicsSystem(style) qapp = Qt.QApplication(sys.argv) tb = top_block_cls() tb.start() tb.show() def quitting(): tb.stop() tb.wait() qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) qapp.exec_() if __name__ == '__main__': main() in the code, under Blocks, it shows self.tutorial_frew_sweep_v1_f_0 = Template error: tutorial.frew_sweep_v1_f($initial_freq, $step) cannot find 'initial_freq' So when I Execute the flowgraph, the error pops up. Executing: /usr/bin/python2 -u /home/pglab1/top_blockRSM_frew_sweepv3.py File "/home/pglab1/top_blockRSM_frew_sweepv3.py", line 67 self.tutorial_frew_sweep_v1_f_0 = Template error: tutorial.frew_sweep_v1_f($initial_freq, $step) ^ SyntaxError: invalid syntax >>> Done (return code 1) Can someone tell why this error is created in the python code? Thanking youRensi
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio