Connecting to SDRs using serial numbers in python

58 views
Skip to first unread message

Bill Voss

unread,
Feb 3, 2021, 7:28:20 PM2/3/21
to Pothos Users
Hello,

I'm working on an application where I need to connect multiple SDRs of the same type (AirSpy R2). Each one has a different antenna so I need to be able to distinguish between them.

We can display connected devices with:
device_list = SoapySDR.Device.enumerate()
for device in device_list:
    print(device)

With two AirSpys connected this gives:
{device_id=0, driver=airspy, label=AIRSPY [260868c8:2673939b], serial=260868c8:2673939b}
{device_id=1, driver=airspy, label=AIRSPY [260868c8:266b479b], serial=260868c8:266b479b}

I've tried many approaches for then using this info to a specific SDR. Two of these are:

1) 
args = dict(driver='airspy', serial='260868c8:266b479b')
sdr = SoapySDR.Device(args)

args = dict(driver='airspy', serial='260868c8:2673939b')
sdr2 = SoapySDR.Device(args)

print(sdr.getHardwareInfo())
print(sdr2.getHardwareInfo())

This prints:

It's connected to the same device twice?

2) Instead trying to reference via device_id:
args = {'driver':'airspy', 'device_id':'0'}
sdr = SoapySDR.Device(args)

args = {'driver':'airspy', 'device_id':'1'}
sdr2 = SoapySDR.Device(args)  # Crashes here!

print(sdr.getHardwareInfo())
print(sdr2.getHardwareInfo())

However, this crashes at the seconds at the marked line, traceback:

Traceback (most recent call last):
  File "./multi_connect_test.py", line 36, in <module>
    sdr2 = SoapySDR.Device(args)
  File "/home/bill/miniforge3/envs/cusignal-dev/lib/python3.6/site-packages/SoapySDR.py", line 1926, in __new__
    return cls.make(*args, **kwargs)
RuntimeError: Airspy device_id out of range [0 .. 1].

Any advice would be great!

Thanks,
Bill

righthal...@gmail.com

unread,
Feb 3, 2021, 8:20:46 PM2/3/21
to Pothos Users

In C++ , I do what amounts to -

sdr = SoapySDR.Device(device_list[0])

sdr2 = SoapySDR.Device(device_list[1])

perhaps that will work in python

Bill Voss

unread,
Feb 3, 2021, 8:28:31 PM2/3/21
to Pothos Users
Thank you for the idea - unfortunately this gives the same error as my attempt 2), with the device_id being out of range.

I'm wondering if it is a bug in the python bindings.

righthal...@gmail.com

unread,
Feb 3, 2021, 10:37:52 PM2/3/21
to Pothos Users
I could be that the driver can only handle one device at a time. Sdrplay can handle only one at a time. Rtlsdr can handle several sticks. You could test it with SdrGlut. SdrGlut can handle several devices if the driver is up to it.. 

Bill Voss

unread,
Feb 4, 2021, 12:23:55 AM2/4/21
to Pothos Users
Thanks for the input. I've got CubicSDR installed already, so I used that - I was able to open two windows, each reading from a separate AirSpy.

I think that this shows that the driver can handle multiple devices?

righthal...@gmail.com

unread,
Feb 4, 2021, 10:16:41 AM2/4/21
to Pothos Users

CubicSDR uses the C++ interface  - there must be a problem with the python routines.

righthal...@gmail.com

unread,
Feb 4, 2021, 11:21:30 AM2/4/21
to Pothos Users

What version of CubicSDR were you using and How did you get it to open two windows ? It always opens the second device into the same window as the first device for me with Cubic 2.3 and 2.5.

I have heard that you can open one device directly and a second device through soapyremote - perhaps that will work.

Bill Voss

unread,
Feb 4, 2021, 7:36:20 PM2/4/21
to Pothos Users
I'm using CubicSDR v0.2.3 on Ubuntu 18.04. Just opening the app twice creates two separate windows for me.

Ideally, I would be able to reference device i with SoapySDR.Device.enumerate()[i] in Python, just like you do in C++.

I'll open an issue in github.

righthal...@gmail.com

unread,
Feb 4, 2021, 11:58:52 PM2/4/21
to Pothos Users

I tried what you are trying to do with rtlsdr sticks - it opens both sticks without a problem. 

Josh Blum

unread,
Feb 7, 2021, 11:20:53 AM2/7/21
to pothos...@googlegroups.com

FYI I moved the issue here: https://github.com/pothosware/SoapyAirspy/issues/26

This is undoubtedly the device index changing after the first open.

Ive been on a quest to make sure device drivers support open by serial and don't expose internal things like enumeration indexes.

I'm sure the original SoapyAirspy was only tested against a single device. And it definitely needs the "treatment" :-)

-josh

--
You received this message because you are subscribed to the Google Groups "Pothos Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pothos-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pothos-users/841489d8-bd08-4690-b291-fff305ea2d11n%40googlegroups.com.

Bill Voss

unread,
Feb 7, 2021, 6:27:19 PM2/7/21
to Pothos Users
Thanks Josh!

I'll reply on the issue page.

Reply all
Reply to author
Forward
0 new messages