短信发送GSM

时间:2018-12-01 14:38:31

标签: c# sms gsm modem

我正在一个项目中,我必须使用AT命令在GSM调制解调器中发送和接收SMS。从SIM卡中读取短信。我已经尝试过以下代码,希望获得实际的SMS。但是我只是得到响应“ OK”,是否有适当的方法来做到这一点?

`public void Read()     {         Console.WriteLine(“ Reading ...”);

    gsmPort.WriteLine("AT+CMGF=1"); // SET MODE TO TEXT
    Thread.Sleep(1000); //1sec to write
    gsmPort.WriteLine("AT+CPMS =\"SM\""); // SET STORAGE TO SIM
    Thread.Sleep(1000); //1sec to write
    gsmPort.WriteLine("AT+CMGL=\"ALL\"");
    gsmPort.WriteLine("AT+CMGL=\"REC UNREAD\"");
    //gsmPort.WriteLine("AT+CMGR ")
    Thread.Sleep(1000); //1sec to write


    string response = gsmPort.ReadExisting();
    if (response.EndsWith("\r\nOK\r\n")) 
    {
        Console.WriteLine(response);

    }
    else
    {
        Console.WriteLine(response);

    }


}`

0 个答案:

没有答案