Skip to contentSkip to conversation

libgpiod - bufor problem

DISCUSSION Adam Tofilski 2 participants 2 messages Aug 26, 2022 – Aug 27, 2022 GPIO

lore
Share & tools
lore
#0 lore raw

Dear Bartosz
First of all thank you for gpiomon software.

I try to use if for data acquisition from an optical sensor. It works fine from command line but when I try to run it as QProcess in QT (GUI) there is a problem with buffering. The output is transferred occasionally in large pieces. What I need is to get output immediately after each line. I plan to distribute my software as open source.

As I understand this problem can be solved by adding to your code setbuf(stdout, NULL);
or
fflush(stdout)
after each line.

I hope you will be able to help me with this.
Best wishes
Adam

Adam Tofilski
Department of Zoology and Animal Welfare
Agricultural University
29 Listopada 56
31-425 Krakow
Poland
[email protected]
tel: +48 12 6625069

#1 lore raw
Quoted 9 lines · Adam Tofilski

Dear Bartosz
First of all thank you for gpiomon software.

I try to use if for data acquisition from an optical sensor. It works fine from command line but when I try to run it as QProcess in QT (GUI) there is a problem with buffering. The output is transferred occasionally in large pieces. What I need is to get output immediately after each line. I plan to distribute my software as open source.

Quoted 6 lines

As I understand this problem can be solved by adding to your code setbuf(stdout, NULL);
or
fflush(stdout)
after each line.

My proposed tool changes for libgpiod v2[1] include the fflush after each line for the same reason. I had issues with the setbuf approach, though I don't recall the specifics, so went with the fflush.

Maybe do the same for v1?

Though I note that the target audience for that is cheap and cheerful scripts, not apps.

Adam, the appropriate solution for you would be to use libgpiod directly rather than wrapping gpiomon. The tools like gpiomon are just that - tools. The output of gpiomon is not part of the stable ABI, so getting the events directly from libgpiod is the way to go. Apps should use the C library directly, or the C++ or Python bindings as appropriate.

Cheers,
Kent.

[1] https://lore.kernel.org/linux-gpio/[email protected]/

Quoted 14 lines

I hope you will be able to help me with this.
Best wishes
Adam

Adam Tofilski
Department of Zoology and Animal Welfare
Agricultural University
29 Listopada 56
31-425 Krakow
Poland
[email protected]
tel: +48 12 6625069