1
votes

I am having a USB-HID barcode scanner. When I try to scan the barcode the output is displaying on STDOUT. I am using Ubuntu machine. I want the output to be redirected to some tty device. So I will be doing open(tty*) with blocking mode.Wait till the Barcode data is captured in that /dev/tty*. How can i achieve the redirecting part ?

1
No one answered ??WallPoster

1 Answers

1
votes

So your problem is basically that you are not able to "bind" the barcode reader input to your software which redirects it to the /dev/tty*?

In this case I would recommend the Python evdev module. "evdev" stands for "event device" which is a Linux kernel term (see evdev on Wikipedia). Your barcode reader is an event device (/dev/input/event*) like a keyboard or gamepad. You could create an event device object with Python evdev and use the grab_context() method to bind the input exclusively to your script. Mention that there are also Linux evdev libraries for other languages which probably all refer to the C implementation.

Having a similar issue I started to write a software for piping barcode input to the network via MQTT. If you want to have a look at example code you could check out my project. The relevant Python files are directly in the root directory.