Friday, September 28, 2007

Today I was asked whether as well as a Symbol barcode scanner, my application could also run on an Intermec device.    Being both Windows Mobile 5, I figured that shouldn't be much of a big deal.

However as ever the only difference between the two machines was the drivers for the barcode scanners.    I didn't fancy having to have a Symbol and Intermec version of my code.   So I went for it and did what I've been meaning to-do for a while build an abstract class that I could use as a prototype for supporting any type of barcode reader.   This is what I came up with -

public abstract class Scanner
    {
        public event ScanEventHandler Scan;

        public delegate void ScanEventHandler(object sender, string data);

        public abstract void Start();
        public abstract void Stop();

        protected bool started = false;
        protected void doscan(string txt)
        {
            if (Scan != null) Scan(this, txt);
        }
    }

 

I then wrote a class that implemented the code required to support each barcode reader type -

i.e

public class ScanningSymbol:Scanner
{

// gubbins of code in here

}

I had to of course implement the start and stop methods, when I want the event raised to tell us when we have received a bardcode call doscan(barcodetext)

 

I had to also implement a dummy class that coped with a device without a barcode reader, i.e the device emulator.

The final part of the implementation is to automatically decide which barcode reader the device has built in/attached,  but we'll cover that next time.

Friday, September 28, 2007 9:04:42 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: