我正在开展项目,我必须向presons发送短信。如果这些人没有收到短信,我必须再次发送给他。所以,因为我需要成功的短信发送报告。如何获取和阅读短信发送状态或报告。我使用的是SIMCOM 800设备,项目语言是c#.net(console appplication)。
Snippet Code Here ...
Program.cs的
public void SendSMS(string sim, string message)
{
//.............................................. Send SMS ....................................................
try
{
if (objclsSMS.sendMsg(this.port, sim, message))
{
//MessageBox.Show("Message has sent successfully");
Console.WriteLine("Message has sent successfully");
}
else
{
//MessageBox.Show("Failed to send message");
Console.WriteLine("Failed to send message");
}
//Console.ReadLine();
}
catch (Exception ex)
{
ErrorLog(ex.Message);
}
}
clcSMS.cs
#region Send SMS
static AutoResetEvent readNow = new AutoResetEvent(false);
public bool sendMsg(SerialPort port, string PhoneNo, string Message)
{
bool isSend = false;
try
{
string recievedData = ExecCommand(port, conncetioncmd, 300, "No phone connected");
recievedData = ExecCommand(port, msgformatcmd, 300, "Failed to set message format.");
//recievedData = ExecCommand(port, "AT+CSMP=49,167,0,242", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=1.0.0.1.0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=1,1,0,0,0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=1,0,0,1,0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=2,2,0,0,0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=2", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CSMP=49,167,0,0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CNMI=2,2,0,1,0", 300, "Failed to accept phoneNo");
//recievedData = ExecCommand(port, "AT+CSAS", 300, "Failed to accept phoneNo");
String command = msgcmd + 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;
}
}
static void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
if (e.EventType == SerialData.Chars)
readNow.Set();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public string ExecCommand(SerialPort port,string command, int responseTimeout, string errorMessage)
{
try
{
port.DiscardOutBuffer();
port.DiscardInBuffer();
receiveNow.Reset();
port.Write(command + "\r");
string input = ReadResponse(port, responseTimeout);
if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
throw new ApplicationException("No success message was received.");
return input;
}
catch (Exception ex)
{
throw ex;
}
}
有人能指出我正确的方向吗?
提前致谢。
答案 0 :(得分:0)
@Mohit我会感谢你的问题,我对android有所了解。 在我们的例子中,我们获取接收器以获取任何系统目的消息。 因此,如果您有任何接收器从您的设备获得响应,那么您可以获得发送消息的报告.. 但是在这种情况下您可能无法获得阅读状态如果有可用的功能你的C#(控制台应用程序)。