private void btnBurn_Click(object sender, EventArgs e) { if (ProjectBuilder.CheckForWinAVR()) { owner.BurnerPanel.FormToProj(); System.Diagnostics.Process p = new System.Diagnostics.Process(); ProjectBuilder.SetEnviroVarsForProc(p.StartInfo); p.StartInfo.FileName = "cmd"; p.StartInfo.Arguments = "/k avrdude "; string overrides = ""; BurnerPanel.GetPortOverride(ref overrides, owner.Project); p.StartInfo.Arguments += String.Format("-c {0} -p {1} {2} {3} {4}", owner.Project.BurnProgrammer, owner.Project.BurnPart, overrides, owner.Project.BurnOptions, GetArgString(fuseVal)); try { p.Start(); } catch (Exception ex) { ErrorReportWindow.Show(ex, "Error While Writing Fuse"); } } }
public AvrDudeWindow(AVRProject project) { InitializeComponent(); // two projects allow changes to be discarded this.originalProject = project; this.project = project.Clone(); burnerPanel = new BurnerPanel(this.project); grpboxBurnerPanel.Controls.Add(burnerPanel); burnerPanel.Dock = DockStyle.Fill; burnerPanel.ProjToForm(); dropDetectionType.SelectedIndex = 0; dropMemoryType.SelectedIndex = 0; // this is the only way i can think of that will // allow the user to view the progress bar live // by using the command line window // because redirecting STDERR doesn't work since // the .NET built-in stream redirection only has // the ability to read line by line so the progress // bar is lost ProjectBuilder.SetEnviroVarsForProc(avrdude.StartInfo); avrdude.StartInfo.FileName = "cmd"; }
private void btnWrite_Click(object sender, EventArgs e) { TryKill(); OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } ProjectBuilder.SetEnviroVarsForProc(avrdude.StartInfo); avrdude.StartInfo.Arguments = GetArgs(GetMemType(), GetOverrides(), "w", ofd.FileName, GetFileFormat(), true); TryRun(); }
private void btnRead_Click(object sender, EventArgs e) { TryKill(); SaveFileDialog sfd = new SaveFileDialog(); if (sfd.ShowDialog() != DialogResult.OK) { return; } burnerPanel.FormToProj(); ProjectBuilder.SetEnviroVarsForProc(avrdude.StartInfo); avrdude.StartInfo.Arguments = GetArgs(GetMemType(), GetOverrides(), "r", sfd.FileName, GetFileFormat(), true); TryRun(); }
private void btnInteractive_Click(object sender, EventArgs e) { burnerPanel.FormToProj(); if (ProjectBuilder.CheckForWinAVR()) { System.Diagnostics.Process p = new System.Diagnostics.Process(); ProjectBuilder.SetEnviroVarsForProc(p.StartInfo); p.StartInfo.FileName = "cmd"; p.StartInfo.Arguments = "/k avrdude "; string overrides = ""; BurnerPanel.GetPortOverride(ref overrides, project); p.StartInfo.Arguments += String.Format("-c {0} -p {1} {2} {3} -t", project.BurnProgrammer, project.BurnPart, overrides, project.BurnOptions); p.Start(); } }
private int ReadFuse() { if (ProjectBuilder.CheckForWinAVR()) { owner.BurnerPanel.FormToProj(); System.Diagnostics.Process p = new System.Diagnostics.Process(); ProjectBuilder.SetEnviroVarsForProc(p.StartInfo); p.StartInfo.FileName = "avrdude"; p.StartInfo.Arguments = ""; //p.StartInfo.FileName = "cmd"; //p.StartInfo.Arguments = "/k avrdude"; string overrides = ""; BurnerPanel.GetPortOverride(ref overrides, owner.Project); string avrdudeFuseStr = GetAVRDUDEFuseStringFromType(typeOfFuse); string action = String.Format("-U {0}:r:\"{1}\":h", avrdudeFuseStr, TempFuseFilePath); p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.WorkingDirectory = SettingsManagement.AppDataPath; p.StartInfo.Arguments += String.Format(" -c {0} -p {1} -n {2} {3} {4}", owner.Project.BurnProgrammer, owner.Project.BurnPart, overrides, owner.Project.BurnOptions, action); try { File.Delete(TempFuseFilePath); } catch { } try { p.Start(); p.WaitForExit(5000); System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); while (true) { if (File.Exists(TempFuseFilePath)) { break; } if (sw.ElapsedMilliseconds > 5000) { break; } } if (File.Exists(TempFuseFilePath) == false) { MessageBox.Show("Failed to Read Fuse, temporary file not found at '" + TempFuseFilePath + "'. Here is the AVRDUDE output:" + Environment.NewLine + Environment.NewLine + p.StandardError.ReadToEnd() + Environment.NewLine + p.StandardOutput.ReadToEnd()); return(-1); } else { string fuseStr = File.ReadAllText(TempFuseFilePath); try { File.Delete(TempFuseFilePath); } catch { } if (string.IsNullOrEmpty(fuseStr)) { MessageBox.Show("Temporary Fuse File is Empty at " + TempFuseFilePath); return(-1); } fuseStr = fuseStr.Trim(); if (string.IsNullOrEmpty(fuseStr)) { MessageBox.Show("Temporary Fuse File is Empty at " + TempFuseFilePath); return(-1); } return(Convert.ToInt32(fuseStr, 16)); } } catch (Exception ex) { ErrorReportWindow.Show(ex, "Error While Reading Fuse"); } } return(-1); }
private bool CheckForAVARICE() { try { Process proc = new Process(); ProjectBuilder.SetEnviroVarsForProc(proc.StartInfo); proc.StartInfo.FileName = "avarice"; proc.StartInfo.Arguments = "--known-devices"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.CreateNoWindow = true; if (proc.Start() == false) { TextBoxModify(this.txtOutput, "WinAVR's AVARICE could not be found", TextBoxChangeMode.SetNewLine); return(false); } else { if (chipList == null) { chipList = new List <string>(); } chipList.Clear(); string listStr = proc.StandardOutput.ReadToEnd(); if (listStr == null) { listStr = ""; } listStr += "\r\n"; string t = proc.StandardError.ReadToEnd(); if (t == null) { t = ""; } listStr += t; string[] lines = listStr.Split('\n'); bool listRdy = false; foreach (string line_ in lines) { string line = line_.Trim(); if (line.Contains("----") && listRdy == false) { listRdy = true; } else if (listRdy) { string[] parts = line.Split(new char[] { ' ', '\t', '\r', '\n', '\0', }); if (parts.Length >= 1) { if (string.IsNullOrEmpty(parts[0].Trim()) == false) { if (chipList.Contains(parts[0].Trim()) == false) { chipList.Add(parts[0].Trim()); } } } } } chipList.Sort((x, y) => string.Compare(x, y)); foreach (string c in chipList) { this.dropAVRChips.Items.Add(c); } try { proc.Kill(); } catch { } return(true); } } catch { TextBoxModify(this.txtOutput, "WinAVR's AVARICE could not be found", TextBoxChangeMode.SetNewLine); return(false); } }
public void Run(ProjectFile file, AVRProject proj) { try { string cmd = this.cmdStr; if (string.IsNullOrEmpty(cmd)) { return; } Process p = new Process(); p.StartInfo.FileName = cmd; if (proj != null) { if (proj.IsReady) { p.StartInfo.WorkingDirectory = proj.DirPath; } } string args = this.argsStr; if (string.IsNullOrEmpty(args) == false) { if (proj != null) { if (proj.IsReady) { args = args.Replace("%PROJNAME%", proj.FileNameNoExt); args = args.Replace("%PROJDIR%", proj.DirPath); args = args.Replace("%PROJOUTFOLDER%", proj.OutputDir); args = args.Replace("%PROJCHIP%", proj.Device); if (file != null) { args = args.Replace("%FILENAMENOEXT%", file.FileNameNoExt); args = args.Replace("%FILEEXT%", file.FileExt); args = args.Replace("%FILEDIR%", file.FileDir); } } } ProjectBuilder.SetEnviroVarsForProc(p.StartInfo); p.StartInfo.Arguments = args; } string dir = this.dirStr; if (string.IsNullOrEmpty(dir) == false) { if (proj != null) { if (proj.IsReady) { dir = dir.Replace("%PROJDIR%", proj.DirPath); dir = dir.Replace("%PROJOUTFOLDER%", proj.OutputDir); if (file != null) { dir = dir.Replace("%FILEDIR%", file.FileDir); } } } p.StartInfo.WorkingDirectory = dir; } if (p.Start()) { // } else { MessageBox.Show(String.Format("Process '{0} {1}' failed to start.", cmd, args)); } } catch (Exception ex) { MessageBox.Show("Error during execution: " + ex.Message); } }
private void btnLoad_Click(object sender, EventArgs e) { if (IDEWindow.CurrentProject == null) { scintilla1.Text = "Error: Project Not Loaded"; return; } if (IDEWindow.CurrentProject.IsReady == false) { scintilla1.Text = "Error: Project Not Loaded"; return; } if (txtOptions.Text.Trim().Length == 0) { txtOptions.Text = "-h -D -S"; } SettingsManagement.LastDisassemblyOptions = txtOptions.Text; string dirPath = IDEWindow.CurrentProject.DirPath + Path.DirectorySeparatorChar + IDEWindow.CurrentProject.OutputDir + Path.DirectorySeparatorChar; if (Program.MakeSurePathExists(dirPath) == false) { scintilla1.Text = "Error: Could not create output directory"; return; } string elfPath = dirPath + IDEWindow.CurrentProject.FileNameNoExt + ".elf"; if (File.Exists(elfPath) == false) { scintilla1.Text = "Error: ELF file not found at '" + elfPath + "'"; return; } string fileNameAddon = txtOptions.Text.Replace(" -", ".").Replace("-", ".").Replace(" ", "."); while (fileNameAddon.Contains("..")) { fileNameAddon = fileNameAddon.Replace("..", "."); } fileNameAddon = fileNameAddon.Trim('.'); string fileName = IDEWindow.CurrentProject.FileNameNoExt + ".disasm." + fileNameAddon + ".lst"; string filePath = dirPath + fileName; if (File.Exists(filePath)) { try { File.Delete(filePath); } catch (Exception ex) { scintilla1.Text = "Error: Could not delete existing file"; return; } } Process avrobjdump = new Process(); ProjectBuilder.SetEnviroVarsForProc(avrobjdump.StartInfo); avrobjdump.StartInfo.FileName = "cmd"; avrobjdump.StartInfo.Arguments = "/C avr-objdump " + txtOptions.Text.Trim() + " " + IDEWindow.CurrentProject.FileNameNoExt + ".elf > " + fileName; avrobjdump.StartInfo.WorkingDirectory = dirPath; avrobjdump.StartInfo.UseShellExecute = false; avrobjdump.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; avrobjdump.StartInfo.CreateNoWindow = true; try { avrobjdump.Start(); avrobjdump.WaitForExit(10000); } catch (Exception ex) { scintilla1.Text = "Error running avr-objdump: " + ex.Message; return; } if (File.Exists(filePath) == false) { scintilla1.Text = "Error: LST file was not generated at '" + filePath + "'"; return; } int oldCaret = scintilla1.CurrentPos; scintilla1.IsReadOnly = false; scintilla1.Text = File.ReadAllText(filePath); scintilla1.IsReadOnly = true; if (oldCaret >= 0 && oldCaret <= scintilla1.Text.Length) { scintilla1.GoTo.Position(oldCaret); } else if (oldCaret > scintilla1.Text.Length) { scintilla1.GoTo.Position(scintilla1.Text.Length); } }