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(); } } }
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; } }
private void StartOrStop( bool fStart ) { bool fButtonState; if(fStart) { if(m_eng != null) return; m_blocks = new ArrayList(); m_fWait = checkBoxWait.Checked; m_fDisconnect = checkBoxDisconnect.Checked; listViewFiles.SelectedIndices.Clear(); try { _DBG.PortDefinition pd = GetSelectedPortDefinition(); m_eng = new _DBG.Engine( pd ); m_eng.Silent = true; m_eng.OnNoise += new _DBG.NoiseEventHandler ( OnNoise ); m_eng.OnMessage += new _DBG.MessageEventHandler( OnMessage ); m_eng.Start(); if (m_eng.TryToConnect(5, 100)) { if (m_fWait) { // if w are talking to the booter, have it to stop and wait for upload // PortBooter will wait to secs no matter what m_eng.RebootDevice(radioButtonPortBooter.Checked ? _DBG.Engine.RebootOption.EnterBootloader : _DBG.Engine.RebootOption.NormalReboot); } } foreach(ListViewItem item in this.listViewFiles.CheckedItems) { m_blocks.Add( item.Tag ); } if(m_blocks.Count > 0) { if(radioButtonPortBooter.Checked) { m_fl = new _DBG.PortBooter( m_eng ); m_fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler( this.OnProgress ); m_fl.Start(); m_worker = new Thread( new ThreadStart( this.UploadWithPortBooter ) ); } else { m_worker = new Thread( new ThreadStart( this.UploadWithTinyBooter ) ); } m_worker.Start(); } buttonAction.Text = "Stop"; richTextBox1.Focus(); } catch(Exception ex) { MessageBox.Show( ex.Message ); return; } fButtonState = false; } else { if(m_eng == null) return; Stop(); buttonAction.Text = "Start"; fButtonState = true; } buttonReload .Enabled = fButtonState; buttonRemove .Enabled = fButtonState; buttonRemoveAll .Enabled = fButtonState; buttonBrowse .Enabled = fButtonState; comboBoxPort .Enabled = fButtonState; comboBoxBaud .Enabled = fButtonState; listViewFiles .Enabled = fButtonState; }
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; } }
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(); } } }
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; }
private void StartOrStop(bool fStart) { bool fButtonState; if (fStart) { if (m_eng != null) { return; } m_blocks = new ArrayList(); m_fWait = checkBoxWait.Checked; m_fDisconnect = checkBoxDisconnect.Checked; listViewFiles.SelectedIndices.Clear(); try { _DBG.PortDefinition pd = GetSelectedPortDefinition(); m_eng = new _DBG.Engine(pd); m_eng.Silent = true; m_eng.OnNoise += new _DBG.NoiseEventHandler(OnNoise); m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage); m_eng.Start(); if (m_eng.TryToConnect(5, 100)) { if (m_fWait) { // if w are talking to the booter, have it to stop and wait for upload // PortBooter will wait to secs no matter what m_eng.RebootDevice(radioButtonPortBooter.Checked ? _DBG.Engine.RebootOption.EnterBootloader : _DBG.Engine.RebootOption.NormalReboot); } } foreach (ListViewItem item in this.listViewFiles.CheckedItems) { m_blocks.Add(item.Tag); } if (m_blocks.Count > 0) { if (radioButtonPortBooter.Checked) { m_fl = new _DBG.PortBooter(m_eng); m_fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler(this.OnProgress); m_fl.Start(); m_worker = new Thread(new ThreadStart(this.UploadWithPortBooter)); } else { m_worker = new Thread(new ThreadStart(this.UploadWithTinyBooter)); } m_worker.Start(); } buttonAction.Text = "Stop"; richTextBox1.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } fButtonState = false; } else { if (m_eng == null) { return; } Stop(); buttonAction.Text = "Start"; fButtonState = true; } buttonReload.Enabled = fButtonState; buttonRemove.Enabled = fButtonState; buttonRemoveAll.Enabled = fButtonState; buttonBrowse.Enabled = fButtonState; comboBoxPort.Enabled = fButtonState; comboBoxBaud.Enabled = fButtonState; listViewFiles.Enabled = fButtonState; }