pyadi-iio operation in GNURadio 3.8

Hello,

I'm running pyadi-iio and it all works great in Python 3.7.3.  Thanks!  But I'm having trouble using it with GNURadio3.8.1.0 (which is also running Python 3.7.3). 

Here's my Python 3.7.3 output (not in GNUradio 3.8.1.0):

But if I try the "import adi" in a GNUradio "Python Block", then I get this error "Can't interpret source code: module 'iio' has no attribute 'Device'.  It runs if I comment out the "import adi".  Below is my Python Block code (it's all the standard template except for the import iio and import adi):


"""
Embedded Python Blocks:

Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!
"""

import numpy as np
from gnuradio import gr

import sys

sys.path.append('/usr/lib/python2.7/site-packages/')
sys.path.append('/lib/python3.7/site-packages/')
import iio
import adi

class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block
    """Embedded Python Block example - a simple multiply const"""

    def __init__(self, example_param=1.0):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        gr.sync_block.__init__(
            self,
            name='Embedded Python Block',   # will show up in GRC
            in_sig=[np.complex64],
            out_sig=[np.complex64]
        )
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
        self.example_param = example_param

    def work(self, input_items, output_items):
        """example: multiply with constant"""
        output_items[0][:] = input_items[0] * self.example_param
        return len(output_items[0])

  • +1
    •  Analog Employees 
    on Aug 12, 2020 9:33 PM 8 months ago

    Yeah, this is a known problem since gr-iio (3.8) and libiio share the same python module name (iio). This won't be a problem once gr-iio is merged upstream but right now its a problem area for out of tree modules.

    The easiest thing to do is to rename the iio.py file to something else then change the imports in pyadi to use that name. For example, if you change iio.py to iiopy.py, then you would have to change every "import iio" to import iiopy.py" in pyadi. This should be only 3 files IIR.

    -Travis 

  • 0
    •  Analog Employees 
    on Aug 12, 2020 11:08 PM 8 months ago in reply to travisfcollins

    Thanks, that works!  It was two files in the adi folder: "rx_tx.py", and "context_manager.py"

    In those files, I changed "import iio" to "import iiopy as iio"

    I think it's all working now!  Thanks!

  • Travis / John

    I've been following this thread with interest as I've been falling down the same rabbit-hole. Wondering if you can help me take the next steps?

    Objective is Pluto + GNU Radio + Python and pyadi-iio - and nearly there.

    Installation is Linux Mint 20.1 (latest LTS) plus successfully installed GRC v3.8.1, plus the iio libraries built from source, plus now pyadi-iio installed. 

    Copied the idea of renaming 'iio.py' and changing the import references to the new name in the ADI folder for rx_tx.py and context_manager.py.

    So, I can now run GRC, complete with Pluto blocks - Yeah!

    I can successfully import my 'newname_iio' in python3

    I can successfully import adi in python 3 - but I am getting an error in running the test script in the PySDR book (Chapter 5).

    test python code is:-

    import adi
    sdr = adi.Pluto('ip:192.168.2.1') # or whatever your Pluto's IP is
    sdr.sample_rate = int(2.5e6)
    sdr.rx()

    Response is:

    bob@samsung-i5:~/Documents/Python scripts/Pluto$ python3 pysdr_0.py
    Traceback (most recent call last):
    File "pysdr_0.py", line 4, in <module>
    sdr.rx()
    File "/usr/local/lib/python3.8/dist-packages/adi/rx_tx.py", line 252, in rx
    return self.__rx_complex()
    File "/usr/local/lib/python3.8/dist-packages/adi/rx_tx.py", line 173, in __rx_complex
    self._rx_init_channels()
    File "/usr/local/lib/python3.8/dist-packages/adi/rx_tx.py", line 129, in _rx_init_channels
    self.__rxbuf = iio.Buffer(self._rxadc, self.__rx_buffer_size, False)
    File "/usr/local/lib/python3.8/dist-packages/bob_iio.py", line 1016, in __init__
    self._ctx = device.ctx()
    TypeError: 'Context' object is not callable

    Typing this command   iio_info -s             produces

    bob@samsung-i5:~$ iio_info -s
    Library version: 0.21 (git tag: 359305c)
    Compiled with backends: local xml ip usb
    Unable to create Local IIO context : No such file or directory (2)
    Available contexts:
    0: 0456:b673 (Analog Devices Inc. PlutoSDR (ADALM-PLUTO)), serial=1044739659930001170019003d352948b6 [usb:1.4.5]

    Typing this command:- iio_attr -a -C      produces

    Using auto-detected IIO context at URI "usb:1.4.5"
    IIO context with 15 attributes:
    hw_model: Analog Devices PlutoSDR Rev.B (Z7010-AD9364)
    hw_model_variant: 0
    hw_serial: 1044739659930001170019003d352948b6
    fw_version: v0.32
    ad9361-phy,xo_correction: 39999868
    ad9361-phy,model: ad9364
    local,kernel: 4.19.0-119999-g6edc6cd
    uri: usb:1.4.5
    usb,idVendor: 0456
    usb,idProduct: b673
    usb,release: 2.0
    usb,vendor: Analog Devices Inc.
    usb,product: PlutoSDR (ADALM-PLUTO)
    usb,serial: 1044739659930001170019003d352948b6
    usb,libusb: 1.0.23.11397

    Changing the adi.Pluto call from an ip context to a usb one makes no difference to the error.

    Any ideas on what needs tweaking?  I feel I am so close....

  • 0
    •  Analog Employees 
    on Feb 3, 2021 5:47 PM 2 months ago in reply to Wireless

    What context are you using in gnuradio?

    -Travis

  • 'ip:pluto.local'

    This was tried in the python script as well as the IP address and the usb number.