Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4620

Beginners • Non-blocking reading of stdin or hidraw* on headless RPi

$
0
0
Raspberry Pi 4
Starting .py script as a service
No monitor
USB barcode scanner as keyboard for input (shows on hidraw0)

Trying to figure out how to get the script to capture input from the scanner in a non-blocking fashion.
Tried

Code:

while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:    bc = sys.stdin.readline()
but it seems to need an active window.

I just need to read the barcode, match it to a data file, and write out the result to a text file.
Everything works fine if I start the script from Geany with a monitor and have the resulting open window be the focus. But I get nothing if I start it as a service when the Pi boots up.

Tried to read from hidraw0, but that seems to be blocking.

Statistics: Posted by evanmars — Tue Sep 10, 2024 6:12 pm — Replies 0 — Views 28



Viewing all articles
Browse latest Browse all 4620

Trending Articles