Monday, October 01, 2007

Here's the second part of what I was banging on about yesterday.  To automatically decide which type of barcode reader is attached to the mobile device we need to know what device we are on.

 

I used a Pinvoke for SystemparetersInfo to return the name of  the manufacturer (and sometimes model) of the device.    An MSDN sample did the hard work for me.    Here's the bit of code you need -

private static class NativeMethods
     {
         [DllImport("coredll.dll")]
         private static extern int SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWiniIni);

         private const uint SPI_GETPLATFORMTYPE = 257;
         private const uint SPI_GETOEMINFO = 258;

         private static string GetSystemParameter(uint uiParam)
         {
             StringBuilder sb = new StringBuilder(128);
             if (SystemParametersInfo(uiParam, (uint)sb.Capacity, sb, 0) == 0)
                 throw new ApplicationException("Failed to get system parameter");
             return sb.ToString();
         }

         public static string GetOEMInfo()
         {
             return GetSystemParameter(SPI_GETOEMINFO);
         }


     }

 

The final bit is to work out which barcode reader is attached is -

public static bool IsEmulator
        {
            get { return (NativeMethods.GetOEMInfo() == "Microsoft DeviceEmulator"); }
        }

public static Scanner ScannerSelect()
    {
        if (Core.IsEmulator)
        {
            return new ScanningDummy();
        }

        string x = NativeMethods.GetOEMInfo();
        if (x.StartsWith("SYMBOL"))
        {
            return new ScanningSymbol();
        }

        if (x.StartsWith("Intermec"))
        {
            return new ScanningIntermec();
        }

        if (x.StartsWith("DataLogic"))
        {
            return new ScanningDataLogic();
        }
        MessageBox.Show("Unknown Scanner Type - " + x);
        return new ScanningDummy();

    }

}

 

There you have it.    One code base supporting multiple different types of scanner

Monday, October 01, 2007 8:17:53 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: