且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得摩托罗拉(Symbol)移动设备序列号?

更新时间:2022-11-29 18:21:12

我刚刚在 MC9090 设备上解决了这个问题,它也使用了符号库(不确定它们是否相同,但这值得一试).我使用反射是因为我有来自不同制造商的设备并希望运行相同的代码.您可以直接从属性访问此字段或使用反射:

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:

这里是房产所在:

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);
        }

希望这会有所帮助!