private void clear_sample() { timerDraw.Stop(); timerDrawI = 0; x1.Clear(); y1.Clear(); LGraphTest.f_ClearAllPix(); lbl_status.Text = "SAMPLING DATA CLEARED."; }
private void Btn_start_sample_Click(object sender, EventArgs e) // Button1_Click { btn_start_sample.Enabled = false; Thread.Sleep(100); if (checkBox_manul.Checked) { sendCount = 1; ToggleControls(true); btn_start_sample.Enabled = false; btn_stop_sample.Enabled = true; lbl_test_time.Visible = true; this.Focus(); x1.Clear(); y1.Clear(); // x2.Clear(); // y2.Clear(); // x3.Clear(); // y3.Clear(); // x4.Clear(); // y4.Clear(); LGraphTest.f_ClearAllPix(); LGraphTest.f_reXY(); if (checkBox_scatter.Checked) { LGraphTest.f_LoadOnePix(ref x1, ref y1, Color.Red, 2, LineJoin.Round, LineCap.NoAnchor, LILEI.UI.LGraph.DrawStyle.dot); } // scatter else { LGraphTest.f_LoadOnePix(ref x1, ref y1, Color.Red, 2); } //curve // LGraphTest.f_AddPix(ref x2, ref y2, Color.Blue, 3); // LGraphTest.f_AddPix(ref x3, ref y3, Color.FromArgb(0, 128, 192), 2); // LGraphTest.f_AddPix(ref x4, ref y4, Color.Yellow, 3); f_timerDrawStart(); //start sample timer lbl_status.Text = "SAMPLING[Period " + tb_sample_frequency.Text + "s]"; //test timer label //开始计时 test_timer.Start(); TimeCount = 0; } else //采样周期 { //ToggleControls(true); lbl_test_time.Visible = false; //list add serial data this.Focus(); tb_sample_frequency.Text = ""; // tb_sample_frequency.Enabled = false; // x1.Clear(); // y1.Clear(); // LGraphTest.f_ClearAllPix(); LGraphTest.f_reXY(); if (checkBox_scatter.Checked) { LGraphTest.f_LoadOnePix(ref x1, ref y1, Color.Red, 2, LineJoin.Round, LineCap.NoAnchor, LILEI.UI.LGraph.DrawStyle.dot); } // scatter else { LGraphTest.f_LoadOnePix(ref x1, ref y1, Color.Red, 2); } foh100_state(); Thread.Sleep(500); foh100_onu(); btn_start_sample.Enabled = true; } btn_clear_graph.Enabled = true; }
// Random rand = new Random(); public void GetData_foh100_state() { String msg = ""; Thread.Sleep(100); int i = 0; msg = usb.ReadData(); if (msg.Contains("sys_power_flg")) // || msg.Contains( "onu_info.rx_lenth") { Action <int> action = (data) => { int start0 = msg.IndexOf("mcu_temperate"); int length0 = " = 36.71".Length; String tmpValue0 = msg.Substring(start0 + 15, length0 - 1).Trim(); int start1 = msg.IndexOf("battary_volatge "); int length1 = " = 4.30".Length; String tmpValue1 = msg.Substring(start1 + 17, length1).Trim(); int start2 = msg.IndexOf("fan_speed_test"); int length2 = " = 0 ".Length; String tmpValue2 = msg.Substring(start2 + 16, length2 - 2).Trim(); // ReceivedTextBox.Text += msg + "\r\n"; //温度计显示 userControl1_temperature.CurValue = float.Parse(tmpValue0); userControl1_temperature.Refresh(); //最大温度值: if (float.Parse(tb_temperature_max.Text) < float.Parse(tmpValue0)) { tb_temperature_max.Text = tmpValue0; } String responseoutput = String.Empty; responseoutput = msg; //save info log StreamWriter file = new StreamWriter("fohlog.txt", true); file.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + " " + responseoutput); file.Close(); //graph list //string amount = string.Empty; //if (!string.IsNullOrEmpty(tmpValue0) && (Regex.IsMatch(tmpValue0, @"^[1-9]\d*|0$"))) // || Regex.IsMatch(tmpValue0, @"^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$") //{ // amount = Convert.ToDecimal(tmpValue0).ToString(); //} //else //{ // amount = "0.00"; //} //string amount = string.Empty; //amount = tmpValue0.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", ""); y1.Add(float.Parse(tmpValue0)); //让文本框获取焦点 this.ReceivedTextBox.Focus(); //设置光标的位置到文本尾 this.ReceivedTextBox.Select(this.ReceivedTextBox.TextLength, 0); //滚动到控件光标处 this.ReceivedTextBox.ScrollToCaret(); ReceivedTextBox.Text += "temperature: " + float.Parse(tmpValue0) + "\r\n" + "battary_volatge: " + tmpValue1 + "\r\n" + "fan_speed: " + tmpValue2 + "\r\n"; x1.Add(timerDrawI); // y1.Add(float.Parse(tb_mcu_temperate.Text)); timerDrawI++; LGraphTest.f_Refresh(); lbl_send_count.Text = "采样计数: " + sendCount++.ToString(); }; Invoke(action, i); i++; // } Thread.Sleep(200); // } } }