【发布时间】:2015-12-13 10:56:44
【问题描述】:
我正在开发一个通过 GSM 调制解调器发送 SMS 的应用程序,为此我使用 AT 命令。 当我调试我的应用程序时,短信会发送到接收方,但是当我运行应用程序时,短信不会发送到接收方。 我的代码如下,我的 gsm 调制解调器是 D-Link DWM-156。 我的代码有什么问题吗? 谢谢。
如果 (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++;
}
}
【问题讨论】:
标签: c# gsm at-command