C#短信发送错误(AT命令)
问题描述:
嘿家伙我试图从窗口窗体使用AT命令发送短信。但是陷入这个功能。它说:“Failed to set message format.
”C#短信发送错误(AT命令)
recievedData = ExecCommand(port,"AT+CMGF=1", 1000, "Failed to set message format."); // Error in this line => Failed to set message format
String command = "AT+CMGS=\"" + PhoneNo + "\"";
recievedData = ExecCommand(port,command, 300, "Failed to accept phoneNo");
command = Message + char.ConvertFromUtf32(26) + "\r";
recievedData = ExecCommand(port,command, 3000, "Failed to send message"); //3 seconds
if (recievedData.EndsWith("\r\nOK\r\n"))
{
isSend = true;
}
else if (recievedData.Contains("ERROR"))
{
isSend = false;
}
return isSend;
}
catch (Exception ex)
{
throw ex;
}
}
答
首先尝试使用超级终端发送的短信.. 那么这是我的代码有
_serialPort.Open();
_serialPort.Write("AT+CMGF=1\r");
_serialPort.Write("AT+CMGS=\"" + mobilenumber + "\"\r\n");
_serialPort.Write("My Mesage" + "\x1A");
_serialPort.Close();
+0
谢谢拉希德...我会检查出来,但将该代码发送短信到我的手机号码? –
+0
是的,你可以通过这个代码发送短信任何人..当你正确配置你的端口 –
+0
谢谢拉希德...我会检查你让你知道。 :) –
http://www.codeproject.com/Articles/38705/发送和阅读短信通过GSM调制解调器使用AT-Com阅读此页可能对您有所帮助... –
@AnantDabhi感谢您考虑我的帖子..但事实上,已从您提到的网站获取此代码,并且错误来自相同的代码。 我的手机连接到正确的端口,但无法获得通过该错误 –