string CommBuffer = ""; //holds incoming serial data from the port private void SerialRXEventHandler(object source, SDRSerialSupportII.SerialRXEvent e) { // SIOMonitor.Interval = 5000; // set the timer for 5 seconds // SIOMonitor.Enabled = true; // start or restart the timer CommBuffer += AE.GetString(e.buffer,0,e.buffer.Length); //put the data in the string if(parser != null) //is the parser instantiated { try { Regex rex = new Regex(".*?;"); //accept any string ending in ; string answer; byte[] out_string; uint result; for(Match m = rex.Match(CommBuffer); m.Success; m = m.NextMatch()) //loop thru the buffer and find matches { answer = parser.Get(m.Value); //send the match to the parser out_string = AE.GetBytes(answer); //get the answer from the parser result = SIO.put(out_string, (uint) out_string.Length); //send the answer to the serial port CommBuffer = CommBuffer.Replace(m.Value, ""); //remove the match from the buffer } } catch(Exception) { //Add ex name to exception above to enable // Debug.WriteLine("RX Event: "+ex.Message); // Debug.WriteLine("RX Event: "+ex.StackTrace); } } }
private void SerialRXEventHandler(object source, SDRSerialSupportII.SerialRXEvent e) { try { lock (this) { SIOMonitorCount = 0; // reset watch dog! } Regex rex = new Regex(".*?;"); byte[] out_string = new byte[1024]; CommBuffer += AE.GetString(e.buffer, 0, e.buffer.Length); Debug.Write(CommBuffer + "\n"); if (console.CATRigType == 1) { byte[] buffer = new byte[e.buffer.Length + 1]; byte[] question = new byte[16]; byte[] answer = new byte[16]; byte[] question1 = new byte[1]; int j = 0; for (int i = 0; i < e.buffer.Length; i++) { if (e.buffer[i] == 0xfd) { question[j] = e.buffer[i]; if (question[2] == console.CATRigAddress) { if (debug && !console.ConsoleClosing) { string dbg_msg = ""; for (int k = 0; k < j + 1; k++) { dbg_msg += question[k].ToString("X").PadLeft(2, '0'); dbg_msg += " "; } if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "CAT command: " + dbg_msg); } } if (console.CATEcho) { if (question1.Length != j) question1 = new byte[j + 1]; for (int k = 0; k < j + 1; k++) question1[k] = question[k]; send_data = question1; // echo send_event.Set(); Thread.Sleep(10); } answer = parser.Get(question); send_data = answer; send_event.Set(); j = 0; } else { } } else { question[j] = e.buffer[i]; j++; } } CommBuffer = ""; } else { bool split = true; for (Match m = rex.Match(CommBuffer); m.Success; m = m.NextMatch()) { split = false; string answer; answer = parser.Get(m.Value); if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "CAT command: " + m.Value.ToString()); } out_string = AE.GetBytes(answer); send_data = out_string; send_event.Set(); } if(!split) CommBuffer = ""; } } catch (Exception ex) { CommBuffer = ""; if (debug && !console.ConsoleClosing) { console.Invoke(new DebugCallbackFunction(console.DebugCallback), "CAT SerialRXEvent error! \n" + ex.ToString()); Debug.Write(ex.ToString()); } } finally { SIO.rx_event.Set(); } }