private void addProgrammer(int i, int id) { progs[i] = new USBTinyISP(id, path_to_avrdude); prog_labels[i] = new Label(); Point loc = new Point(5, this.Height - 35); prog_labels[i].Location = loc; prog_labels[i].AutoSize = true; prog_labels[i].ForeColor = SystemColors.ControlText; prog_labels[i].Text = String.Format("P{0}:", i); prog_labels[i].Parent = this; prog_textBoxes[i] = new RichTextBox(); loc = new Point(prog_labels[i].Width + 5, this.Height - 55); prog_textBoxes[i].Location = loc; prog_textBoxes[i].Width = 195; prog_textBoxes[i].Height = 20; prog_textBoxes[i].ForeColor = SystemColors.ControlText; prog_textBoxes[i].Parent = this; prog_menuitems[i] = new ToolStripMenuItem(); prog_menuitems[i].Text = "USBTinyISP_0" + i; prog_menuitems[i].Checked = true; prog_menuitems[i].Click += new EventHandler(delegate(Object o, EventArgs a) { prog_menuitems[i].Checked = !prog_menuitems[i].Checked; progs[i].active = prog_menuitems[i].Checked; if (!prog_menuitems[i].Checked) { prog_textBoxes[i].ForeColor = Color.White; prog_textBoxes[i].BackColor = Color.LightGray; prog_textBoxes[i].Text = "Inactive"; } }); deviceToolStripMenuItem.DropDownItems.Add(prog_menuitems[i]); }
public void connectProgs() { int tempId = 0; USBTinyISP tempProg = new USBTinyISP(tempId, path_to_avrdude); String root = System.IO.Directory.GetCurrentDirectory(); String target = root + "\\batches\\check.bat"; String args = String.Format("{0}", tempId); tempProg.performBat(target, args); string path = root + String.Format("\\batches\\check_results\\check_results_p{0}.txt", args); if (File.Exists(path)) { var task = Task.Run(() => tempProg.WaitForFile(path)); if (task.Wait(TimeSpan.FromSeconds(2))) { if (task.Result) { string text = System.IO.File.ReadAllText(path); num_of_progs = Regex.Matches(text, "Found USBtinyISP").Count; if (num_of_progs == 0) { num_of_progs = 0; button1.Text = "Refresh"; toolStripMenuItem2.Enabled = false; } else { progs = new USBTinyISP[num_of_progs]; prog_labels = new Label[num_of_progs]; prog_textBoxes = new RichTextBox[num_of_progs]; prog_menuitems = new ToolStripMenuItem[num_of_progs]; for (int i = 0; i < num_of_progs; i++) { button1.Text = "Program"; toolStripMenuItem2.Enabled = true; int index = text.IndexOf("Found USBtinyISP"); //Console.WriteLine("Index is {0}", index); int id = 0; if (index < 0) { id = i; } else { text = text.Substring(index + 48); //Console.WriteLine("Parsed text is \n {0}", text); id = Int32.Parse(text.Substring(0, 4)); } //Console.WriteLine("id is {0}", id); addProgrammer(i, id); if (progs[i].active) { if (progs[i].connected()) { prog_textBoxes[i].Invoke((MethodInvoker)(() => { prog_textBoxes[i].ForeColor = Color.White; prog_textBoxes[i].BackColor = Color.DarkCyan; prog_textBoxes[i].Text = progs[i].message; })); } else { prog_textBoxes[i].Invoke((MethodInvoker)(() => { prog_textBoxes[i].ForeColor = Color.White; prog_textBoxes[i].BackColor = Color.Firebrick; prog_textBoxes[i].Text = progs[i].message; })); } } } } } else { message("File Error: Could not gain access."); } } else { message("File Error: Timed out."); num_of_progs = 0; } task.Dispose(); } else { //Console.WriteLine(String.Format("File Error: {0} not nound.", path)); } }