public MFTestResults MFPortDefinitionEnumerationTest()
        {
            MFDeploy dep = new MFDeploy();

            try
            {
                int count = dep.DeviceList.Count;
                Log.Comment("Found " + count + " PortDefinitions.");
                int i = 1;
                foreach (MFPortDefinition pd in dep.DeviceList)
                {
                    Log.Comment("====================================");
                    Log.Comment("Port Definition " + i++);
                    Log.Comment("====================================");
                    Log.Comment("Name = " + pd.Name);
                    Log.Comment("Port = " + pd.Port);
                    Log.Comment("Transport = " + pd.Transport);
                }
                Log.Comment("====================================");
                Log.Comment("Successfully iterated through all the enumerations");
                Log.Comment("====================================");
            }
            catch (Exception ex)
            {
                Log.Exception(ex.Message);
                return(MFTestResults.Fail);
            }

            return(MFTestResults.Pass);
        }
Exemple #2
0
 public void Dispose()
 {
     foreach (var item in _devices)
     {
         item.Dispose();
     }
     _devices.Clear();
     _deploy.Dispose();
     _deploy = null;
 }
Exemple #3
0
 public DeviceModel()
 {
     _deploy = new MFDeploy();
     _deploy.OnDeviceListUpdate += _deploy_OnDeviceListUpdate;
     // This is slow and needs to run in the background
     Task.Run(() => UpdateDeviceList());
     _healthCheck          = new Timer(10 * 1000);
     _healthCheck.Elapsed += HealthCheckOnElapsed;
     _healthCheck.Enabled  = true;
     _healthCheck.Start();
 }
        static void Main(string[] args)
        {
            using (MFDeploy deploy = new MFDeploy())
            {
                // Obtain devices connected to USB port
                IList <MFPortDefinition> portDefs = deploy.EnumPorts(TransportType.USB);

                // List devices
                Debug.WriteLine("USB Devices:");
                foreach (MFPortDefinition portDef in portDefs)
                {
                    Debug.WriteLine(portDef.Name);
                }

                // Return if no device was found
                if (portDefs.Count == 0)
                {
                    Debug.WriteLine("No device.");
                    return;
                }

                // Connect to first device that was found
                using (MFDevice device = deploy.Connect(portDefs[0]))
                {
                    uint entryPoint = 0;
                    if (device.Deploy("c:\\myapp.hex", // deployment image
                                      "c:\\myapp.sig", // signature file (optional)
                                      ref entryPoint   // return apps entry point
                                      ))
                    {
                        Debug.WriteLine("Deploying succeded.");

                        if (entryPoint != 0) // check if image has an entry point
                        {
                            Debug.WriteLine("Executing application.");
                            device.Execute(entryPoint);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Deploying failed.");
                    }
                }
            }
        }
Exemple #5
0
        private void Form1_FormClosing(System.Object sender, FormClosingEventArgs e)
        {
            m_fShuttingDown = true;

            if (m_pluginThread != null && m_pluginThread.IsAlive)
            {
                m_pluginThread.Abort();
            }

            if (m_device != null)
            {
                m_device.Dispose();
                m_device = null;
            }

            if (m_deploy != null)
            {
                m_deploy.Dispose();
                m_deploy = null;
            }
        }
Exemple #6
0
        internal void Execute()
        {
            MFDeploy deploy = new MFDeploy();
            MFDevice port   = null;

            try
            {
                switch (m_cmd)
                {
                case Commands.Help:
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpBanner);
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpDescription);
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpUsage);
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpCommand);
                    foreach (CommandMap cm in m_commandMap)
                    {
                        Console.WriteLine("  " + cm.HelpString);
                    }
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpInterface);
                    foreach (InterfaceMap im in m_interfaceMap)
                    {
                        Console.WriteLine("  " + im.InterfaceHelp);
                    }
                    Console.WriteLine();
                    Console.WriteLine(Properties.Resources.HelpInterfaceSpecial);
                    Console.WriteLine();
                    break;

                case Commands.List:
                    foreach (MFPortDefinition pd in deploy.DeviceList)
                    {
                        Console.WriteLine(pd.Name);
                    }
                    break;

                case Commands.Ping:
                    Console.Write(Properties.Resources.StatusPinging);
                    try
                    {
                        port = deploy.Connect(m_transports[0]);
                        Console.WriteLine(port.Ping().ToString());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                    }
                    break;

                case Commands.Erase:
                    Console.Write(Properties.Resources.StatusErasing);
                    try
                    {
                        port             = deploy.Connect(m_transports[0]);
                        port.OnProgress += new MFDevice.OnProgressHandler(OnStatus);
                        Console.WriteLine((port.Erase() ? Properties.Resources.ResultSuccess : Properties.Resources.ResultFailure));
                        port.OnProgress -= new MFDevice.OnProgressHandler(OnStatus);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                    }
                    break;

                case Commands.Deploy:
                    try
                    {
                        bool fOK        = false;
                        uint entrypoint = 0;

                        port = deploy.Connect(m_transports[0]);

                        foreach (string file in m_flashFiles)
                        {
                            uint     entry          = 0;
                            FileInfo fi             = new FileInfo(file);
                            string   signature_file = file;

                            if (fi.Extension != null || fi.Extension.Length > 0)
                            {
                                int index = file.LastIndexOf(fi.Extension);
                                signature_file = file.Remove(index, fi.Extension.Length);
                            }

                            signature_file += ".sig";

                            if (!File.Exists(file))
                            {
                                Console.WriteLine(string.Format(Properties.Resources.ErrorFileNotFound, file));
                                break;
                            }

                            if (!File.Exists(signature_file))
                            {
                                Console.WriteLine(string.Format(Properties.Resources.ErrorFileNotFound, signature_file));
                                break;
                            }

                            Console.WriteLine(string.Format(Properties.Resources.StatusFlashing, file));
                            port.OnProgress += new MFDevice.OnProgressHandler(OnDeployStatus);
                            fOK              = port.Deploy(file, signature_file, ref entry);
                            port.OnProgress -= new MFDevice.OnProgressHandler(OnDeployStatus);
                            Console.WriteLine();
                            Console.WriteLine((fOK ? Properties.Resources.ResultSuccess : Properties.Resources.ResultFailure));
                            if (entry != 0 && entrypoint == 0 || file.ToLower().Contains("\\er_flash"))
                            {
                                entrypoint = entry;
                            }
                        }
                        if (fOK)
                        {
                            Console.WriteLine(string.Format(Properties.Resources.StatusExecuting, entrypoint));
                            port.Execute(entrypoint);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                    }
                    break;

                case Commands.Reboot:
                    try
                    {
                        port = deploy.Connect(m_transports[0]);
                        Console.WriteLine(Properties.Resources.StatusRebooting);
                        port.Reboot(!m_fWarmReboot);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message);
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format(Properties.Resources.ErrorFailure, e.Message));
            }
            finally
            {
                if (deploy != null)
                {
                    deploy.Dispose();
                    deploy = null;
                }
            }
        }