Skip to content

Commit

Permalink
rework Quick Start docs with new API
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Sep 14, 2021
1 parent 228f55a commit dd5ef2d
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,44 @@ julia> using SoapySDR, SoapyRTLSDR_jll

### Transmitting and Receiving

TX:
```
# Open first TX-capable channel on first device
channel = Devices()[1].tx[1]
# Configure channel with appropriate parameters
channel.bandwidth = 800u"kHz"
channel.frequency = 30u"MHz"
channel.gain = 42u"dB"
channel.sample_rate = 2.1u"MHz"
# Open a (potentially multichannel) stream on this channel
stream = SoapySDR.Stream([channel])
SoapySDR.activate!(stream)
# Write out random noise
Base.write(stream, (randn(ComplexF32, 10000),))
```

RX:
```
# Open first RX-capable channel on first device
channel = Devices()[1].rx[1]
# Configure channel with appropriate parameters
channel.bandwidth = 800u"kHz"
channel.frequency = 30u"MHz"
channel.gain = 42u"dB"
channel.sample_rate = 2.1u"MHz"
# Open a (potentially multichannel) stream on this channel
stream = SoapySDR.Stream([channel])
SoapySDR.activate!(stream)
# Collect all available samples in the buffer
Base.read(stream)
# Open all TX-capable channels on first device
tx_channels = Devices()[1].tx
# Open all RX-capable channels on first device
rx_channels = Devices()[1].rx
# Configure a TX channel with appropriate parameters
# configure the RX channel with similar for e.g. a loopback test
# Be sure to check your local regulations before transmitting!
tx_channel[1].bandwidth = 800u"kHz"
tx_channel[1].frequency = 30u"MHz"
tx_channel[1].gain = 42u"dB"
tx_channel[1].sample_rate = 2.1u"MHz"
# Open a (potentially multichannel) stream on the channels
tx_stream = SoapySDR.Stream(tx_channels)
rx_stream = SoapySDR.Stream(rx_channels)
# Setup a sample buffer optimized for the device
# The data can be access with e.g. tx_buf.bufs
# Note: we ask for 10,000 samples, but the API will re-size correctly for the device
tx_buf = SoapySDR.SampleBuffer(tx_stream, 10_000)
rx_buf = SoapySDR.SampleBuffer(rx_stream, 10_000)
# Setup some data to transmit on each channel
for i in eachindex(tx_buf)
tx_buf.bufs[i] = randn(SoapySDR.streamtype(tx_stream), length(tx_buf))
end
# Spawn two tasks for full duplex operation
# The tasks will run in parallel and for best resuslts run julia with --threads=auto
read_task = @spawn read!(rx_stream, rx_buf)
write_task = @spawn write(tx_stream, tx_buf)
# Wait for the tasks to complete
wait(read_task); wait(write_task);
# access the recieved data in with
@show rx_buf.bufs[:][1:100] # show the first 100 samples
```

0 comments on commit dd5ef2d

Please sign in to comment.