Dynamics CRM Barcode Scanner Integration - Attempt 3

Vitalii Symon, 27 August 2010

This post is the next part of scanner integration story. To recap on how this all began, I was assigned a task to connect a Barcode Scanner to Dynamics CRM. The project came about as one of our customers required such an integration in order to check, monitor and manage attendance levels for events. In my first post, Dynamics CRM Barcode Scanner Integration – Attempt 1, I offered a solution for using the barcode scanner as a virtual keyboard, which worked well but only within its own application. In my second post, Dynamics CRM Barcode Scanner Integration – Attempt 2, I looked at ways to block the input system-wide.

*

As I faced issues with the previous two attempts I had to rethink. I moved back to working with the solution from first post, Attempt 1, because it is more universal and easier to deploy on unknown (to me) infrastructure. Nevertheless I’ve collected some information and created code samples to share.

Since there was no stable and reliable way to communicate with the scanner I decided to try another way of inputting information which is supported by Symbol LS2208 scanner is virtual COM port. You can download drivers for the COM port here on the Symbol website. Install them and configure the scanner to work in old school COM mode.

To do that:

1. Download 123 Scanner configuration Utility.
This tool will just print out configuration barcodes which will be reusable for scanners, so there’s no need to install it on every machine – just scan existing paper. A very comfortable solution in my opinion.

2. Install it

3. Run and connect to your scanner.

Initially the scanner might be not recognized, especially if its plugged in COM or keyboard mode. In that case select the model of the scanner manually (mine was LS2208 for example) and print out the pages. Basically, you need scanner to recognize its model only, no other communications happens.

4. Run the configuration wizard and print out configuration barcodes.
Page will contain several barcodes – first one will reset scanner to its default state, others will be picked up depending on your selection.

5. Scan the barcodes with your scanner and all settings will apply instantly.
Scanner will produce several beeps after each configuration barcode recognized. If it doesn’t – most likely attempt wasn’t successful or speaker is broken.

Now the scanner works as a COM device which is very to communicate with. You can use native .NET classes to communicate with COM port or any others (for example I’ve used JustinIO which appears to be easier for me). You can find more samples for COM port programming on stackoverflow.com and www.codeproject.com. For example this is a draft I was using for a test:

            JustinIO.CommPort port = new JustinIO.CommPort();

            port.PortNum = 2;

            port.Open();

 

            StringBuilder sb = new StringBuilder();

            byte[] b = new byte[100];

 

            do

            {

                do

                {

                    b = port.Read(1);

                    sb.Append(Encoding.ASCII.GetChars(b));

                    Thread.Sleep(20);

                } while (b.Length > 0);

 

                if (sb.Length > 0)

                {

                    Console.WriteLine(sb.ToString());

                    sb = new StringBuilder();

                }

            } while (true);

Don’t forget to make the port number configurable because the number of virtual ports might vary on different computers.

The last way I am looking at to resolve the problem allows hiding scanning process from the user to the background and use scanner at any time no matter which application is currently in focus.

The only problem of using COM is that the virtual driver wasn’t updated by the manufacturer since 2005 and has no 64-bit version.

To conclude, if you are sure that your software will be launched on x86 platforms only – go for it. It will work in hidden mode with no extra noise and customers will be happy to scan items without opening extra windows. Otherwise use solution from my first post Attempt 1.

This method of things makes me sad, but device driver is supplied by a manufacturer and were only last updated in 2005. Also, a good point to think about is customer support - using standardized or compatible drivers and maybe going open-source for sensitive programs like driver for this scanner.

* Image from http://www.sagedata.com/images/2007/Code_128_Barcode_Graphic.jpg