Intermec Scan Configuration

I received a CN3 today to try out with our snapRetail applications and at first it seemed like things weren’t working correctly with scanning, but it soon became apparent that it was just a matter of scanner configuration.

Virtual Wedge

Virtual Wedge ConfigurationThe first problem I had was ironically the problem of scanning ocurring when I it should be disabled. By default Intermec has enabled a keyboard wedge, “Virtual Wedge”, that accepts barcode data from the scanner and generates key events to simulate that the data has come from the keybooard. This is easy enough to disable, just go in to Intermec Settings (Settings->System->Intermec Settings) and disabled the Virtual Wedge and after copying the Intermec Data Collection dll over to my program the terminal scanned only when I wanted.

While I guess it’s ok to enable this by default, though it has always been a pet peeve of mine to call applications barcode enabled, when all they are doing is using a keyboard wedge. While this “works”, it creates an incredibly clumsy interface for barcode scanning that keeps the scanner always enabled, and puts barcode data anywhere the keyboard focus is set. This may be “ok” for consumer devices, so I can put barcode data in my Word document, but for “real” applications it is really a bad idea.

What bothers me even more is when people claim that they have a barcode-enabled handheld program, when all they’ve done is turn the keyboard wedge on. Perhaps the worst case of this “mis-advertising” I’ve seen was during the keynote of the 2006 Microsoft Embedded Developers Convention where they demonstrated creating a “barcode enabled application” to a roomful of developers when all they had done was use a keyboard wedge. Perhaps if they would have attended my session they would have been able to do it the real way ;-).

Automatic Symbology Conversion

Once I got back to being able to control the scanner, and configure the Symbologies, I went in to the Item Lookup application to try scanning some barcodes. Everything seemed to be scanning fine, except that whenever I scanned a UPC code I was receiving thirteen digits (with a leading zero) instead of twelve as I was expecting from a UPC barcode.

UPC A xmit as EAN 13This gets in to the whole world of automatic barcode conversions. In order to support the requirements of different industries and governments there are a broad variety of similar, but slightly different symbologies. This means that for a US-based retail , the developer must take in to consideration EAN8, EAN13, UPCA, UPCE0, and UPCE1 barcode symbologies. In addition, there are also UPC Supplemental barcodes (extra information often used on books for ISBN numbers), check digits, and expansion of EAN8 barcodes to EAN13.

In this case, the default configuration that Intermec has selected is to convert everything to an EAN13 symbology which in my case caused the problem. This is also configurable through the Intermec Settings application, and disabling the conversion “UPC A xmit as EAN 13” solved my problem. Alternately, this can be configured programmatically through the Intermec Data Collection API but I like keeping these types of paramaters configurable by the end user.

However, the lesson is that even if the hardware vendors decide to make it easy for the application developer to use barcodes, its still important for them to understand what “magic” is happening under the covers.

Intermec Scan to Exit

We had another very curious incident, this time on an Intermec terminal. Each time the terminal scanned a barcode our application would immediately exit.  No warning, no exception, nothing but an immediate exit.  And it wasn’t even a complicated application, just a simple prototype.

What made this even more curious was that it didn’t happen on all of our Intermec terminals and hadn’t occurred in the past with our other customers.  A few more details will make the problem a little clearer.  First of all we are developing in .NET CF 2 with VS.NET 2005 and our SNAP application framework.  The Intermec 760B terminal is running Pocket PC 2003 (OS 4.51 Premium with PSM 3.93.1 for 32MB Flash) and the Intermec 2.4 IDL.Intermec 700 Series Terminals

So it was a matter of rolling up our sleeves and getting down in to the bowels of the source code.  Initially we suspected that there was an exception in the scanner dll causing the application to abort.  We tried the usual tasks such as walking through the code (difficult since scanning is event driven), and catching exceptions on invocation instead of where they are caught, all to no avail.  Finally, it was a matter of controlling the scanning to catch the error, where we found a Windows Message conflict, essentially programmatically triggering the scanner to control the execution in the debugger.

Apparently Intermec has implemented their scanner code using messages and happened to assign the same Window Message ID (WM_USER+1 =  0x401) that we were using for exiting a sequence of forms (in this case out of the application).  And that’s the end of the application.

So what does that mean.  The first thing one could argue is that a system object like this should not expose the window messages to the application, or at least not use one that is quite so common. And I’d think you’d have a pretty good argument there. 

So the simple solution is that rather than using WM_USER as our Message ID base, we could use a value that is unique within the system.  The easy way to do this is to register the window message with the OS and request a unique id.  Simply use the method:

[DllImport("CoreDll.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern uint RegisterWindowMessage(string lpString);

static uint WM_MY_MSG = // use RegisterWindowMessage to ensure unique

Of course this isn’t 100% perfect since you can still have people using the same string to register their message.  To take it the next step you can create a GUID, but I think that’s getting a bit much.  Just use a reasonable unique name and everything should be fine.