Open rherban opened 3 months ago
The code is here: https://github.com/pothosware/SoapyPlutoSDR/blob/master/PlutoSDR_Registration.cpp#L10
The find_PlutoSDR()
call will cache results and always return previously found results.
Not great at all. I imagine newly added devices will also not show up if at least one device was discovered once. The call is expensive, but we should find out if caching is needed at all.
Can you try to remove if (!results.empty()) return results;
and check if it fixes the problem as expected?
The caching was added with a3dcbd3 and we should also check if the iio_context
can really be safely reused.
Removing those lines did not work, that is I still see the device after being unplugged.
[icarus@7afa] /opt/soapysdr/SoapyPlutoSDR> vi PlutoSDR_Registration.cpp
[icarus@7afa] /opt/soapysdr/SoapyPlutoSDR> cd build
[icarus@7afa] /opt/soapysdr/SoapyPlutoSDR/build> ../../cmake-3.27.4/bin/cmake ..
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Build type not specified: defaulting to release.
-- LibIIO_INCLUDE_DIRS: /usr/include
-- LibIIO_LIBRARIES: /usr/lib/arm-linux-gnueabihf/libiio.so
-- LibIIO_DEFINITIONS:
-- Could NOT find LibAD9361 (missing: LibAD9361_LIBRARY LibAD9361_INCLUDE_DIR)
-- LibUSB_INCLUDE_DIRS: /usr/include/libusb-1.0
-- LibUSB_LIBRARIES: /usr/lib/arm-linux-gnueabihf/libusb-1.0.so
-- LibUSB_DEFINITIONS:
-- Module PlutoSDRSupport configured with version: 0.2.2-03b5ae2
-- Configuring done (0.8s)
-- Generating done (0.1s)
-- Build files have been written to: /opt/soapysdr/SoapyPlutoSDR/build
[icarus@7afa] /opt/soapysdr/SoapyPlutoSDR/build> make
[ 20%] Building CXX object CMakeFiles/PlutoSDRSupport.dir/PlutoSDR_Registration.cpp.o
In file included from /opt/soapysdr/SoapyPlutoSDR/PlutoSDR_Registration.cpp:7:0:
/usr/include/libusb-1.0/libusb.h:736:4: warning: ISO C++ forbids zero-size array ‘dev_capability_data’ [-Wpedantic]
[0] /* non-standard, but usually working code */
^
/usr/include/libusb-1.0/libusb.h:767:4: warning: ISO C++ forbids zero-size array ‘dev_capability’ [-Wpedantic]
[0] /* non-standard, but usually working code */
^
/usr/include/libusb-1.0/libusb.h:1263:4: warning: ISO C++ forbids zero-size array ‘iso_packet_desc’ [-Wpedantic]
[0] /* non-standard, but usually working code */
^
cc1plus: warning: unrecognized command line option ‘-Wno-zero-length-array’
[ 40%] Building CXX object CMakeFiles/PlutoSDRSupport.dir/Version.cpp.o
[ 60%] Linking CXX shared module libPlutoSDRSupport.so
[100%] Built target PlutoSDRSupport
[icarus@7afa] /opt/soapysdr/SoapyPlutoSDR/build> sudo make install
[100%] Built target PlutoSDRSupport
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/SoapySDR/modules0.8-3/libPlutoSDRSupport.so
-- Set runtime path of "/usr/local/lib/SoapySDR/modules0.8-3/libPlutoSDRSupport.so" to ""
Sorry, one more line of changes is required:
You need to move the line static std::vector<SoapySDR::Kwargs> results;
down into the function and remove the static
.
Or call results.clear();
first thing in the find_PlutoSDR()
function.
That did the trick!
probe found: {device=PlutoSDR, driver=plutosdr, label=PlutoSDR #0 usb:1.4.5, uri=usb:1.4.5}
Adding PlutoSDR #0 usb:1.4.5 - usb:1.4.5
There are 1 sensors: [{device=PlutoSDR, driver=plutosdr, label=PlutoSDR #0 usb:1.4.5, product=PlutoSDR #0 usb:1.4.5, serial=usb:1.4.5, uri=usb:1.4.5}]
No devices detected
Removing Soapy device: PlutoSDR #0 usb:1.4.5
There are 0 sensors: []
For reference, the code looks like this now:
...
#ifdef HAS_LIBUSB1
#include <libusb.h>
#endif
static std::vector<SoapySDR::Kwargs> find_PlutoSDR(const SoapySDR::Kwargs &args) {
std::vector<SoapySDR::Kwargs> results;
ssize_t ret = 0;
iio_context *ctx = nullptr;
iio_scan_context *scan_ctx;
...
Thanks for the pointers!
Thanks for testing! Let's keep this open as it really needs to be fixed, the behaviour right only works for one fixed device.
I am testing some code to detect when a Soapy-compatible SDR is physically unplugged and to remove it from an internal list. This works for an RTLSDR and HackRF, but the Pluto continues to be recognized by the
SoapySDR.Device.enumerate()
call.Host: BeagleBone Black Debian 9 (I know it's old, but our stack is locked to this)
dmesg
output:Here is code that replicates the problem:
Code output (showing the RTL being detected, then removed, then the pluto being detected but not removed). Newlines were added to distinguish physical events.