public string WaitingData(int timeout, string ResultContain = null, string Error = "") { receive_AutoResponse.Reset(); try { string result = ""; do { if (receive_AutoResponse.WaitOne(timeout, false)) { string t = SpGSM_Modem_AutoResponse.ReadExisting(); result += t; } else { string t = SpGSM_Modem_AutoResponse.ReadExisting(); result += t; return(result); } }while ((!result.EndsWith("\r\nOK\r\n") && !result.EndsWith("\r\n> ") && !result.EndsWith("\r\nERROR\r\n") && !result.EndsWith("\r\n") && !result.EndsWith("\r")) && ((ResultContain != null && result.Contains(ResultContain)) || ResultContain == null)); return(result); } catch (Exception ex) { LoggingData.WriteLog(ex); return(string.Empty); } }
public string ExecuteCommands(string ATcommand, int timeout, string Error = "") { receiveNow.Reset(); try { string result = ""; SpGSM_Modem.Write(ATcommand + "\r"); do { if (receiveNow.WaitOne(timeout, false)) { string t = SpGSM_Modem.ReadExisting(); result += t; } else { string t = SpGSM_Modem.ReadExisting(); result += t; return(result); } }while (!result.EndsWith("\r\nOK\r\n") && !result.EndsWith("\r\n> ") && !result.EndsWith("\r\nERROR\r\n")); return(result); } catch (Exception ex) { LoggingData.WriteLog(ex); return(ex.Message); } }