public bool Open1() { string s = null; if (SMSPort.IsOpen == false) { try { SMSPort.Open(); SMSPort.Write("AT\r\n"); Thread.Sleep(100); s = SMSPort.ReadExisting(); if (s.Contains("OK")) { SMSPort.Write("AT+CFUN=1\r\n"); ReadThread.Start(); return(true); } else { if (SMSPort.IsOpen) { SMSPort.Close(); } return(false); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); return(false); } } return(true); }
public bool SendSMS(string CellNumber, string SMSMessage) { string MyMessage = null; string s = null;;; //Check if Message Length <= 160 if (SMSMessage.Length <= 160) { MyMessage = SMSMessage; } else { MyMessage = SMSMessage.Substring(0, 160); } if (SMSPort.IsOpen == true) { SMSPort.Write("AT+CMGF=1\r\n"); Thread.Sleep(1000); SMSPort.Write("AT+CMGS=\"" + CellNumber + "\"\r\n"); Thread.Sleep(1000); SMSPort.Write(SMSMessage + (char)(26) + Environment.NewLine); Thread.Sleep(1000); s = SMSPort.ReadExisting(); _Continue = false; if (Sending != null) { Sending(false); } } return(false); }