Problem loading Python block

Hi all,

today i was trying to make hierarchical signal processing block in
Python.
I started with gr_modtool script, and configured it for hierpython block
type.

My idea was to design block similar to packet framer, so inside of the
new
block, I connected binary slicer and Framer sink. I have also declared
message queue.

Outside of main block, I designed another block which should collect
messages sent by framer from the main block.

When I wanted to run this block, I got following error:

Traceback (most recent call last):
File “/home/savi_ne/work/gnuradio/GRC/top_block.py”, line 439, in

tb = top_block()
File “/home/savi_ne/work/gnuradio/GRC/top_block.py”, line 183, in
init
self.test_packet_proba_0 = test.packet_proba()
AttributeError: ‘module’ object has no attribute ‘packet_proba’

Next I found that maybe I have to put following line in init.py
file:

from packet_proba import *

After that I got similar error:

Traceback (most recent call last):
File “/home/savi_ne/work/gnuradio/GRC/top_block.py”, line 18, in

import test
File “/usr/local/lib64/python2.6/site-packages/test/init.py”, line
49, in
from packet_proba import *
File “/usr/local/lib64/python2.6/site-packages/test/packet_proba.py”,
line 51, in
class proba(gr.basic_block):
AttributeError: ‘module’ object has no attribute ‘basic_block’

I have also tried with gr.block instead of gr.basic_block, but with
identical results.

Can anybody tell what’s missing?

Thanks

For a hier block in Python, do

$ gr_modtool.py add -t hier -l python

You need 3.6.3 to do that.

Also, you’ll need a new version of modtool (it usually lags a bit behind
changes in GNU Radio).

MB

On Fri, Jan 25, 2013 at 05:05:56PM +0100, Nemanja S. wrote:

File “/home/savi_ne/work/gnuradio/GRC/top_block.py”, line 439, in

51, in

Thanks


Nemanja Savić


Discuss-gnuradio mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

Thank you Martin, I will try that on Monday.
I suppose that I have older version of gr_modtool, cause there is no
option
-l for selecting language.
My weekend would be maybe perfect If you or anybody else can explain to
me
why my code won’t work, cause I have more or less copied block
structure
from grextras.

Nice weekend
Nemanja

I installed new version of gr_modtool script and it won’t work. The
error
is following:

[[email protected] gr-test]$ gr_modtool.py add -N rx_tx_message -t
hier
-l python
Using Python < 2.7 possibly buggy. Ahem. Please send all complaints to
/dev/null.
Operating in directory .
GNU Radio module name identified: test
Language: Python
Block/code identifier: rx_tx_message
Enter valid argument list, including default arguments:
Add Python QA code? [Y/n] n
Traversing python…
Adding file ‘rx_tx_message.py’…
Traceback (most recent call last):
File “/usr/local/bin/gr_modtool.py”, line 3369, in
main()
File “/usr/local/bin/gr_modtool.py”, line 3362, in main
modtool.run()
File “/usr/local/bin/gr_modtool.py”, line 1339, in run
self._run_python()
File “/usr/local/bin/gr_modtool.py”, line 1479, in _run_python
self._write_tpl(‘block_python’, ‘python’, fname_py)
File “/usr/local/bin/gr_modtool.py”, line 1324, in _write_tpl
open(os.path.join(path, fname), ‘w’).write(get_template(tpl,
**self._info))
File “/usr/local/bin/gr_modtool.py”, line 870, in get_template
return str(GRMTemplate(Templates[tpl_id], searchList=kwargs))
File “/usr/local/bin/gr_modtool.py”, line 865, in init
Cheetah.Template.Template.init(self, src, searchList=searchList)
File “/usr/lib64/python2.6/site-packages/Cheetah/Template.py”, line
1257,
in init
self._compile(source, file, compilerSettings=compilerSettings)
File “/usr/lib64/python2.6/site-packages/Cheetah/Template.py”, line
1551,
in _compile
keepRefToGeneratedCode=True)
File “/usr/lib64/python2.6/site-packages/Cheetah/Template.py”, line
795,
in compile
raise parseError
Cheetah.Parser.ParseError:

Error in the Python code which Cheetah generated for this template:

expected an indented block (DynamicallyCompiledCheetahTemplate.py, line
122)

