Re: [Discuss-gnuradio] runtime error while running flowgraph

2018-08-30 Thread Rensi Mathew
 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:
 

  frew_sweep_v1_f
  tutorial_frew_sweep_v1_f
  [tutorial]
  import tutorial
  from gnuradio.digital import packet_utils
  tutorial.frew_sweep_v1_f($initial_freq, $step)
  post_message($msg)
  
    message
    msg
    string
  
  
    in
    message
  
 
  
    out
    message
  


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"), 1)
    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()
    

Re: [Discuss-gnuradio] runtime error while running flowgraph

2018-08-27 Thread CEL
Have you first registered the "clock" message port? This looks like
you're trying to set a handler for a message port that doesn't exist.

Also, when asking for help, it's usually very helpful to have your
*exact* code somewhere, not a reference to code that is /similar/.

Best regards,
Marcus
On Mon, 2018-08-27 at 04:18 +, Rensi Mathew wrote:
> I created a block using gr_modtool add -l python -tsync command,
> where I tried to implement this discussion:[Discuss-gnuradio] Change
> frequency in USRP source automatically (https://lists.gnu.org/archive
> /html/discuss-gnuradio/2016-03/msg00402.html)
> And then used this block in a flowgraph connecting to the block USRP
> Source.
> when I tried to run the top_block.py block, the following error was
> displayed:-
> > root@pglab1-HCL-Desktop:/home/pglab1# python top_block.py
> > Traceback (most recent call last):
> > File "top_block.py", line 98, in 
> > main()
> > File "top_block.py", line 86, in main
> > tb = top_block_cls()
> > File "top_block.py", line 64, in __init__
> > self.tutorial_frew_sweep_v1_f_0 = tutorial.frew_sweep_v1_f()
> > File "/usr/local/lib/python2.7/dist-
> > packages/tutorial/frew_sweep_v1_f.py", line 40, in __init__
> > self.set_msg_handler(pmt.intern('clock'),self.handler)
> > File "/usr/local/lib/python2.7/dist-
> > packages/gnuradio/gr/gateway.py", line 200, in set_msg_handler
> > self.__gateway.set_msg_handler_feval(which_port, handler)
> > File "/usr/local/lib/python2.7/dist-
> > packages/gnuradio/gr/runtime_swig.py", line 6423, in
> > set_msg_handler_feval
> > return _runtime_swig.block_gateway_sptr_set_msg_handler_feval(self,
> > which_port, msg_handler)
> > RuntimeError: attempt to set_msg_handler_feval() on bad input
> > message port!
> > 
> > Can someone help me to correct this error?
> > Thanking you
> > Rensi Sam
> > Anna University
>  
> ___
> Discuss-gnuradio mailing list
> Discuss-gnuradio@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

smime.p7s
Description: S/MIME cryptographic signature
___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio