[TriZPUG] [newbie] bind character device output

Tom Roche Tom_Roche at pobox.com
Sat Mar 27 23:09:08 CET 2010


Chris Calloway Fri, 26 Mar 2010 16:17:47 -0400
> I think at the next Hack Night I will try to help some newbies
> instead of get so hung up on my own project.

Why wait til Hack Night ?-) As an actual pynewbie needing help with an
real problem, I'd like to learn about pythonically redirecting the
output from a character device to a particular file or process,
regardless of focus, on a generic graphical OS. Here's the usecase:

Woody Allen said 80% of life is just showing up. This semester I've
TAed a seminar for which 50% of one's grade is just showing up with
one's UNC ID card, which has a barcode on the back, which we record
with a handheld USB scanner. This is pretty straightforward, except
that the barcode scanner is like a keyboard writing the ASCII
equivalent of the barcode (== the student's ID#) to whatever frame has
focus at the time. Since the scanner is connected to an ordinary
student laptop (I use ubuntu, but others will probably use mac or
windows), on which one will likely be doing other things while
scanning (notably setting up to record the presenter), it sometimes
happens (and happened a lot more when I started) that I write to
something other than the text file into which I mean to record
attendee ID#s. This semester happens every {fall, spring}, so someone
will face this pitfall again.

How to prevent that? The trivial solution--shlep a dedicated USB host
for the scanner--is deprecated. Rather, It Would Be Nice, and useful
for this seminar's mechanics, to be able to run some code to which one
could say, see this device? and this file? Make the device's output go
only to that file. For extra credit, don't let anything else write
that file while this code is running.

I'm pretty sure this can be done if one gets close enough to the metal
(e.g., doesn't *nix 'dd' require that?), but for future use this code
probably needs to be portable. I tried googling, but saw only
tutorials on python string processing.

TIA, Tom Roche <Tom_Roche at pobox.com>


More information about the TriZPUG mailing list