APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Why I have to use Unix: scanning name tag badges

Referencing: Unix vs. PC again

I had email from a client who needed to use handheld scanners to scan visitor badges and determine if the badge had already been used that day. I quickly came up with some protocode that would run against the device the scanner(s) were connected to.

It's not efficient code. It does a lot of opening and closing. Part of the reason for that is simplicity, and the other reason is that this was to be used in hostile territory where the power might die at any minute, etc - we wanted to write early, write often. There are better ways of doing that, too, but again, this was just a quick, ad-hoc solution.

Now yeah, you could do this on Windows, probably even with similar code. But my bet is you wouldn't. In fact, I bet if you had to do this on Windows, it would either never get done at all or cost you a pretty penny at least.

Now sure, part of the reason for that is that I know it can be done and know how to do it. If you happened to have a Windows person with similar talents, it wouldn't be a big deal. But my point is that the Windows customer wouldn't ordinarily think that this would be something they could write themselves. What devices does the scanner use? Who the heck knows, that's buried in the device driver. Will it even do multiple scanners? How do you conveniently tie Perl to the device(s)?

It just isn't as direct, and as I said, my bet is it just wouldn't get done. The client would go shopping for Windows Badge Scanning Software.Try a Google search for that and you'll see what I mean: most of it wants an NT Server, Oracle or Access, and $$$. And as is almost always true, it probably does much, much more than you need it to do. This client just wants to scan a badge number: she doesn't want to track leads, she doesn't want to buy a big NT server or Palm Pilots instead of scanners. She carries a cheap little Linux machine to the show, a little network switch (these are network connected scanners), runs multiple instances of this little script, and she has what she wants. If she needs to add features or make changes while at the show, well, it's just a Perl script: change it. That's another reason the code is simplistic: a less techy user may want to mess with it.

#!/usr/bin/perl
while (1) {
       $line = <>;
       exit 0 if $line =~ /quit/i;
       chomp;
       $rightnow=time();
       ($sec, $min, $hour, $mday, $mon, $year) = localtime($rightnow);
       # if it's after 3 PM it's "tomorrow"
       $rightnow += (24 * 3600) if $hour > 14;
      ($sec, $min, $hour, $mday, $mon, $year) = localtime($rightnow);
       $date=sprintf("%0.2d%0.2d%0.2d",$mon+1,$mday,$year-100);

       open(LOCK,"/tmp/mylockfile");
       flock(LOCK,2);
       #dbm files aren't multi-user safe so we lock

       dbmopen(%db,"/usr/home/tagfile",0666);

       $key = "$line $date";
       if ($db{$key}) {
          print "\007" .$line . "already in db $date";
       }
       $db{$key} = "1";
       dbmclose %db;
       flock(LOCK,8);
       close LOCK;
       }
 

That's all of it. You could add more features, like storing the full date and time instead of just a "1", or scanning information and storing it, and you could use the database after the show to make reports of vistors, etc. And the interface could be more user friendly, could be gui-fied, etc. But as it sits, she can connect her hand held scanners and get what she wants.


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Why I have to use Unix: scanning name tag badges


1 comment



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence




"Why I have to use Unix: scanning name tag badges"

The title could have been "Why I have to avoid using Windows: scanning name tag badges."

This is a classic example of properly sizing the hammer to the nail. Or in naval terms, there is never any reason to deploy a battleship to sink a rowboat. Based upon exhaustive calculations carried out here at the Dinosaur Development Depot, if this had been done in Windows the program would have four times as big, 16 times as expensive and 256 times as bug-prone, an exponential relationship possible only with Windows.

--BigDumbDinosaur

---July 21, 2004





------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





I just invent, then wait until man comes around to needing what I've invented (R. Buckminster Fuller)

Try not to become a man of success, but rather try to become a man of value. (Albert Einstein)












This post tagged: