Example #1
0
        private void WaitForProcessExit()
        {
            try
            {
                if (string.Equals(m_transport.ToLower(), "emulator"))
                {
                    Process[] p = Process.GetProcessesByName("Microsoft.SPOT.Emulator.Sample.SampleEmulator");

                    if (p != null && p.Length > 0)
                    {
                        m_emulatorProcess = p[p.Length - 1];

                        m_emulatorProcess.WaitForExit();
                        m_deviceDone.Set();
                    }
                }
                else
                {
                    int retries = 90; // 15 minutes

                    while (true)
                    {
                        if (!m_deviceDone.WaitOne(10000))
                        {
                            if (m_engine.TryToConnect(10, 500, true, ConnectionSource.Unknown))
                            {
                                Commands.Monitor_Ping.Reply ping = m_engine.GetConnectionSource();

                                if (ping != null)
                                {
                                    if (0 != (ping.m_dbg_flags & Commands.Monitor_Ping.c_Ping_DbgFlag_AppExit))
                                    {
                                        m_deviceDone.Set();
                                        break;
                                    }
                                }
                            }
                            else if (retries-- <= 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Example #2
0
        /// <summary>
        /// Attempt to establish a connection with TinyBooter (with reboot if necessary)
        /// </summary>
        /// <returns>true connection was made, false otherwise</returns>
        public bool ConnectToTinyBooter()
        {
            bool ret = false;

            if (m_eng == null)
            {
                _DBG.PortDefinition pd = m_portTinyBooter;

                try
                {
                    if (m_eng == null)
                    {
                        m_eng = new _DBG.Engine(pd);

                        m_eng.OnNoise   += new _DBG.NoiseEventHandler(OnNoiseHandler);
                        m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);

                        m_eng.Start();
                        m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown);
                    }
                }
                catch
                {
                }
            }


            if (m_eng != null)
            {
                if (m_eng.ConnectionSource == _DBG.ConnectionSource.TinyBooter)
                {
                    return(true);
                }

                m_eng.RebootDevice(_DBG.Engine.RebootOption.EnterBootloader);

                // tinyBooter is only com port so
                if (m_port is _DBG.PortDefinition_Tcp)
                {
                    Disconnect();

                    m_port = m_portTinyBooter;

                    // digi takes forever to reset
                    if (!Connect(60000, true))
                    {
                        Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooterSerial);
                        return(false);
                    }
                }
                bool fConnected = false;
                for (int i = 0; i < 40; i++)
                {
                    if (EventCancel.WaitOne(0, false))
                    {
                        throw new MFUserExitException();
                    }

                    if (fConnected = m_eng.TryToConnect(0, 500, true, _DBG.ConnectionSource.Unknown))
                    {
                        _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource();
                        ret = (reply.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter);

                        break;
                    }
                }
                if (!fConnected)
                {
                    Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooter);
                }
            }
            return(ret);
        }
        private void buttonEraseDeployment_Click(object sender, EventArgs e)
        {
            bool   bWasStarted = EnsureDebuggerConnection();
            Cursor old         = Cursor.Current;

            Cursor = Cursors.WaitCursor;
            buttonEraseDeployment.Text = "Erasing...";
            buttonEraseDeployment.Update();
            NewText("Erasing Deployment Sector...\r\n");

            try
            {
                _DBG.WireProtocol.Commands.Monitor_Ping.Reply ping = m_eng.GetConnectionSource();
                if (ping == null)
                {
                    NewText("Unable to connect to device\r\n");
                    return;
                }

                bool fClrConnection = ping.m_source == _DBG.WireProtocol.Commands.Monitor_Ping.c_Ping_Source_TinyCLR;

                if (fClrConnection)
                {
                    m_eng.PauseExecution();
                }

                _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply status = m_eng.GetFlashSectorMap() as _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply;

                if (status == null)
                {
                    NewText("Erase Deployment may Not be supported on this device build\r\n");
                }
                else
                {
                    const uint c_deployFlag = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT;
                    const uint c_usageMask  = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK;

                    foreach (_DBG.WireProtocol.Commands.Monitor_FlashSectorMap.FlashSectorData sector in status.m_map)
                    {
                        if (c_deployFlag == (c_usageMask & sector.m_flags))
                        {
                            NewText(string.Format("Erasing sector at 0x{0:x08}\r\n", sector.m_address));
                            m_eng.EraseMemory(sector.m_address, sector.m_size);
                        }
                    }

                    if (fClrConnection)
                    {
                        m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly);
                    }
                    NewText("Erase Deployment Successfull");
                }
            }
            catch (Exception ex)
            {
                NewText("Exception: " + ex.Message + "\r\n");
            }
            finally
            {
                buttonEraseDeployment.Text = "Erase Deployment";

                Cursor = old;
                if (!bWasStarted)
                {
                    m_eng.Stop();
                    m_eng = null;
                }
            }
        }