/* Make sure that Disconnect gets called, otherwise EndOfStreamException will never get thrown and it will block forever. */ private void WorkerThread() { while (true) { try { Packets.ProfilerPacket pp = ProfilerPacketFactory.Decode(m_incomingStream); pp.Process(this); // Don't write out incomplete lines if we lose the device during processing? Insert 'safe' values instead? } catch (System.IO.IOException) { /* The CLR is allowed to resume/quit now; we have all data we need. */ try { m_engine.ResumeExecution(); } catch { } /*We've been disconnected -- shutdown thread. */ if (OnDisconnect != null) { OnDisconnect(this, EventArgs.Empty); } return; } } }
private void bwConnecter_RunWorkerCompleted(System.Object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { Exception ex = (Exception)e.Error; LogText(string.Format("Error connecting to device:\r\n{0}", ex.Message)); Disconnect(); } else if (e.Cancelled) { LogText("Connection canceled."); Disconnect(); return; } else { bool result = false; if (e.Result != null) { result = (bool)e.Result; } if (result) { m_session.SetProfilingOptions(checkCalls.Checked, checkAllocations.Checked); m_engine.ResumeExecution(); LogText("Successfully connected to TinyCLR."); LogText("Using file: " + m_exporter.FileName); ConnectComplete(); } else { LogText("Device is unresponsive or cannot be found."); Disconnect(); } } }
private void Disconnect() { if (m_ah != null) { m_ah.Stop(); m_ah.Dispose(); m_ah = null; } if (m_eng != null) { if (m_deviceRunning) { m_eng.ResumeExecution(); } m_eng.Stop(); m_eng = null; } m_deviceRunning = false; }
/// <summary> /// Erases the deployment sectors of the connected .Net Micro Framework device /// </summary> /// <param name="options">Identifies which areas are to be erased, if no options are given, all /// user sectors will be erased. /// </param> /// <returns>Returns false if the erase fails, true otherwise /// Possible exceptions: MFUserExitException, MFDeviceNoResponseException /// </returns> public bool Erase(params EraseOptions[] options) { bool ret = false; bool fReset = false; if (m_eng == null) { throw new MFDeviceNoResponseException(); } EraseOptions optionFlags = 0; if (options == null || options.Length == 0) { optionFlags = (EraseOptions.Deployment | EraseOptions.FileSystem | EraseOptions.UserStorage); } else { foreach (EraseOptions opt in options) { optionFlags |= opt; } } if (!m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown)) { throw new MFDeviceNoResponseException(); } if (!IsClrDebuggerEnabled()) { fReset = (Ping() == PingConnectionType.TinyCLR); ConnectToTinyBooter(); } _WP.Commands.Monitor_FlashSectorMap.Reply reply = m_eng.GetFlashSectorMap(); if (reply == null) { throw new MFDeviceNoResponseException(); } _WP.Commands.Monitor_Ping.Reply ping = m_eng.GetConnectionSource(); ret = true; long total = 0; long value = 0; bool isConnectedToCLR = ((ping != null) && (ping.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyCLR)); if (isConnectedToCLR) { m_eng.PauseExecution(); } List <_WP.Commands.Monitor_FlashSectorMap.FlashSectorData> eraseSectors = new List <_WP.Commands.Monitor_FlashSectorMap.FlashSectorData>(); foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData fsd in reply.m_map) { if (EventCancel.WaitOne(0, false)) { throw new MFUserExitException(); } switch (fsd.m_flags & _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) { case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT: if (EraseOptions.Deployment == (optionFlags & EraseOptions.Deployment)) { eraseSectors.Add(fsd); total++; } break; case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_A: case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_B: if (EraseOptions.UserStorage == (optionFlags & EraseOptions.UserStorage)) { eraseSectors.Add(fsd); total++; } break; case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_FS: if (EraseOptions.FileSystem == (optionFlags & EraseOptions.FileSystem)) { eraseSectors.Add(fsd); total++; } break; } } foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData fsd in eraseSectors) { ret &= m_eng.EraseMemory(fsd.m_address, fsd.m_size); value++; if (OnProgress != null) { OnProgress(value, total, string.Format(Properties.Resources.StatusEraseSector, fsd.m_address)); } } // reset if we specifically entered tinybooter for the erase if (fReset) { m_eng.ExecuteMemory(0); } // reboot if we are talking to the clr if (isConnectedToCLR) { if (OnProgress != null) { OnProgress(0, 0, Properties.Resources.StatusRebooting); } m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly); m_eng.ResumeExecution(); } return(ret); }
internal void StartProfiler(string device, string logFile, string transport, string exePath, string buildPath, ArrayList referenceList, bool isDevEnvironment, string assemblyName ) { try { PortDefinition port = Utils.GetPort(device, transport, exePath); m_engine = new Engine(port); m_session = new ProfilerSession(m_engine); #if DEBUG m_exporter = new Exporter_OffProf(m_session, logFile); #endif lock (m_engine) { m_engine.StopDebuggerOnConnect = true; m_engine.Start(); bool connected = false; connected = m_engine.TryToConnect(20, 500, true, ConnectionSource.TinyCLR); if (connected) { if (m_engine.Capabilities.Profiling == false) { throw new ApplicationException("This device is not running a version of TinyCLR that supports profiling."); } // Deploy the test files to the device. Utils.DeployToDevice(buildPath, referenceList, m_engine, transport, isDevEnvironment, assemblyName); // Move IsDeviceInInitializeState(), IsDeviceInExitedState(), // GetDeviceState(),EnsureProcessIsInInitializedState() to Debugger.dll? m_engine.RebootDevice(Engine.RebootOption.RebootClrWaitForDebugger); if (!m_engine.TryToConnect(100, 500)) { throw new ApplicationException("Connection Failed"); } m_engine.ThrowOnCommunicationFailure = true; m_session.EnableProfiling(); m_session.SetProfilingOptions(true, false); m_engine.OnCommand += new CommandEventHandler(OnWPCommand); m_engine.ResumeExecution(); } else { throw new ApplicationException("Connection failed"); } } } catch (Exception ex) { SoftDisconnectDone(null, null); throw ex; } }
private void ConnectToDevice(string buildPath, string exePath, ArrayList referenceList) { TestSystem.IncludesDeviceTest = true; PortDefinition port = Utils.GetPort(m_device, m_transport, exePath); try { for (int retry = 0; retry < 3; retry++) { m_engine = new Microsoft.SPOT.Debugger.Engine(port); m_engine.StopDebuggerOnConnect = true; m_engine.Start(); bool connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); if (connected) { m_engine.PauseExecution(); if (!string.Equals(m_transport.ToLower(), "emulator")) { // Deploy the test files to the device. Utils.DeployToDevice(buildPath, referenceList, m_engine, m_transport, m_isDevEnvironment, m_assemblyName); // Connect to the device and execute the deployed test. m_engine.RebootDevice(Microsoft.SPOT.Debugger.Engine.RebootOption.RebootClrWaitForDebugger); // give the device some time to restart (especially for tcp/ip) Thread.Sleep(500); if (m_engine.PortDefinition is PortDefinition_Tcp) { Thread.Sleep(1000); } connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); } if (!connected) { DetachFromEngine(); throw new ApplicationException("Reboot Failed"); } AttachToProcess(); m_engine.ThrowOnCommunicationFailure = true; m_engine.OnMessage += new MessageEventHandler(OnMessage); m_engine.OnCommand += new CommandEventHandler(OnCommand); m_engine.OnNoise += new NoiseEventHandler(OnNoise); Console.WriteLine("\tExecuting the device test.."); m_initialTime = DateTime.Now; m_engine.ResumeExecution(); m_deviceDone.WaitOne(); break; } else { DetachFromEngine(); //throw new ApplicationException("Connection failed"); } } } catch (Exception ex) { DetachFromEngine(); throw new ApplicationException("Connection failed: " + ex.ToString()); } }
private void ConnectToDevice(string buildPath, string exePath, ArrayList referenceList) { TestSystem.IncludesDeviceTest = true; PortDefinition port = Utils.GetPort(m_device, m_transport, exePath); try { for (int retry = 0; retry < 3; retry++) { m_engine = new Microsoft.SPOT.Debugger.Engine(port); m_engine.StopDebuggerOnConnect = true; m_engine.Start(); bool connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); if (connected) { m_engine.PauseExecution(); if (!string.Equals(m_transport.ToLower(), "emulator")) { // Deploy the test files to the device. Utils.DeployToDevice(buildPath, referenceList, m_engine, m_transport, m_isDevEnvironment, m_assemblyName); // Connect to the device and execute the deployed test. m_engine.RebootDevice(Microsoft.SPOT.Debugger.Engine.RebootOption.RebootClrWaitForDebugger); // give the device some time to restart (especially for tcp/ip) Thread.Sleep(500); if (m_engine.PortDefinition is PortDefinition_Tcp) { Thread.Sleep(1000); } connected = false; connected = m_engine.TryToConnect(200, 500, true, ConnectionSource.TinyCLR); } if (!connected) { DetachFromEngine(); throw new ApplicationException("Reboot Failed"); } AttachToProcess(); m_engine.ThrowOnCommunicationFailure = true; m_engine.OnMessage += new MessageEventHandler(OnMessage); m_engine.OnCommand += new CommandEventHandler(OnCommand); m_engine.OnNoise += new NoiseEventHandler(OnNoise); Console.WriteLine("\tExecuting the device test.."); m_initialTime = DateTime.Now; m_engine.ResumeExecution(); m_deviceDone.WaitOne(); break; } else { DetachFromEngine(); //throw new ApplicationException("Connection failed"); } } } catch(Exception ex) { DetachFromEngine(); throw new ApplicationException("Connection failed: " + ex.ToString()); } }