AnsweredAssumed Answered

Unable to create buffer for ad9361 in libiio (C language)

Question asked by musb on Jan 19, 2017
Latest reply on Jan 23, 2017 by musb

I'm trying use the ad9361 and libiio to grab a small snapshot of i&q samples from the receive channel and write them to a file.  To familiarize myself with libiio, I've been working through the ad9361-iiostream.c example.  My issue is that I follow the example but am unable to create a buffer.  My code snippet is below:

 

struct iio_context *ctx = NULL;
struct iio_device *dev = NULL;
struct iio_channel *ch_i = NULL, *ch_q = NULL;
struct iio_buffer *rx_buf = NULL;
     

//initialize ad9361 & buffer
if ((ctx = iio_create_local_context()) == NULL) {
     fprintf(stderr, "unable to create local context\n");
     goto fail;
}
if ((dev = iio_context_find_device(ctx, "ad9361-phy")) == NULL) {
     fprintf(stderr, "unable to find device\n");
     goto fail;
}
if (((ch_i = iio_device_find_channel(dev, "voltage0", false)) == NULL) ||
     ((ch_q = iio_device_find_channel(dev, "voltage1", false)) == NULL)) {
     fprintf(stderr, "unable to get channel\n");
     goto fail;
}
if (!iio_channel_is_scan_element(ch_i) ||
     !iio_channel_is_scan_element(ch_q)) {
     fprintf(stderr, "channel can not generate samples\n");
//     goto fail;
}

iio_channel_enable(ch_i);
iio_channel_enable(ch_q);
if ((rx_buf = iio_device_create_buffer(dev, 1024*1024, false)) == NULL) {
     fprintf(stderr, "unable to create buffer\n");
     goto fail;
}

 

The program always fails at the buffer.  One confusing thing is that iio_channel_is_scan_element returns false for the 2 channels (meaning they don't generate samples), but I believe I'm using the same ones from the example program.  I configure the ad9361's sample rate, frequency, etc in a different program.

 

Thanks

Outcomes