private void frmMain_Load(object sender, EventArgs e) { string COM = Ini.Read("COM"); List <string> list = new List <string>(); string[] SPNames = SerialPort.GetPortNames(); for (int i = 0; i < SPNames.Length; i++) { list.Add(SPNames[i]); } ToolStripMenuItem myItem = new ToolStripMenuItem(); myItem.Text = "选择串口"; while (设置串口ToolStripMenuItem.DropDownItems.Count > 0) { 设置串口ToolStripMenuItem.DropDownItems.RemoveAt(0); } foreach (string item in list) { ToolStripMenuItem mi = new ToolStripMenuItem(item); mi.Text = item; if (item == COM) { mi.Image = Properties.Resources.Image1; } mi.Click += new EventHandler(CustomItem_Click); 设置串口ToolStripMenuItem.DropDownItems.Add(mi); } }
private string Read_UpDataInfor() { try { string name = Ini.Read("附件路径"); comboBox1.Text = name; return(name); } catch { } return("NULL"); }
private string Read_UpDataInfor() { try { string name = Ini.Read("附件路径"); textBox16.Text = name; FileInfo FI = new FileInfo(name); textBox19.Text = FI.Length.ToString(); return(name); } catch { } return("NULL"); }
public static void ResetCom() { try { Value.serialPort1.Close(); } catch { } try { Value.serialPort1.BaudRate = 115200; Value.serialPort1.PortName = Ini.Read("COM"); Value.serialPort1.Open(); } catch (Exception E) { MessageBox.Show(E.Message); } }
private void button41_Click(object sender, EventArgs e) { try { while (comboBox1.Items.Count > 0) { comboBox1.Items.RemoveAt(0); } string[] files = System.IO.Directory.GetFiles(Application.StartupPath + "\\File", "*.bin"); for (int i = 0; i < files.Length; i++) { comboBox1.Items.Add(Path.GetFileName(files[i])); } } catch { } comboBox1.Text = Ini.Read("附件路径"); }
private void 设置_Load(object sender, EventArgs e) { string[] SPNames = SerialPort.GetPortNames(); comboBox1.Items.Clear(); for (int i = 0; i < SPNames.Length; i++) { comboBox1.Items.Add(SPNames[i]); } try { comboBox1.Text = Ini.Read("COM"); if (comboBox1.Text.Length < 3) { comboBox1.Text = comboBox1.Items[0].ToString(); } } catch {} }
private void 更多ToolStripMenuItem_Click(object sender, EventArgs e) { this.Hide(); try { Value.serialPort1.Close(); }catch { } Sensor form = new Sensor(); form.ShowDialog(); this.Show(); try { Value.serialPort1.PortName = Ini.Read("COM"); Value.serialPort1.Open(); } catch { } }
private void Supper_Face_Load(object sender, EventArgs e) { Value.App_Run = true; Value.serialPort1 = new SerialPort(); SetUpDataGridView(); try { Value.serialPort1.PortName = Ini.Read("COM"); } catch { (new SetPort()).ShowDialog(); } Tools.ResetCom(); (new Thread(MySql.LoginThread)).Start(); (new Thread(UpLoad)).Start(); try { this.Width = int.Parse(Ini.Read("窗口宽度")); this.Height = int.Parse(Ini.Read("窗口高度")); } catch { } }
private void ResetCom() { try { Value.serialPort1.Close(); } catch { } try { Value.serialPort1 = new System.IO.Ports.SerialPort(); Value.serialPort1.PortName = Ini.Read("COM"); Value.serialPort1.BaudRate = 115200; Value.serialPort1.Open(); } catch { (new SetPort()).ShowDialog(); if (FailCount++ > 2) { return; } ResetCom(); } }
private void Sensor_Load(object sender, EventArgs e)//加载窗口 { int i; Value.App_Run = true; tabControl1.TabPages.RemoveAt(2); if (int.TryParse(Ini.Read("StartTabIndex"), out i)) { tabControl1.SelectedIndex = i; } tabControl1.SelectedTab.BackColor = groupBox2.BackColor; OpenFileDialog Dlg = new OpenFileDialog(); ResetCom(); DrawHumi = new DrawWatch(); DrawTemp = new DrawWatch(); DrawVol = new DrawWatch(); DrawUserate_CPU = new DrawWatch(); DrawHumi.Init(); DrawTemp.Init(); DrawVol.Init(); DrawUserate_CPU.Init(); ServiceThread = new Thread(new ThreadStart(GetAngle)); }
private void 烧写() { int PageSize; uint LostCount = 0; UInt32 Error = 0; FileInfo fi; uint len; byte[] buffer; try { fi = new FileInfo(Application.StartupPath + "\\File\\" + Ini.Read("附件路径")); len = (uint)fi.Length; FileStream fs = fi.OpenRead(); buffer = new byte[len]; fs.Read(buffer, 0, (int)len); fs.Close(); } catch (Exception E) { MessageBox.Show(E.Message); return; } PageSize = (int)len / 1024; Ai: Count = 0; while (Value.App_Run) { button4_Click(null, null); for (int z = 0; z < 5; z++) { Thread.Sleep(10); if (Count > 0) { goto Ci; } } } Ci: Count = 0; Erase((uint)fi.Length); Thread.Sleep(2000); for (int z = 0; z < 5300; z++) { Thread.Sleep(1); if (Count > 0) { goto Bi; } } goto Ai; Bi: Thread.Sleep(1000); Count = 0; int i = 0; while (Value.App_Run) { if (i == Count) { Error = 0; if (len >= 1024) { Write1024(buffer, i, 1024); len -= 1024; LostCount = 1024; goto B; } if (len < 1024) { if (len > 0) { Write1024(buffer, i, (int)len); len = 0; LostCount = len; goto B; } } if (len == 0) { break; } B: i++; } else { Error++; } if (Error == 100) { i--; len += LostCount; } BeginInvoke(new MethodInvoker(delegate() { progressBar1.Maximum = PageSize + 1; progressBar1.Value = i; })); Thread.Sleep(10); } BeginInvoke(new MethodInvoker(delegate() { richTextBox1.SelectionColor = Color.Blue; richTextBox1.AppendText("烧写完成!\r\n"); button1.Text = "烧写"; })); button3_Click(null, null); Thread.Sleep(100); button3_Click(null, null); BeginInvoke(new MethodInvoker(delegate() { richTextBox1.SelectionColor = Color.Blue; richTextBox1.AppendText("程序开始执行!\r\n"); button1.Text = "烧写"; Value.queue.Enqueue(DateTime.Now.ToString() + "固件下载LOG:" + richTextBox1.Text); comboBox1.Enabled = true; })); }