libiio icon indicating copy to clipboard operation
libiio copied to clipboard

Accessing already enabled device

Open xhpohanka opened this issue 9 years ago • 6 comments

When I open device that is already running (buffer/enable is 1) I cannot set its attributes with iio_channel_attr_write(). This can happen eg. after when application closes unexpectedly. For such case I'm lacking a possibility to disable buffer before calling iio_device_create_buffer().

My issue can be workarounded by sequence iio_device_create_buffer(), iio_buffer_destroy(), iio_device_create_buffer() but it does not look very nice...

xhpohanka avatar Jul 22 '16 08:07 xhpohanka

That looks like a real bug. I'll look into it.

pcercuei avatar Jul 27 '16 08:07 pcercuei

It's a bit tricky to fix. Since we definitely dont want to disable all buffers when the context is created since this would upset any other running application using libiio. We could have a force_disable primitive that ensures that a specific buffer is disabled. But this should only work if the buffer is currently not opened by another application.

lclausen-adi avatar Jul 27 '16 13:07 lclausen-adi

My current workaround lookslike following piece of code,

dev = iio_context_find_device(accel.ctx, ACCEL_NAME);
if (dev == NULL) {
    iio_context_destroy(accel.ctx);
    return -1;
}

iio_device_attr_write_longlong(dev, "buffer/enable", 0);

I thing that it is acceptable however at first I searched for something like iio_device_buffer_disable().

xhpohanka avatar Jul 27 '16 13:07 xhpohanka

Currently I'm facing the same/similar issue as @xhpohanka. When application is closed unexpectedly, buffer stays enabled. (When I rerun app and trying to refill buffer using "iio_buffer_refill" it returns err -11).

qo0op avatar May 11 '20 15:05 qo0op

You mean when the application crashes? We added a stress test, but it closes things properly, but I can add something that randomly kills threads to see if I can reproduce things.

rgetz avatar Jun 04 '20 23:06 rgetz

Yes. As is described in first comment.

qo0op avatar Jun 08 '20 15:06 qo0op