[]RSS

About Archives Artwork Comic Contact Philosophy Projects Tags

Hack of the day: serial programming on Linux versus Windows

[Comment]

October 19th, 2007 in Programming

screenshotI 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 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 symbols1.

I booted to my XP partition and started . 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 modules2. I moved on.

I switched to C# to see how it compared to Perl and the Linux/Bash hack. I whipped together a simple application3 that listened for data on a serial port, cleaned it up, and copied it to the clipboard. It worked4.

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 for5.

My favorite approach? Hands down, I liked the Bash script6 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 minutes7.

  1. You print the page and scan the symbols to change the scanner’s settings
  2. Most of the tests failed for the Win32::Serial module
  3. And the .NET build of it
  4. C#’s serial code was nicer than Perl’s, but not as nice as the devfs hack
  5. Perl’s networking is much nicer than C#’s
  6. Bash and devfs’s /dev/ttyS0
  7. My wife and kids were out for the evening

Libra, UPC scanning and tracking for DVDs, books, and other stuff

[Comment]

August 17th, 2007 in Links

Libra is a free Windows clone of the great Mac Delicious Monster Library tool.

Gimp UI revamp planned

[Comment]

July 29th, 2007 in Links

Here’s a short post about the upcoming Gimp UI overhaul (the resulting comments are typical).

Plot versus content in games

[Comment]

January 11th, 2007 in Links

Here’s an excerpt from an upcoming book that describes process intensity, which is the amount of processing power (and effort spent developing it) used by the plot of a game. Some more background on the concept of process-intensity.

Ubuntu concept art

[Comment]

July 20th, 2006 in Links

Some artwork in progress for upcoming releases. Mmmmm … shiny vectors …

In-depth not-so-positive review of Vista

[Comment]

April 21st, 2006 in Links

Windows Vista February 2006 Build Review, Part 5: Where Vista Fails. An interesting look at some of the upcoming limitations in Microsoft’s new OS.

How to Read 12 Digit UPC Barcodes

[Comment]

November 17th, 2005 in Links

How to Read 12 Digit UPC Barcodes. I’ve been thinking of writing a web app to do this … now at least I know how they work.