Automated Testing of Bar Code Scanners for Flash Museum Installations.
byBruce on Jul.22, 2010, under Hardware, Software
We have a Flash application that takes an input from a bar code scanner via serial keys in windows. Each time a ticket is read by the scanner, it’s translated into a keyboard input, and that is sent to the Flash application. The application can then analyze the string of characters, validate them through php with a Microsoft SQL database, and return whatever info we need. It’s a good example of integrating Flash with an external input device – the scanner. Although the scanner we’re using requires a few pieces of software to send keyboard command (because of the way it works with the touchscreen), most just emulate a keyboard input when an item is scanned.
Because what we’re making has to work hundreds of times a day, every day, we needed a way to do some solid stress testing. It wasn’t practical to have one of us sit in front of a computer with a ticket and scan it every 5 seconds to make sure that our application and the hardware were functioning properly. So, Charles came up with the idea to trigger a small servo motor to scan a ticket every XX number of seconds. In about two hours, he had the device you see below. It is pretty utilitarian, but the main function is to just make sure the ticket scans properly, so it doesn’t have to be too sexy. The program is actually a modified version of the servo motor example that ships with the Make Controller that we have used in a few exhibits. The controller is pretty handy for connecting Flash to all sorts of external devices.
We’re not showing the actual program we’re testing, but instead you can see the input from the scanner appear on notepad. It helped us assure that our software could take the continuous input of thousands of scans a day and still be functioning well.
July 22nd, 2010 on 2:52 pm
Nice article Bruce!
I know you are tempted to approve the purchase of a robotic arm for this kind of testing.
I could definitely have it programmed in only…3 hours.. ha ha!
July 27th, 2010 on 8:15 am
Hey Bruce – I’m in the research phase of trying to communicate between a bar-code scanner and a flash application myself. I would love to be able to direct a few questions your way and hopefully get pointed in the right direction. Any help would be much appreciated!
July 27th, 2010 on 9:56 am
Sean,
I’d be happy to answer any questions you have. We did a good amount of work with some different methods, so hopefully I can point you in the right direction.
July 27th, 2010 on 11:37 am
What I’m basically trying to accomplish is a user check-in. Where scanning a badge(barcode) would initiate an animation and “unlock” the interactive touchscreen to them. Similar to your validation with PHP, their unique barcode would identify the user, and log their progress (maybe more than one kiosk).
Which leads me to a few questions:
- Did you use a standalone .swf, or wrap it in zinc/AIR for added support?
- What method did you use to listen for the scan? For instance, did you run an interval on a textbox (that was filled after scan generated a keycode string)?
Just trying to wrap my head around this technology, thanks for any insight you may have. Kudos on the testing rig as well!
July 27th, 2010 on 12:37 pm
Sean,
First, to answer your questions.
1. We used a compiled .exe since this was running full-screen on a kiosk. It did not use any sort of wrapper like Zinc. It was an AIR application, but was so because it had to read and write image files, not because it had to interact with the scanner. The barcode scanner sends the code it has scanned as keystrokes, so the application can listen and respond to that. There was not any special code needed to accept that input from the scanner. I can’t speak to the exact functionality of your scanner, but most emulate keyboard input.
2. To listen for the scan, I set up a listener on keystrokes and kept a buffer (length configurable in my XML) in my program which was the length of however long the codes you’re using are. The scanner probably sends a return character after each scan, one of ours actually sent the equivalent of pressing the command key. Each key that is received by our listener gets added to the front of the buffer, and, if the buffer is full, the last character gets knocked off the end. When the return character is detected, the buffer is sent to validate the user. In our case, this was through PHP to a SQL database. The code I used to manage the buffer is below.
private var keyboardBuffer
function checkKey(e:KeyboardEvent):void {
//Add the key to the buffer
//Make sure it’s not our return character, in this case that code was 17
if (e.keyCode != 17) {
keyboardBuffer += String.fromCharCode(e.charCode);
//Check the contents of the buffer
trace(”The keyboard buffer is:”, keyboardBuffer);
}
//
//If the buffer is full, then cut it down.
if (keyboardBuffer.length > config_xml.config.digitBuffer) {
keyboardBuffer = keyboardBuffer.substring(keyboardBuffer.length – config_xml.config.digitBuffer, keyboardBuffer.length);
}
//
//If it’s our return character, then send it to the function to validate
if (e.keyCode == 17){
//Put validation function here.
validateUser(keyboardBuffer);
}
}
My program actually has other things that happen here, such as keyboard shortcuts, etc. But, by keeping a buffer, and checking it every time you get the return character from the scanner, you know that you’ll always be validating the same number of characters. Hopefully this helps out a bit.
August 10th, 2010 on 1:29 pm
I wanted to chime in as well as I did the PHP work that interfaces with the database.
I made it so that the php portion of this deals with specific URL parameters that allow interaction with the database. Anyone that has worked with AJAX programming in javascript will be somewhat familiar with this technique.
Basically we always have the php portion of the code output a specific format of xml.
You can use a URLRequest and URLLoader in Flash in order to make the request to the php script with certain parameters and then read its XML output. We were able to cast the results of a URLLoader into XML in order to make the data easier to traverse inside the Flash kiosk applications.
By passing the read barcode from flash to PHP, we were able to write database queries in PHP that obtained specific data based on the barcode and return it to the kiosk.
I had great success using the MS SQL Server PHP driver in order to make our queries to SQL Server 2008. It seems to be very stable and fast.