Line Python Code
120 deciminterp = ‘’
121 else: # generated from line 42, col 1
122 write(u’’'from gnuradio import gr
            ^

123 |class ‘’’)
124 | _v = VFFSL(SL,“blockname”,True) # u’${blockname}’ on line
46,
col 7
125 | if _v is not None: write(_filter(_v,
rawExpr=u’${blockname}’))

from line 46, col 7.

================================================================================

Here is the corresponding Cheetah code.
** I had to guess the line & column numbers, so they are probably
incorrect:

Line 42, column 1

Line Cheetah Code
39 #else if $blocktype == ‘decimator’
40 #set $deciminterp = ‘, <+decimation+>’
41 #set $deciminterp = ‘’
42 #else
 ^

43 |#end if
44 |from gnuradio import gr
45 |

Any suggestions how to ovecome this except using older version which
worked
perfectly?

Since I don’t know why gr_modtool doesn’t work for me, I took the older
working version and made very simple hier block in order to understand
messages flow in gnuradio.
The block code is following:

from gnuradio import gr

class msg_proba(gr.hier_block2):
def init(self, ):
gr.hier_block2.init(self, “msg_proba”,
gr.io_signature(1, 1, gr.sizeof_char), # Input
signature
gr.io_signature(1, 1, gr.sizeof_char)) # Output
signature

    gr_message_sink_0_msgq_out = gr_message_source_0_msgq_in =

gr.msg_queue(4)

    self.gr_message_source_0 = gr.message_source(gr.sizeof_char*1,

gr_message_source_0_msgq_in)
self.gr_message_sink_0 = gr.message_sink(gr.sizeof_char*1,
gr_message_sink_0_msgq_out, False)

    self.connect(self, self.gr_message_sink_0)
    self.connect(self.gr_message_source_0, self)

and the test code is following:

from gnuradio import gr, gr_unittest
import test
import msg_proba

class qa_msg_proba (gr_unittest.TestCase):

def setUp (self):
    self.tb = gr.top_block ()

def tearDown (self):
    self.tb = None

def test_001_msg_proba (self):

    self.src_data = ()
    self.expected_result = ()

    for i in range(51):
      self.src_data = self.src_data + (1,)
      self.expected_result = self.expected_result+(1,)

    self.src = gr.vector_source_b(self.src_data, False, 1)
    self.dst = gr.vector_sink_b ()

    self.msg_pr = msg_proba.msg_proba()

    self.tb.connect(self.src, self.msg_pr, self.dst)

    self.tb.run ()
    # check data
    result_data = dst.data ()
    self.assertEqual (expected_result, result_data)

if name == ‘main’:
gr_unittest.main ()

When I run test, it doesn’t finish. No errors, just stays active without
giving any results.
Can somebody provide some explanation?

  • Try the latest gr_modtool from github
  • What you’re doing seems weird–why are you connecting message blocks?
    These are meant as a hackish solution to access samples from outside
    the flow graph. Perhaps you want the new PDU to stream blocks?

MB

On Mon, Jan 28, 2013 at 04:42:04PM +0100, Nemanja S. wrote:

    def __init__(self, ):
gr_message_sink_0_msgq_out, False)
from gnuradio import gr, gr_unittest

        self.dst = gr.vector_sink_b ()
if __name__ == '__main__':

Operating in directory .

**self._info))
  File "/usr/lib64/python2.6/site-packages/Cheetah/Template.py", line 795,

# from line 46, col 7.
Line|Cheetah Code

    I suppose that I have older version of gr_modtool, cause there is no


        >
        declared message
        >
        >
        >   File "/home/savi_ne/work/gnuradio/GRC/top_block.py", line 18,
        > AttributeError: 'module' object has no attribute 'basic_block'
        > Thanks
        > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
        Building 05.01
        Discuss-gnuradio mailing list

Nemanja Savić


Discuss-gnuradio mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

Guys,

i am not able to load gr.basic_block and make signal processing block in
Python. Simplu, there is no binding within gnuradio/gr for that class.
It works perfectly for gr.hier)block2 class.
What might be the problem?

Thanks

Hi all,

In my first post from today, where I reported error in gr_modtool, I was
using script downloaded from github this morning (just to clarifu how
old
scriot I used).
Basically I am trying to make my own packet deframer block, and they are
more or less designed like that. This block was designed just to see how
messages work. In GRC when I connect them in that way it works, but in
test
script above it doesn’t work.
Basically the problem comes from making similar block like packet
deframer,
but I am not able to import gr.block, or gr.basic_block in python (and
gr.hier_block2 works perfectly)

Cheers

On Tue, Jan 29, 2013 at 7:40 AM, Nemanja S. [email protected]
wrote:

    gr.hier_block2.__init__(

1’s and 0’s" % (access_code,)

    #    num_msg_outputs = 1

I have no idea what files these are from. Are they part of the GNU Radio
source code? I can’t find references to them.

Sounds like you don’t have something installed correctly. You wouldn’t
normally be inheriting straight from gr_basic_block, but you should be
able
to.

And in tutorial on how to write signal processing block, it is stated to
use gr.basic_block.

Which tutorial? Again, I don’t think this is in the main GNU Radio
source,
so please point out where you are getting this from.

Tom

On Tue, Jan 29, 2013 at 7:00 AM, Nemanja S. [email protected]
wrote:

Guys,

i am not able to load gr.basic_block and make signal processing block in
Python. Simplu, there is no binding within gnuradio/gr for that class.
It works perfectly for gr.hier)block2 class.
What might be the problem?

Thanks

I’m not sure what you mean by “load gr.basic_block.” Do you mean inherit
from?

For signal processing endpoints, you want to use either gr_block,
gr_sync_block, gr_sync_decimator or gr_sync_interpolator.

Tom

OK, I’ll try to explain everything.

I want to design block responsible for decoding messages, calculating
crc,
etc … In order to do that I investigated packet_demod_base block from
main gnuradio branch,
and also packet_deframer from gr_extras group of blocks. I realized that
such kind of blocks consists of correlator, framer sink which acts like
message sink, and finally of some kind of message source. Framer sink
sends
messages to message
source and message source then does packet checking and everything.

I also wanted to design my block in that fashion, so I used correlator
and
framer sink and I wanted to design my own block which is able to receive
messages from packet framer and to check it. The code I provided in the
last post is my own, and not the part of gnuradio. Here is complete
source
file of my block:

import numpy
from math import pi
from gnuradio import gr
from gruel import pmt
from gnuradio.digital import packet_utils
import gnuradio.digital as gr_digital

class packet_tst(gr.hier_block2):
def init(self, access_code=None, threshold=-1):

    gr.hier_block2.__init__(
            self,
            "packet_tst",
                    gr.io_signature(1, 1, 1),  # Input signature
                    gr.io_signature(0, 0, 0) # Output signature
    )

    if not access_code:
        access_code = packet_utils.default_access_code
    if not packet_utils.is_1_0_string(access_code):
        raise ValueError, "Invalid access_code %r. Must be string of

1’s and 0’s" % (access_code,)

    if threshold == -1:
        threshold = 12              # FIXME raise exception

    msgq = gr.msg_queue(4)          # holds packets from the PHY
    self.correlator = 

gr_digital.correlate_access_code_bb(access_code,
threshold)

    self.framer_sink = gr.framer_sink_1(msgq)
    self.connect(self, self.correlator, self.framer_sink)

    self.hlp_blk = helper_block(msgq)

class helper_block(gr.basic_block):
def init(self, msgq):
gr.basic_block.init(
self, name = “helper_block”,
in_sig = None, out_sig = None
# num_msg_outputs = 1
)

self._msgq = msgq


def work(self, input_items, output_items):
    while True:
        try: msg = self._msgq.delete_head()
        except: return -1
        print "Message received"

At the moment the block is designed only to write something to standard
output if it receives a message. The problem is gr.basic_block as I
described in previous post. Python interpreter doesn’t complain about
gr.hier_block2, but only about gr.basic_block.
The tutorial for writing blocks in python is from gnuradio.org:
http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules#Tutorial-3-Writing-a-signal-processing-block-in-Python

Hope this helps.

Thanks

Today I have tried again, but this time i used block as is designed by
gr_modtool. It wont wen throught test, bu it reports:

AttributeError: ‘module’ object has no attribute ‘sync_block’

It is becoming horror.

On Wed, Jan 30, 2013 at 01:23:19PM +0100, Nemanja S. wrote:

Today I have tried again, but this time i used block as is designed by
gr_modtool. It wont wen throught test, bu it reports:

AttributeError: ‘module’ object has no attribute ‘sync_block’

It is becoming horror.

Nemanja,

it seems like you haven’t actually changed anything.

To recap:

  • If you want Python blocks (gr.sync_block), you need > 3.6.3.
  • You’re doing something with messages (right?) Perhaps you want
    msg_connect() rather than the old message queues (read
    Johnathan’s release announcement)

