Created
July 3, 2019 03:36
-
-
Save takurx/36aa05d65b0b2c62c8d755856bf0f808 to your computer and use it in GitHub Desktop.
SoapySDR Basic example, modified for airspy on BBB, BeagleBoardUbuntu 18.04.2 (https://github.com/pothosware/SoapySDR/wiki/PythonSupport)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ubuntu@arm:~$ python3 test_soapysdr_basicexaple.py | |
{device_id=0, driver=airspy, label=AIRSPY [26a464dc:286c2693], serial=26a464dc:286c2693} | |
('RX',) | |
('LNA', 'MIX', 'VGA') | |
2.4e+07, 1.8e+09 | |
[INFO] Using format CF32. | |
-1 | |
0 | |
0 | |
-1 | |
0 | |
0 | |
-1 | |
0 | |
0 | |
-1 | |
0 | |
0 | |
-1 | |
0 | |
0 | |
1024 | |
32 | |
0 | |
1024 | |
32 | |
0 | |
1024 | |
32 | |
0 | |
1024 | |
32 | |
0 | |
1024 | |
32 | |
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic example modified only args for airspy | |
# https://github.com/pothosware/SoapySDR/wiki/PythonSupport | |
# | |
import SoapySDR | |
from SoapySDR import * #SOAPY_SDR_ constants | |
import numpy #use numpy for buffers | |
#enumerate devices | |
results = SoapySDR.Device.enumerate() | |
for result in results: print(result) | |
#create device instance | |
#args can be user defined or from the enumeration result | |
# args = dict(driver="rtlsdr") | |
args = dict(driver="airspy") | |
sdr = SoapySDR.Device(args) | |
#query device info | |
print(sdr.listAntennas(SOAPY_SDR_RX, 0)) | |
print(sdr.listGains(SOAPY_SDR_RX, 0)) | |
freqs = sdr.getFrequencyRange(SOAPY_SDR_RX, 0) | |
for freqRange in freqs: print(freqRange) | |
#apply settings | |
sdr.setSampleRate(SOAPY_SDR_RX, 0, 1e6) | |
sdr.setFrequency(SOAPY_SDR_RX, 0, 912.3e6) | |
#setup a stream (complex floats) | |
rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32) | |
sdr.activateStream(rxStream) #start streaming | |
#create a re-usable buffer for rx samples | |
buff = numpy.array([0]*1024, numpy.complex64) | |
#receive some samples | |
for i in range(10): | |
sr = sdr.readStream(rxStream, [buff], len(buff)) | |
print(sr.ret) #num samples or error code | |
print(sr.flags) #flags set by receive operation | |
print(sr.timeNs) #timestamp for receive buffer | |
#shutdown the stream | |
sdr.deactivateStream(rxStream) #stop streaming | |
sdr.closeStream(rxStream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment