Serial Barcode Reader as a Keyboard

Today I was trying to solve an unsupported device problem, I’ve been asked to get a small library terminal type computer up and running using a barcode scanner…

There are two kinds of barcode readers, those that fake keyboard interfaces (keyboard wedges and keyboard usb hids) and those that communicate over the serial bus. The keyboard variety work perfectly with Linux and thus Ubuntu, but the serial readers are a backside pain unless you want to write your own tools which can’t interface effectively with anything that already exists (i.e. Firefox).

But I didn’t get a choice in what barcode reader I was to work with, instead I was given a SerialIO LaserChamp, which comes with a USB to serial interface as well as a memory bank to store more than one barcode. The real solution here would be to digg into the Linux Kernel project and develop a serial keyboard interface driver, much like the 4 already available.

The problem? When I looked at doing just that the code for those devices is not commented at all. The code just expects the programmer to instinctively know what’s going on, and well it’s not too complex a feature to take in scancodes and output key events, but seriously at least explain API use. Since I’m not a C programmer and the Kernel programmers are as helpful as nepalm, I ditched that idea and decided to hack it instead.

Instead I created a small python program which will sit and listen to the serial port and take in the barcodes, then it will output them using xdotool causing the barcode to be typed as if it were a keyboard. Once it was up and running I marveled at how badly I had to hack this up in order to get it working. I’ll have to run the python program as a daemon type service, but meh, it’s not like I’m going to distribute it.

Thanks to Romain Aviolat (xens) for phonixing some code to make this work, you can find code for serial barcode scanners here: On GitHub