Non-blocking reading from /dev/input/event

Linux specific questions.
Post Reply
maratus
Posts: 3
Joined: May 28, 2019 20:05

Non-blocking reading from /dev/input/event

Post by maratus »

Dear Friends, good day.

I can't solve the problem of non-blocking reading from /dev/input/event.
Linux. Platform ARM.
Found solution (open, O_NONBLOCK, fdopen, ...) is implemented at C and, as I understand, supported C-functions are not insufficient to do this using FB.
I very hope that I'm not right.

I open pipe "cat /dev/input/event" and use Get#. It works perfectly while input stream from /dev/input/event is coming. As soon as the stream ends I catch the block (waiting for stream renewal).
Of course EOF doesn't help.
I tried standart C functions fopen, feof, fgetc/fgets/freads/fscanf - there is block when the stream stops.
Move of the reading procedure into separate thread, via CreateThread, doesn't allow to avoid the block.

Can anyone solve this issue by FB?
Thanks.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Non-blocking reading from /dev/input/event

Post by TJF »

Hi maratus!

Code: Select all

open pipe "cat /dev/input/event"
Why do you use the indirect route involving the shell and the cat command?

Just open "/dev/input/event" directly, either by FB or C functions. Do asynchronous readings in a thread.

Regards
maratus
Posts: 3
Joined: May 28, 2019 20:05

Re: Non-blocking reading from /dev/input/event

Post by maratus »

TJF wrote:Just open "/dev/input/event" directly, either by FB or C functions. Do asynchronous readings in a thread.
TJF, thank you for advice.
Now it is solved. Yes I used FB code with included C functions (many thanks to Haav).
First I tried to put asynchronous reading into thread. I'm using ARM, not PC Linux. Furthermore there is a lot of graphics in my program. So all this set has led to serious freezes in a random intervals. Each time I was forced to reload the controller. If to remove threads and to place asynchronous reading at the main/root code everything works perfectly. This problem concerns only ARM architecture. PC works fine with threads.

Thank you very much.

Best regards
Post Reply