// auto-scroll private void SerialRXBox_TextChanged(object sender, EventArgs e) { if (SerialRXEnableCheck.Checked) { SerialRXBox.SelectionStart = SerialRXBox.Text.Length; SerialRXBox.ScrollToCaret(); } }
private void WriteToLog() { do { if (tagData != "") { int tempInt; char tempChar; string intStr, tempStr; if (statReady) { /* * Next lines should look like this. For now, assume it's always gonna be 4 lines * * 0000: 24 36 39 30 32 35 30 43 42 38 36 31 35 31 30 30 $690250CB8615100 * 0010: 33 30 36 33 39 39 36 30 32 30 31 38 30 31 31 33 3063996020180113 * 0020: 31 32 31 36 31 30 2D 32 30 30 34 30 61 33 34 20 121610 - 20040a34 * 0030: 53 54 2D 39 32 30 2D 43 4C 6B 30 30 32 30 33 38 ST-920-CLk002038 * 0040: 30 31 33 38 30 30 30 31 30 30 36 31 31 30 01380001006110 */ if (tagData.Contains("ST-920-CL")) { // skip the version number as well intStr = tagData.Substring(tagData.IndexOf("ST-920-CL") + 13); if (int.TryParse(intStr, out tempInt)) { BatLev = tempInt; } } else if (tagData.Contains("0040:")) { int index = 0; // skip the decoded ascii chars columns tempStr = tagData.Substring(tagData.IndexOf("0040:") + 58); tempStr = tempStr.Trim(); // remove white spaces intStr = tempStr.Substring(index, 4); if (int.TryParse(intStr, out tempInt)) { ACalls = tempInt; } index += 4; intStr = tempStr.Substring(index, 4); if (int.TryParse(intStr, out tempInt)) { CCalls = tempInt; } index += 4 + 2; // next 2 chars are reserved intStr = tempStr.Substring(index, 1); if (char.TryParse(intStr, out tempChar)) { TOS = tempChar; } index += 1; intStr = tempStr.Substring(index, 2); if (int.TryParse(intStr, out tempInt)) { CallStatus = tempInt; } WriteToStat(); statReady = false; GPSFix = 0; BatLev = 0; ACalls = 0; CCalls = 0; TOS = '0'; CallStatus = 0; CallNum++; } } else if (onCall) { // get GPSFix result if (tagData.Contains("fixTime")) { //int fixtime; tempStr = tagData.Substring(tagData.IndexOf("fixTime") + 8); tempStr.Trim(); intStr = tempStr.Substring(0, 3); if (int.TryParse(intStr, out tempInt)) { GPSFix = tempInt; } //statStream.WriteLine("{0} [{1}] ({2})", GPSFix, intStr, tempStr); //statStream.Flush(); } // look for status log else if (tagData.Contains("addEntryToLog")) { statReady = true; } else if (tagData.Contains("PowerOffSim")) { //statWaitHandle.Set(); callTimer.Stop(); onCall = false; flukeTimer.Change(0, 500); // reduce sampling rate while not on call } } else if (tagData.Contains("PowerOnSim")) { onCall = true; callTimer.Restart(); flukeTimer.Change(0, 50); // increase sampling rate while on call } //else if (tagData.Contains("nextState")) //{ // int state; // string stateString = tagData.Substring(tagData.IndexOf("nextState") + 9); // // decimal after "nextState" is the state number // if (int.TryParse(stateString, out state)) // { // callState = state; // } //} if (SerialRXEnableCheck.Checked) { SerialRXBox.Invoke((MethodInvoker) delegate { SerialRXBox.AppendText(tagData); }); } if ((TimestampCheck.Checked)) { tagStream.Write("[ {0} ] ", ((double)(upTime.ElapsedMilliseconds)) / 1000); } tagStream.Write(tagData); tagStream.Flush(); logWaitHandle.WaitOne(); } }while (tagPort.IsOpen); }