Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
C#
string recievedData = ExecCommand(port, "AT", 300, "No phone connected at ");
recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
String command = "AT+CPMS?";
recievedData = ExecCommand(port, command, 1000, "Failed to count SMS message");
int uReceivedDataLength = recievedData.Length;

#endregion
//We received uReceivedDataLength 34 that false the condition
#region If command is executed successfully
if ((recievedData.Length >= 45) && (recievedData.StartsWith("AT+CPMS?")))
{

    #region Parsing SMS
    string[] strSplit = recievedData.Split(',');
    string strMessageStorageArea1 = strSplit[0];     //SM
    string strMessageExist1 = strSplit[1];           //Msgs exist in SM
    #endregion

    #region Count Total Number of SMS In SIM
    CountTotalMessages = Convert.ToInt32(strMessageExist1);
    #endregion

}

At last error show "There is no message in SIM"
Posted
Updated 13-Sep-14 3:49am
v2
Comments
MuhammadUSman1 13-Sep-14 3:51am    
It means you haven't any sms to receive.
Member 10028394 15-Sep-14 7:02am    
yes, i could received any message

1 solution

+CPMS? is the AT command to get information about which message stores are supported by the device, not to actually get the messages.
+CMGL="REC UNREAD" is the AT command to read unread messages from the message store, use "ALL" to get all messages.
You will only retrieve messages from the message store you have selected using a +CPMS="..." command, where +CPMS="MT" selects messages from both sim and phone storage.
 
Share this answer
 
v2
Comments
Member 10028394 15-Sep-14 7:01am    
Tell me how recievedData.Length>=45, i try but failed to recievedData.lenght>=45.
if you have a code to receive sms please send me thanks
Member 10028394 15-Sep-14 7:07am    
Please send me about details of AT commands.
i have use c5 nokia mobile
kbrandwijk 18-Sep-14 11:13am    
You can use the AT Command Tester, a Java app at http://m2msupport.net/m2msupport/module-tester/ to see the AT commands and responses needed for SMS and other functions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900