rtlsdr.rtlsdraio
This module adds asyncio
support for reading samples from the device.
The main functionality can be found in the stream()
method of rtlsdr.rtlsdraio.RtlSdrAio
.
Example
import asyncio
from rtlsdr import RtlSdr
async def streaming():
sdr = RtlSdr()
async for samples in sdr.stream():
# do something with samples
# ...
# to stop streaming:
await sdr.stop()
# done
sdr.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(streaming())
- class rtlsdr.rtlsdraio.AsyncCallbackIter(func_start, func_stop=None, queue_size=20, *, loop=None)
Bases:
object
Convert a callback-based legacy async function into one supporting asyncio and Python 3.5+
The queued data can be iterated using
async for
- Parameters
func_start – A callable which should take a single callback that will be passed data. Will be run in a seperate thread in case it blocks.
func_stop (optional) – A callable to stop
func_start
from calling the callback. Will be run in a seperate thread in case it blocks.queue_size (
int
, optional) – The maximum amount of data that will be buffered.loop (optional) – The
asyncio.event_loop
to use. If not supplied,asyncio.get_event_loop()
will be used.
- async add_to_queue(*args)
Add items to the queue
- Parameters
*args – Arguments to be added
This method is a
coroutine
- class rtlsdr.rtlsdraio.RtlSdrAio(device_index=0, test_mode_enabled=False, serial_number=None)[source]
Bases:
rtlsdr.rtlsdr.RtlSdr
- stop()[source]
Stop async stream
Stops the
read_samples_async
andExcecutor
task created bystream()
.
- stream(num_samples_or_bytes=131072, format='samples', loop=None)[source]
Start async streaming from SDR and return an async iterator (Python 3.5+).
The
read_samples_async()
method is called in anExcecutor
instance usingasyncio.AbstractEventLoop.run_in_executor()
.The returned asynchronous iterable can then used to retrieve sample data using
async for
syntax.Calling the
stop()
method will stop theread_samples_async
session and close theExcecutor
task.- Parameters
- Returns
An
asynchronous iterator
to yield sample data