public void LoadLogFile(string pathname) { string line; System.IO.StreamReader file = new System.IO.StreamReader(pathname); while ((line = file.ReadLine()) != null) { ParseTags(line, 0); //send message to UI if (null != TagLine) { TagLine.Invoke(line); } } file.Close(); }
//we have recieved serial data, get a line of it and send it to the parser private void serialDataReceived(object sender, SerialDataReceivedEventArgs e) { string temp; string Rx; int position = 0; if (TheSerialPort.IsOpen) { int cr; try { //get rx chars RXBuffer += TheSerialPort.ReadExisting(); //is there a \n? cr = RXBuffer.IndexOf("\n"); //there HAS to be at least 1 character to be at all valid; while (cr >= 0) { //copy all data up to \n //as long as there IS data //if (cr > 1) //{ Rx = RXBuffer.Substring(position, cr - position); //send message to UI if (null != TagLine) { TagLine.Invoke(Rx); } //Trace.WriteLine(Rx + "\n"); //Process the message //try //{ // //do //may have multiple tags per line // //{ position = ParseTags(Rx, position); // //} // //while ((position > 0) && (position < Rx.Length)); //} //catch (Exception ex) //{ // Trace.WriteLine("serial0, " + ex.Message + "\n"); // Type ep = ex.GetType(); // return; //} //} //Copy everything after \n back into rx buffer, removing string just sent int len = RXBuffer.Length - (cr + 1); temp = string.Empty; //Anything left to copy? if (len > 0) { temp = RXBuffer.Substring(cr + 1, len); } RXBuffer = temp; //any more \n? position = 0; cr = RXBuffer.IndexOf("\n", position); } //position = 0; //stripError.Text = "No Errors"; } catch (Exception ex) { Trace.WriteLine("serial, " + ex.Message + "\n"); Type ep = ex.GetType(); return; } } }