I am working on an application that sends SMS through GSM Modem, and i use AT Commands for that. When i debug my application, Then sms is sent to reciever, but when i run the application sms is not sent to Reciever. My code is below and my gsm Modem is D-Link DWM-156. is there any wrong here in my code? thanks.
if (SPort.IsOpen) {
int i = 0;
while (i < msgs.Count)
{
SPort.DiscardInBuffer();
System.Threading.Thread.Sleep(1000);
var res = SPort.ReadExisting();
SPort.DiscardOutBuffer();
System.Threading.Thread.Sleep(1000);
SPort.Write("AT\r");
System.Threading.Thread.Sleep(1000);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "1" + res + "---";
SPort.Write("AT+CMGF=0\r");
System.Threading.Thread.Sleep(100);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "2" + res + "---";
SPort.Write("AT+CSCS=\"HEX\"\r");//char set
System.Threading.Thread.Sleep(100);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "3" + res + "---";
SPort.Write("AT+CSMP=17,71,0,17\r");
System.Threading.Thread.Sleep(100);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "4" + res + "---";
string hexString = msgs[i];
SPort.Write(string.Format("AT+CMGS={0}\r", (hexString.Length - 16) / 2));
System.Threading.Thread.Sleep(100);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "5" + res + "---";
SPort.Write(string.Format("{0}{1}\n", hexString, Convert.ToChar(26)));
System.Threading.Thread.Sleep(100);
while ((res = SPort.ReadExisting()).Contains("ERROR")) ;
resultResponse += "6" + res + "---";
System.Threading.Thread.Sleep(1500);
response += res;
i++;
}
}