I borrowed a serial UPC scanner from work today for some Friday night hacking. It’s a ReaderWare LaserChamp/Flic Barcode reader re-branded under the SerialIO name. It came with a standard serial cable and didn’t have a manual.
First, I booted to my Ubuntu partition to see the raw data from the scanner.
$ cat /dev/ttyS0
No dice. I did some searching and found that the scanner likely ran at 4800 baud.
$ setserial /dev/ttyS0 baud_base 4800
$ cat /dev/ttyS0
^B043396143234
Ah, some data. I removed the control characters and had myself a UPC symbol. I wrote a script and scanned a bunch of books, CDs, and other crap sitting on my desk. I also found a manual for the scanner, which had some settings symbols.
I booted to my XP partition and started Cygwin. I wrote a Perl script to mimic what I did on Linux, except using the Win32::Serial module. I fired up CPAN to grab the library, but CPAN was down. I switched to ActiveState’s Perl distribution and grabbed their Win32:: PPM. I finished the script and tested it. It worked.
A while later I checked CPAN again, grabbing the Win32:: module using Cygwin’s Perl. It didn’t build. This seems typical for Cygwin and CPAN/Perl modules. I moved on.
I switched to C# to see how it compared to Perl and the Linux/Bash hack. I whipped together a simple application that listened for data on a serial port, cleaned it up, and copied it to the clipboard. It worked.
I also attempted to hook the C# code up to the Amazon API (to get ASINs), but found the networking libraries more complicated than I had time for.
My favorite approach? Hands down, I liked the Bash script best. It was one line of code, including cleaning it up with sed. It’s not something I can ship, but it’s the way I’ll scan all of my books/CDs/DVDs.
The Perl Win32::Serial hack was longer (a dozen lines), but it also worked. It was no better than the 1-line Bash script, so I tossed it.
The C# hack consisted of a single form and its supporting class (a few dozen lines of code). It worked, and is easy to distribute. I’ll use this if I’m stuck doing something in Windows.
Total time for all 3 hacks? 3 hours and 25 minutes.