1

I'm developing a background application with use of a barcode scanner. The barcode scanner is recognised as an USB HID (Human Interface Device) device on my linux OS. So the default USB HID driver is loaded and the scanner behaves like a keyboard.

I'm able to read the STDIN contents of the scanner by using the pyxhook Python module. So even if my process is running in background, I can read the input from the barcode scanner.

My problem is, that the background application is also reading the inputs from the regular keyboard, because it also writes into STDIN.

I would like to use the STDIN of the barcode scanner by the background process only and ignore the STDIN of other HID devices such as keyboard, but I have no clue how to realize that. Any idea?

4
  • Barcode scanners act like keyboards. They read the barcodes and then generate input as if someone was typing on a keyboard. I'm not sure you can differentiate between the input devices at the application level. To the application they both look like keyboard presses. You probably have to go lower in the hardware stack. But I am not sure how to say, "don't accept input from device X". Commented Nov 11, 2019 at 15:00
  • Major manufacturer's scanners support serial port mode. Can you use that instead of HID mode? Commented Nov 11, 2019 at 22:51
  • @kunif: I was thinking about this option too, the problem is that in case of my test barcode scanner Zebra LS2208 there is no driver for linux available, meaning in the serial mode the devices still gets recognized as HID divice and not as a serial one, one other option is, to use a special RS232 cable (instead of usb one) with DB9 socket and plug it to linux compatible rs232 to USB converter with available drivers (FTDI). But the option is more complex because it demands special cable and adapter. So I want to fix this on software level. Commented Nov 12, 2019 at 11:13
  • It may be better to switch to scanner hardware that can easily use ttyX than to deal with complicated combinations. Commented Nov 12, 2019 at 11:35

1 Answer 1

1

If you intercept the input on a lower level (evdev), you can split it out by device. For python, there is python-evdev. You can filter devices based on name, and go from there. One downside is that you have to translate the evdev events to readable input yourself (something the kernel does for you normally).

I've written a simple program for saving barcodes to a file, to run on a RPi (with additional support for GS1-128/SSCC-128/EAN-128).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.