Skip to content

Support devices by index when serial number isn't available. - #83

Open
ooeygui wants to merge 1 commit into
pothosware:masterfrom
ooeygui:feature/by_index
Open

Support devices by index when serial number isn't available.#83
ooeygui wants to merge 1 commit into
pothosware:masterfrom
ooeygui:feature/by_index

Conversation

@ooeygui

@ooeygui ooeygui commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Add USB enumeration indexes to RTL-SDR discovery and allow devices to be opened by index instead of requiring a unique serial number.

This enables reliable use of multi-receiver hardware such as the KerberosSDR and KrakenSDR, whose RTL2832U receivers may expose duplicate or empty serial descriptors. Serial-based selection cannot distinguish those receivers and may repeatedly open the first matching device.

This change is intended to support both the CyberEther desktop application and its WebAssembly/WebUSB application, while remaining generally useful to other SoapySDR clients.

Changes

  • Publish an index argument for every enumerated RTL-SDR receiver.
  • Support filtering discovery results with index.
  • Prefer index when opening a receiver so devices with duplicate or empty serials can be selected individually.
  • Validate that supplied indexes are numeric and within the current librtlsdr device range.
  • Preserve serial-based lookup as a compatibility fallback for existing configurations.
  • Cache native tuner discovery by device index rather than serial number.
  • Read the tuner type from the selected device after it is opened.
  • Avoid opening every authorized receiver during discovery under Emscripten/WebUSB.

The Emscripten-specific discovery path intentionally returns a stable label based on the USB enumeration index and avoids optional tuner/string probing. Opening devices during browser discovery can serialize or block WebUSB operations, allowing one active or unresponsive receiver to prevent the remaining receivers from being discovered. Native discovery retains the existing manufacturer, product, serial, and tuner metadata.

Motivation

Multi-receiver products commonly contain several otherwise identical RTL-SDR devices. A serial-only identity is insufficient when their descriptors are duplicated, blank, or unavailable through WebUSB.

For example, CyberEther needs to represent each KerberosSDR or KrakenSDR receiver as a separate selectable source in both its desktop and browser applications. Exposing the librtlsdr enumeration index gives the application an unambiguous selector for each receiver in the current enumeration.

Indexes identify devices within the current librtlsdr enumeration; they are not intended to be persistent physical identifiers across reconnects or system reboots.

Compatibility

Existing callers that select devices by serial continue to work. When both arguments are available, index is used to open the selected device. The reduced metadata probing behavior is limited to Emscripten builds; native discovery behavior is otherwise preserved.

Testing

Tested on Windows with RTL2832U/R820T receivers from a multi-receiver SDR:

  • Confirmed the rtlsdr factory is available through SoapySDRUtil.

  • Confirmed two connected receivers enumerate independently as index=0 and index=1, including devices with non-unique serial information.

  • Successfully probed both devices using:

    SoapySDRUtil --probe="driver=rtlsdr,index=0"
    SoapySDRUtil --probe="driver=rtlsdr,index=1"
    
    
  • Successfully configured both receivers at 2 MSps.

  • Measured approximately 1.998 MSps from each receiver during active RX rate tests.

  • Built and exercised the changes through CyberEther’s native desktop and Emscripten/WebUSB builds.

@zuckschwerdt

Copy link
Copy Markdown
Member

Thanks! Does this change impact opening a single available RTL-SDR without any arguments?

I'm not sure about changing devInfo["label"], I see why it is needed, but it was a stable name before and is dependent on other devices and order now.

The cache might not work as intended if the usb tree changes. I.e. plug in one RTL-SDR type, discover, then swap for another tuner type, and there will be a mismatch.

@ooeygui

ooeygui commented Sep 2, 2026

Copy link
Copy Markdown
Author

Thank you for the feedback!
I tested with single and multiple radios on the same device, both with and without serial numbers. I'll look at the cache semantics with multiple different radios and verify.
I don't want to break downstream users - are there any other test cases or consumers I should run?

@zuckschwerdt

Copy link
Copy Markdown
Member

I don't know of critical SoapySDR API consumers to test. I guess it never properly worked for the interesting devices you use, so that's a win to support those.
For the simple use case of a single classical dongle it needs to be all automatic. And the cache is needed but could perhaps be on a short timeout. Thinking about it, it would already not work if you swapped fresh (no serial) RTL-SDR sticks with different tuners. It's just a diagnostic output, so maybe nobody ever noticed?

@zuckschwerdt

Copy link
Copy Markdown
Member

I'm not sure about changing devInfo["label"], I see why it is needed, but it was a stable name before and is dependent on other devices and order now.

I've checked our other modules and there is prior use of the enumeration index in the label. E.g. HackRF and Pluto use a format of e.g. label_str << options["device"] << " #" << i << " " << options["serial"];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants