public void Serial_Receive(object sender, SerialDataReceivedEventArgs e) { try { Helper.Serial serial = new Helper.Serial(); get_sRecvData = serial.Read(); if ((get_sRecvData != string.Empty)) // && (g_sRecvData.Contains('\n'))) { serial_buffer += get_sRecvData; if (get_sRecvData.Contains("$e")) { SetText(serial_buffer); serial_buffer = String.Empty; //serial.Buffer_Clear(); } else if (get_sRecvData.Contains("$mw")) { serial.Write(TransferData()); serial_buffer = String.Empty; } else if (get_sRecvData.Contains("$mrcplt")) { System.Windows.MessageBox.Show("읽기 완료"); serial_buffer = String.Empty; serial.Buffer_Clear(); } else if (get_sRecvData.Contains("$complate")) { System.Windows.MessageBox.Show("쓰기 완료"); serial_buffer = String.Empty; serial.Buffer_Clear(); } else if (get_sRecvData.Contains("$ce")) { serial_buffer = String.Empty; serial.Buffer_Clear(); } } } catch (TimeoutException) { get_sRecvData = string.Empty; } }
private void btn_Serial_Close_Click(object sender, RoutedEventArgs e) { Helper.Serial serial = new Helper.Serial(); serial.Buffer_Clear(); if (serial.Close()) { tb_status.Text = "Disconnected"; btn_status_change(); serial.Dispose(); } }