MB

Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

In order to find which version I am using (since I have few build
folders
on my computer, and I don’t know from which gnuradio was installed,
because
i tried a lot of times to install it without success (there were some
problems since I am using RHEL6)) I decided to uninstall everything and
make fresh new installation of gnuradio. I am receiving folloowing error
from cmake:

– Uninstalling “/usr/local/share/doc/gnuradio-3.6.0/README”

CMake Error at cmake_uninstall.cmake:20 (ELSEIF):
had incorrect arguments: IS_SYMLINK “$ENV{DESTDIR}${file}” (Unknown
arguments specified).

make[3]: *** [CMakeFiles/uninstall] Error 1
make[2]: *** [CMakeFiles/uninstall.dir/all] Error 2
make[1]: *** [CMakeFiles/uninstall.dir/rule] Error 2
make: *** [uninstall] Error 2

I simply tried to make this file, but then there was another file
missing,
and so on.
Is there any other way to uninstall gnuradio?

Best

I deleted everything that was Gnu Radio-ish and istalled fresh new
version.
But it doesn’t work now. GRC won’t start, it complains about environment
variable, I checket, they are good.
When I want to start uhd_fft I come the following error:

Traceback (most recent call last):

“/usr/local/lib64/python2.6/site-packages/gnuradio/gr/gnuradio_core_runtime.py”,
line 24, in
_gnuradio_core_runtime = swig_import_helper()
File
“/usr/local/lib64/python2.6/site-packages/gnuradio/gr/gnuradio_core_runtime.py”,
line 20, in swig_import_helper
_mod = imp.load_module(’_gnuradio_core_runtime’, fp, pathname,
description)
ImportError: libgnuradio-core-3.6.4git.so.0.0.0: cannot open shared object
fil

The problem is this objest does exist in this location: /usr/local/lib64

I am using RHEL6.

Best

On Thu, Jan 31, 2013 at 11:34 AM, Martin B. (CEL)

The problem was bad LD_LIBRARY_PATH.
Can anybody explain:
why with LD_LIBRARY_PATH=/usr/bin:usr/local/lib64:usr/local/lib, GRC
won’t
run, and with LD_LIBRARY_PATH=/usr/local/lib64. it works?

On Thu, Jan 31, 2013 at 9:52 AM, Nemanja S. [email protected]
wrote:

The problem was bad LD_LIBRARY_PATH.
Can anybody explain:
why with LD_LIBRARY_PATH=/usr/bin:usr/local/lib64:usr/local/lib, GRC won’t
run, and with LD_LIBRARY_PATH=/usr/local/lib64. it works?

My only guess for that is you have something left over in one of those
directories from a previous installation that’s pointing to a wrong
version. (Also, I wouldn’t think that a bin directory ever needs to be
in
the library path.)

Tom

Just install 3.6.3, you should be fine.
Otherwise, manually browse through /usr/local and kill everything that
looks GNU Radio-ish.

MB

On Wed, Jan 30, 2013 at 04:13:20PM +0100, Nemanja S. wrote:

  arguments specified).


Nemanja,


[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Nemanja Savić


Discuss-gnuradio mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

On Fri, Feb 1, 2013 at 10:12 AM, Nemanja S. [email protected]
wrote:

function and nothing happens. The work function looks like this:

In the flow graph, I have vector source and message sink which shares
message queue with my block. There are no errors.

Could the problem be no inputs and no outputs? Or maybe something else?

Best and thanks

Nemanja

If I recall… you have to connect /something/, so add a line
‘self.connect(self)’.

Tom

Guys,

As i told you my new installation works fine, I eve tested blocks in
python. Now, the problem is following:

I designed block in python which has None for both input and output
signature. I wanted to use such block only for receiving messages and
for
writing to terminal some information, etc.
The constructor of my new block, is executed, but the problem is work
function is never executed. I put some printing at the beginning of work
function and nothing happens. The work function looks like this:

def work(self, input_items, output_items):
    print "In work"
    while True:
        print "In loop"
        try: msg = self._msgq.delete_head()
        except: return -1
        print "Message received"
    return len(output_items[0])

In the flow graph, I have vector source and message sink which shares
message queue with my block. There are no errors.

Could the problem be no inputs and no outputs? Or maybe something else?

Best and thanks

Nemanja

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs