void Stop()
        {
            if (m_worker != null)
            {
                m_worker.Abort();
                m_worker.Join();
                m_worker = null;
            }

            if (m_fl != null)
            {
                m_fl.Stop();
                m_fl = null;
            }

            if (m_eng != null)
            {
                m_eng.Stop();
                m_eng = null;
            }
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null) return;

                _DBG.Engine engine = device.DbgEngine;

                ReadOnlyCollection<string> files = form.Files;
                if (files.Count == 0) return;

                uint address = uint.MaxValue;

                _DBG.PortBooter fl = new _DBG.PortBooter(engine);
                fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                fl.Start();

                try
                {
                    foreach (string file in files)
                    {
                        if (!File.Exists(file))
                        {
                            form.DumpToOutput(string.Format("Error: File doesn't exist {0}", file));
                            continue;
                        }

                        ArrayList blocks = new ArrayList();

                        uint tmp = _DBG.SRecordFile.Parse(file, blocks, null);

                        m_form = form;

                        fl.Program(blocks);

                        if (address == uint.MaxValue)
                        {
                            if (tmp != 0)
                            {
                                address = tmp;
                            }
                        }
                    }

                    if (address == uint.MaxValue) address = 0;

                    m_form.DumpToOutput(string.Format("Executing address 0x{0:x08}", address));
                    fl.Execute(address);
                    System.Threading.Thread.Sleep(200);
                }
                finally
                {
                    if (fl != null)
                    {
                        fl.OnProgress -= new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                        fl.Stop();
                        fl.Dispose();
                    }
                }
            }
Example #3
0
        bool Process(string[] args)
        {
            string port     = null;
            uint   baudrate = 0;
            bool   fWait    = true;
            int    i;

            if (args.Length == 0)
            {
                Usage();
                return(false);
            }

            for (i = 0; i < args.Length; i++)
            {
                string arg = args[i].ToLower();

                if (arg == "-port")
                {
                    port = args[++i]; continue;
                }
                if (arg == "-baudrate")
                {
                    baudrate = UInt32.Parse(args[++i]); continue;
                }
                if (arg == "-nowait")
                {
                    fWait = false; continue;
                }

                if (arg == "-com1")
                {
                    port = "COM1"; baudrate = 115200; continue;
                }
                if (arg == "-com2")
                {
                    port = "COM2"; baudrate = 115200; continue;
                }

                if (arg == "-write")
                {
                    try
                    {
                        string file = args[++i];

                        Console.WriteLine("Loading {0}...", file);

                        Microsoft.SPOT.Debugger.SRecordFile.Parse(file, m_blocks, null);

                        Console.WriteLine("Loaded.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("{0}", e.ToString());
                        return(false);
                    }

                    continue;
                }

                if (arg == "-writeandexecute")
                {
                    try
                    {
                        string file = args[++i];

                        Console.WriteLine("Loading {0}...", file);

                        m_entrypoint = Microsoft.SPOT.Debugger.SRecordFile.Parse(file, m_blocks, null);

                        Console.WriteLine("Loaded.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("{0}", e.ToString());
                        return(false);
                    }

                    continue;
                }

                if (arg == "-entrypoint")
                {
                    m_entrypoint = ParseHex(args[++i]);

                    continue;
                }

                Usage();
                return(false);
            }

            if (port == null || baudrate == 0)
            {
                Console.WriteLine("No serial port specified!");
                return(false);
            }

            m_eng = new _DBG.Engine(new Microsoft.SPOT.Debugger.PortDefinition_Serial(port, port, baudrate));

            m_eng.Silent = true;

            m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);

            m_eng.Start();

            if (fWait)
            {
                if (m_eng.TryToConnect(5, 100))
                {
                    m_eng.RebootDevice();
                }
            }

            m_fl = new _DBG.PortBooter(m_eng);

            m_fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler(this.OnProgress);

            m_fl.Start();

            if (fWait)
            {
                m_fl.WaitBanner(Int32.MaxValue, 2000);
            }

            DateTime start = DateTime.Now;

            m_fl.Program(m_blocks);

            Console.WriteLine("Execute: {0}", DateTime.Now - start);

            if (m_entrypoint != 0)
            {
                while (true)
                {
                    m_fl.Execute(m_entrypoint);

                    _DBG.PortBooter.Report r = m_fl.GetReport(2000);

                    if (r != null && r.type == _DBG.PortBooter.Report.State.EntryPoint)
                    {
                        break;
                    }
                }
            }

            m_fl.Stop();

            m_eng.Stop();

            return(true);
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null)
                {
                    return;
                }

                _DBG.Engine engine = device.DbgEngine;

                ReadOnlyCollection <string> files = form.Files;

                if (files.Count == 0)
                {
                    return;
                }

                uint address = uint.MaxValue;

                _DBG.PortBooter fl = new _DBG.PortBooter(engine);
                fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                fl.Start();

                try
                {
                    foreach (string file in files)
                    {
                        if (!File.Exists(file))
                        {
                            form.DumpToOutput(string.Format("Error: File doesn't exist {0}", file));
                            continue;
                        }

                        ArrayList blocks = new ArrayList();

                        uint tmp = _DBG.SRecordFile.Parse(file, blocks, null);

                        m_form = form;

                        fl.Program(blocks);

                        if (address == uint.MaxValue)
                        {
                            if (tmp != 0)
                            {
                                address = tmp;
                            }
                        }
                    }

                    if (address == uint.MaxValue)
                    {
                        address = 0;
                    }

                    m_form.DumpToOutput(string.Format("Executing address 0x{0:x08}", address));
                    fl.Execute(address);
                    System.Threading.Thread.Sleep(200);
                }
                finally
                {
                    if (fl != null)
                    {
                        fl.OnProgress -= new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                        fl.Stop();
                        fl.Dispose();
                    }
                }
            }
Example #5
0
        bool Process( string[] args )
        {
            string port     = null;
            uint   baudrate = 0;
            bool   fWait    = true;
            int    i;

            if(args.Length == 0)
            {
                Usage();
                return false;
            }

            for(i=0; i<args.Length; i++)
            {
                string arg = args[i].ToLower();

                if(arg == "-port"    ) { port     =               args[++i]  ; continue; }
                if(arg == "-baudrate") { baudrate = UInt32.Parse( args[++i] ); continue; }
                if(arg == "-nowait"  ) { fWait    = false                    ; continue; }

                if(arg == "-com1") { port = "COM1"; baudrate = 115200; continue; }
                if(arg == "-com2") { port = "COM2"; baudrate = 115200; continue; }

                if(arg == "-write")
                {
                    try
                    {
                        string file = args[++i];

                        Console.WriteLine( "Loading {0}...", file );

                        Microsoft.SPOT.Debugger.SRecordFile.Parse( file, m_blocks, null );

                        Console.WriteLine( "Loaded." );
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine( "{0}", e.ToString() );
                        return false;
                    }

                    continue;
                }

                if(arg == "-writeandexecute")
                {
                    try
                    {
                        string file = args[++i];

                        Console.WriteLine( "Loading {0}...", file );

                        m_entrypoint = Microsoft.SPOT.Debugger.SRecordFile.Parse( file, m_blocks, null );

                        Console.WriteLine( "Loaded." );
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine( "{0}", e.ToString() );
                        return false;
                    }

                    continue;
                }

                if(arg == "-entrypoint")
                {
                    m_entrypoint = ParseHex( args[++i] );

                    continue;
                }

                Usage();
                return false;
            }

            if(port == null || baudrate == 0)
            {
                Console.WriteLine( "No serial port specified!" );
                return false;
            }

            m_eng = new _DBG.Engine( new Microsoft.SPOT.Debugger.PortDefinition_Serial( port, port, baudrate ) );

            m_eng.Silent = true;

            m_eng.OnMessage += new _DBG.MessageEventHandler( OnMessage );

            m_eng.Start();

            if(fWait)
            {
                if(m_eng.TryToConnect( 5, 100 ))
                {
                    m_eng.RebootDevice();
                }
            }

            m_fl = new _DBG.PortBooter( m_eng );

            m_fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler( this.OnProgress );

            m_fl.Start();

            if(fWait)
            {
                m_fl.WaitBanner( Int32.MaxValue, 2000 );
            }

            DateTime start = DateTime.Now;

            m_fl.Program( m_blocks );

            Console.WriteLine( "Execute: {0}", DateTime.Now - start );

            if(m_entrypoint != 0)
            {
                while(true)
                {
                    m_fl.Execute( m_entrypoint );

                    _DBG.PortBooter.Report r = m_fl.GetReport( 2000 );

                    if(r != null && r.type == _DBG.PortBooter.Report.State.EntryPoint)
                    {
                        break;
                    }
                }
            }

            m_fl.Stop();

            m_eng.Stop();

            return true;
        }