3

How to obtain a Motorola (Symbol) Mobile Device Serial Number?

I'm programming the Motorola ES400 which comes with "Symbol" libraries.

There seems to be ways of getting the serial numbers of the various scanners, but not of the actual device itself!

Anyone got any ideas?


Whats the difference between "serial number" (as shown on the device) and "electronic serial number" returned by TerminalInfo?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
DomBat
  • 1,981
  • 5
  • 27
  • 42

4 Answers4

4

I just dealt with this on the MC9090 device, which also uses the Symbol libraries (not sure if they are the same, but this is worth a shot). I used reflection because I have devices from different manufacturers and want the same code to run. You could access this field directly from the property or use reflection:

Here is where the property is:

Symbol.ResourceCoordination.Terminalinfo.ESN

Here is my method using reflection:

try
        {                   
                Assembly symbolApi = Assembly.LoadFrom("Symbol.ResourceCoordination.dll");      

                Type terminalInfo = null;

                foreach (Type t in symbolApi.GetTypes())
                {
                    if (t.Name == "TerminalInfo")
                    {
                        terminalInfo = t;                       
                        break;
                    }
                }

                LogService.log(terminalInfo.Name);

                if (terminalInfo != null)
                {
                    object objTerminalInfo = Activator.CreateInstance(terminalInfo);

                    PropertyInfo esn = null;
                    foreach (PropertyInfo info in terminalInfo.GetProperties())
                    {                           
                        if (info.Name == "ESN")
                        {
                            esn = info;
                            break;
                        }
                    }

                    if (esn != null)
                    {
                        object objSn = esn.GetValue(objTerminalInfo, null);
                        sn = objSn.ToString();
                    }
                }
                else
                    LogService.log("TerminalInfo type not found in " + symbolApi.FullName);

        }
        catch (MissingFieldException e)
        {               
            LogService.log("MissingFieldException, not Symbol Unit: " + e.Message);
        }
        catch (Exception e)
        {
            LogService.log("Error in SymbolAPI: " + e.Message);
        }

Hope this helps!

IronicMuffin
  • 4,182
  • 12
  • 47
  • 90
  • Why all the for/each loops? Why not use GetType(string) to get the TerminalInfo Type and similarly GetProperty(string) to get the ESN property? And since the ESN presumably will never change, I'd recommend caching the value once acquired to prevent doing this more than once. – ctacke Dec 31 '10 at 15:41
  • I did cache this and only called it if I didn't already have it. The for/each loops were because the GetType(string) method was returning null, and I couldn't really take too much more time to figure out why. – IronicMuffin Dec 31 '10 at 21:06
0

Here's the quick and easy VB.Net solution:

Add a reference to Symbol.ResourceCoordination.dll (I found mine here: C:\Program Files\Motorola EMDK for .NET\v2.8\SDK\Smart Devices\Symbol.ResourceCoordination.dll).

Then use the following code to access the ESN (Electronic Serial Number) value.

Dim Version As New Symbol.ResourceCoordination.TerminalInfo
MsgBox(Version.ESN)

Worked great on our MC3190S scanners! :)

Matty Brown
  • 404
  • 3
  • 16
0

Thats fantatic, thanks. The Symbol SDK help didn't find this when searching!

Just used:

Symbol.ResourceCoordination.TerminalInfo  Version = new Symbol.ResourceCoordination.TerminalInfo();

        return Version.ESN;
DomBat
  • 1,981
  • 5
  • 27
  • 42
0

Also found this:

            Symbol.ResourceCoordination.TerminalInfo  Version = new Symbol.ResourceCoordination.TerminalInfo();

        System.Text.StringBuilder MyUUID = new StringBuilder("0x") ;

        if (Version.UniqueUnitID != null)
        {
            //this code is actually from the Motorola SDK guid 
            foreach (byte b in Version.UniqueUnitID)

                MyUUID.Append(b.ToString("X2"));

        }

        return MyUUID.ToString();
DomBat
  • 1,981
  • 5
  • 27
  • 42