For retrieving inbox details from a GSM mobile phone is not simple as the sending messages from phone using PC with the help of a AT Commands. Here we need to check whether your phone store your messages in the SIM memory or phone memory. We need to alter our messages according to the storage type of the messages.
Here are the example in the case of storing the messages inside the inbox.
AT Command
AT // For checking phone connected
AT+CMGF=1 // Setting message format
AT+CSCS="PCCP437" // Setting charset
AT+CPMS="SM" // Selecting sim message storage
AT+CMGL="ALL" // Reading all inbox messages
Function for reading message collection
public ShortMessageCollection ReadSMS(SerialPort port)
{
// Set up the phone and read the messages
ShortMessageCollection messages = null;
try
{
#region Execute Command
// Check connection
ExecCommand(port,"AT", 300, "No phone connected");
// Use message format "Text mode"
ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format.");
// Use character set "PCCP437"
ExecCommand(port,"AT+CSCS=\"PCCP437\"", 300, "Failed to set character set.");
// Select SIM storage
ExecCommand(port,"AT+CPMS=\"SM\"", 300, "Failed to select message storage.");
// Read the messages
string input = ExecCommand(port,"AT+CMGL=\"ALL\"", 5000, "Failed to read the messages.");
#endregion
#region Parse messages
messages = ParseMessages(input);
#endregion
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
if (messages != null)
return messages;
else
return null;
}
Monday, October 19, 2009
Subscribe to:
Post Comments (Atom)
Hi! The function can't work.
ReplyDeleteShortMessageCollection lost using namespace??
Can u help me?
Ur function is importment to me. Thank you
this is my email : nelson_liu@msn.com
Okay, I will give you the whole class file. Please go to the link I provided.
ReplyDeletehttp://docs.google.com/View?id=dgc3t2gt_9gz4mc8hc
Save this class file and add to your project.
Please let us know if you have any more doubts.
Is there a reason for
ReplyDeleteif (messages != null)
return messages;
else
return null;
Can't it just be
return messages;
You need check your mobile phones set number, some nokia phones did not support the CGL AT commands.
ReplyDeletehey Joseph
ReplyDeleteI am making a project that needs to send and read messages using a GSM modem.
I tried out the AT commands that you have posted here.
But i had an error with the command AT+CPMS ="SM" and also with AT+CMGL="ALL"
i am using my Nokia 6681 as a GSM modem.
Can you pls help me with this ???
I am able to send SMS but reading gives an error.
I think your mobile phone will not support the AT+CMGL="ALL" command , use little older nokia phone.
ReplyDeletehi sir,
ReplyDeletei use the complete class file.but it create the following error :
The type or namespace name 'ShortMessageCollection' could not be found (are you missing a using directive or an assembly reference?).
please help me.
my email address:cse.tanim@yahoo.com
thank you.
Check your are correctly given the proper Namespaces , System.IO etc.
ReplyDeletei use the following namespaces.but it contineously generate the error:
ReplyDeleteThe type or namespace name 'ShortMessageCollection' could not be found (are you missing a using directive or an assembly reference?).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Threading;
using System.Text.RegularExpressions;
plz help me an inform me that what the actual missing namespaces that can solve the error
thank you.
okay , there are two extra clases called
ReplyDeleteShortMessage.cs and ShortMessageCollection.cs and it contains the code
create new class ShortMessage.cs in your project and paste these code
using System;
using System.Collections.Generic;
using System.Text;
public class ShortMessage
{
#region Private Variables
private string index;
private string status;
private string sender;
private string alphabet;
private string sent;
private string message;
#endregion
#region Public Properties
public string Index
{
get { return index;}
set { index = value;}
}
public string Status
{
get { return status;}
set { status = value;}
}
public string Sender
{
get { return sender;}
set { sender = value;}
}
public string Alphabet
{
get { return alphabet;}
set { alphabet = value;}
}
public string Sent
{
get { return sent;}
set { sent = value;}
}
public string Message
{
get { return message;}
set { message = value;}
}
#endregion
}
public class ShortMessageCollection : List
{
}
create another class called ShortMessageCollection.cs and paste these code
using System;
using System.Collections.Generic;
using System.Text;
The article has been copied from:
ReplyDeletehttp://69.10.233.10/KB/cs/Send_and_Read_SMS.aspx
Check out this link for more details.
Yes you are right, I have alredy gave the reference link to the codeproject. My project is not the copy of codeproject's project combined app from many websites. I have given those websites link as reference at the home.
ReplyDeletehaii
ReplyDeleteI got an Error
"The name 'ExecCommand' does not exist in the current context"
Please send the codes
on praneeshpeeyar.codes@gmail.com if u dont mind
do you have the code for the same in c++
ReplyDelete