Monday, October 19, 2009

Retrieving inbox from mobile

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;

}

Saturday, September 26, 2009

Sample projects using C#.Net , Communication GSM modem with PC

In this blog I like to tell you about the communication between the PC and GSM modem in mobile phone. Iam creating this sample application in C#.Net and SQL Server , for communicating with GSM mobile phone we need to know how to execute AT commands in Windows Hyper-terminal.

Microsoft HyperTerminal

Microsoft HyperTerminal is a small program that comes with Microsoft Windows. You can use it to send AT commands to your mobile phone or GSM/GPRS modem. It can be found at Start -> Programs -> Accessories -> Communications -> HyperTerminal. If you cannot find it and you are using Windows 98, then probably you have not installed it. You can go to Control Panel -> Add/Remove Programs -> Windows Setup tab -> Communications list box item -> Details button to install MS HyperTerminal.
for more details follow this web site :http://www.developershome.com/sms/howToUseHyperTerminal.asp

Hypertreminal communicates directly with the modem /mobile connected and instructs the modem. It also gives responses back as OK or error etc. But if we have a application where we need to send SMS after a specific set of actions, then hypertreminal is not useful, since it requiers manual typing. You need to select the COM port on which modem/mobile is connected.(port can be serial port for modem or USB port for mobile).

Sending through hyper-terminal

AT
OK
AT+CMGF=1
OK
AT+CMGW="+cell number",129
> Your sms message content [
press ctrl Z ]



Sending SMS through GSM modem.




First let us examine how to send SMS through a GSM mobile phone in C#.Net.

1. Connect the phone to the PC and Install modem driver software , for eg Nokia pc suite
2. Refer the AT commands for communicating with GSM Modem.
3. Test these commands through windows hyperterminal.
4. Find the port address of the COM port of the modem from device manager.
5. Use these port address in our application for sending SMS.


Creating code in C#

Create new project and add new class SMSCOMMS.cs .
In the class import class library Threading, ComponentModel, IO.Ports

Click here to view the whole class file.

Iam now try to develop the receiving the list of inbox items , sent items and trash in a mobile phone.


References

www.codeproject.com

AT Commands

www.shefeekj.com