Created
November 16, 2021 00:42
-
-
Save wheberth/4c78c7cdeea2fda356e9a069fc9d0e5d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import iio | |
import struct | |
import numpy as np | |
import matplotlib.pyplot as plt | |
#initalize the iio device and read samples from the channel voltage0 | |
ctx = iio.Context("ip:192.168.2.1") | |
dev = ctx.find_device('cf-ad9361-lpc') | |
ch0 = dev.find_channel('voltage0', False) | |
ch0.enabled = True | |
nsamples = 4096 | |
buf = iio.Buffer(dev, nsamples) | |
data = np.zeros(nsamples, dtype=np.int16) | |
while True: | |
buf.refill() | |
data_bytes = buf.read() | |
byte=0 | |
for i in range(0, nsamples): | |
data[i] = struct.unpack('<h', data_bytes[byte:byte+2])[0] | |
byte+=2 | |
plt.plot(data) | |
plt.autoscale(False) | |
plt.grid(True) | |
plt.ylim([-100,100]) | |
plt.xlim([0, nsamples]) | |
plt.draw() | |
plt.pause(0.001) | |
plt.clf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment