예제 #1
0
    public int Connect()
    {
        int retval = 0; /* okay */

        if (m_device != null)
        {
            Interlocked.Increment(ref m_devRefCount);
        }
        else
        {
            MFPortDefinition port;
            try
            {
                port = FindHeroPortDef();
            }
            catch (Exception excep)
            {
                Console.Out.WriteLine(excep.Message);
                return(-5); /* exception suggests HERO is connected to VS */
            }

            if (port == null)
            {
                retval = -1; /* could not find a device */
            }
            else
            {
                try
                {
                    m_device = m_deploy.Connect(port, null);

                    if (m_device != null)
                    {
                        m_device.OnDebugText += new EventHandler <DebugOutputEventArgs>(OnDbgTxt);

                        Interlocked.Increment(ref m_devRefCount);
                    }
                    else
                    {
                        retval = -2; /* tried to connect and failed */
                    }
                }
                catch (Exception)
                {
                    retval = -3; /* tried to connect and failed */
                }
            }
        }
        return(retval);
    }
예제 #2
0
        private MFDevice ConnectToNetmfDevice(MFPortDefinition port)
        {
            MFDevice result = null;

            try
            {
                result = _deploy.Connect(port);
            }
            catch
            {
                MessageBox.Show(
                    "Failed to connect to device. You may need to reset your board or restart this program.", "Error",
                    MessageBoxButton.OK);
                result = null;
            }
            return(result);
        }
        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.");
                    }
                }
            }
        }
예제 #4
0
        private MFDevice ConnectToSelectedDevice()
        {
            if (m_device != null)
            {
                Interlocked.Increment(ref m_deviceRefCount);
            }
            else
            {
                MFPortDefinition port = null;
                this.Invoke((MethodInvoker) delegate
                {
                    port = GetSelectedItem();
                });

                if (port != null)
                {
                    try
                    {
                        m_device = m_deploy.Connect(port, port is MFTcpIpPort ? m_transportTinyBooter : null);

                        if (m_device != null)
                        {
                            comboBoxTransport.Invoke((MethodInvoker) delegate
                            {
                                comboBoxDevice.Enabled           = false;
                                comboBoxTransport.Enabled        = false;
                                connectToolStripMenuItem.Enabled = false;
                            });

                            m_device.OnDebugText += new EventHandler <DebugOutputEventArgs>(OnDbgTxt);
                            Interlocked.Increment(ref m_deviceRefCount);
                        }
                    }
                    catch (Exception exc)
                    {
                        DumpToOutput(Properties.Resources.ErrorPrefix + exc.Message);
                    }
                }
            }
            return(m_device);
        }
예제 #5
0
        public async Task <bool> ConnectToDevice(ComboBox deviceList)
        {
            // Already connected to a device or invalid item selected
            if (Device != null || deviceList.SelectedIndex >= 0)
            {
                return(false);
            }
            var port = (MFPortDefinition)deviceList.SelectedItem;

            Device = await Task.Run(() =>
            {
                var device = _deploy.Connect(port, null);
                if (device == null)
                {
                    return(null);
                }
                device.OnDebugText += Handler.Process;
                return(device);
            });

            return(Device != null);
        }
예제 #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;
                }
            }
        }