短信发送报告AT命令

本文关键字:命令 AT 报告 短信发送 | 更新日期: 2023-09-27 18:16:00

我正在做一个项目,我必须向人发送短信。如果对方没有收到短信,我就得再发一次。所以,我需要成功的短信交付报告。如何获取和阅读短信发送状态或报告?我使用SIMCOM 800设备,项目语言是c#.net(控制台应用程序)。

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;
            }
        }   
谁能给我指个正确的方向?

短信发送报告AT命令

@Mohit我很欣赏你的问题,我对android很了解。在我们的例子中,我们正在获取用于获取任何系统目的消息的接收器。如果你有任何接收器用于从你的设备获取响应那么你可以获得发送消息的报告。但是在这种情况下,读取状态可能是不可能的,如果c#(控制台应用程序)中的功能可用,则只能获得交付状态