I have a barcode scanner that I want to read non-blocking with no monitor.
The code I have works if I boot to desktop, run the code from Geany , and leave the resulting terminal window open and in focus. If I click anywhere on the monitor that does not have any type of input field, it won't work.
It will also work if I boot to CLI, as long as I have a monitor connected.
If I disconnect the monitor, it no longer captures anything (at least from the scanner) from stdin.
Here is a pared down version where I'm just trying to get the input and write it to a file: (code from the web, I'll admit I don't know how it works)Just gives me rows and rows of 'No code read'
The code I have works if I boot to desktop, run the code from Geany , and leave the resulting terminal window open and in focus. If I click anywhere on the monitor that does not have any type of input field, it won't work.
It will also work if I boot to CLI, as long as I have a monitor connected.
If I disconnect the monitor, it no longer captures anything (at least from the scanner) from stdin.
Here is a pared down version where I'm just trying to get the input and write it to a file: (code from the web, I'll admit I don't know how it works)
Code:
import system, selectdef barcode(block=True): if block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): bc = sys.stdin.readline() return bc return Nonewhile True: bar = barcode() if bar: with open('/home/pi/result', 'a') as f: f.write(f'barcode = {bar}\n') else: with open('/home/pi/result', 'a') as f: f.write('No code read\n')
Statistics: Posted by evanmars — Thu Sep 12, 2024 6:29 pm