private void timer2_Tick(object sender, EventArgs e) { Timeout_Count++; if (Timeout_Count == modbus.Modbus_Timeout) { if (buffer[modbus.Modbus_Id_Index] != 0) { TimeOut_Error_Times++; TimeOut_Count_TextBox.Text = TimeOut_Error_Times.ToString(); Error_TextBox.AppendText("Tx: "); Error_TextBox.AppendText(BitConverter.ToString(buffer).Replace("-", " ")); Error_TextBox.AppendText(Environment.NewLine); DataRow dr = file.dt.NewRow(); //建立新的Rows dr["TX"] = BitConverter.ToString(buffer).Replace("-", " "); dr["RESULT"] = "FALSE"; file.dt.Rows.Add(dr); } else { Correct_Times++; Correct_Count_TextBox.Text = Correct_Times.ToString(); DataRow dr = file.dt.NewRow(); //建立新的Rows dr["TX"] = BitConverter.ToString(buffer).Replace("-", " "); dr["RESULT"] = "TRUE"; file.dt.Rows.Add(dr); } file.SaveCsv(file.dt, file.GetFileName()); Is_Need_Receive = false; Clear_Timer2_Parameter(); //s.Stop();//開始計時 //TimeOut_Count_TextBox.Text = ((s.ElapsedMilliseconds).ToString() + "毫秒"); //s.Reset(); } }
private void Display_Error_Text(Byte[] Receive_Buffer) { Error_TextBox.AppendText("Tx: "); Error_TextBox.AppendText(BitConverter.ToString(buffer).Replace("-", " ")); Error_TextBox.AppendText(Environment.NewLine); Error_TextBox.AppendText("Rx: "); Error_TextBox.AppendText(BitConverter.ToString(Receive_Buffer).Replace("-", " ")); Error_TextBox.AppendText(Environment.NewLine); Error_TextBox.ForeColor = Color.Red; DataRow dr = file.dt.NewRow(); //建立新的Rows dr["TX"] = BitConverter.ToString(buffer).Replace("-", " "); dr["RX"] = BitConverter.ToString(Receive_Buffer).Replace("-", " "); dr["RESULT"] = "FALSE"; file.dt.Rows.Add(dr); file.SaveCsv(file.dt, file.GetFileName()); Error_Times++; Error_Count_TextBox.Text = Error_Times.ToString(); Temp_Receive_Buffer = new Byte[1024]; }