AT commands is use to communicate with GSM Madame and Mobile Phone.There are a lot of libraries which has been made using AT commands and These libraries are not Free it charge money for Using it But Today You learn how to Send and receive sms through AT commands .
Using AT commands you're not restricted to a specific phone model, as long as the phone supports the commands you are using.
Using AT commands you're not restricted to a specific phone model, as long as the phone supports the commands you are using.
This program uses the text mode for sending the message, which is good for starting, but it may not be supported by every phone. If you want to use the PDU mode instead of the text mode - which is supported by all mobiles but is more complicated - see the PDU encoding sample for creating the required data.
Sample source code is available for VB6.
Details about the VB6 sample:
This program uses the text mode for reading the messages, which is good for learning how it works, but it may not be supported by every phone. You may have to change character sets depending on the characters used in the messages to get the original text back.
Basically there are two ways to send SMS.
Lets Start..
Step-1
Open Visual Studio, Create a New Project with the Name SMS. (In this tutorial I'm not going to show you how to create a new project, I'm skipping the detail about it.)
Step-2
In the solution Explorer, Right Click on the Project and Click on Add -> Add New Item and Add New Class with the name SmsClass.cs copy the following code in the class.
SmsClass.cs
Now on the Form1, we'll use
Copy and Paste the following code in the Form1 Code.
Form1
and Run the Project. From the main Window Select COM Port on which your Modem/Phone is Connected to.
Note: This application is Tested using Nokia N82 By Me...
Download Source Code:
Sample source code is available for VB6.
Details about the VB6 sample:
- Shows how to use the MSComm ActiveX control
- Shows how to use the SMS AT commands
- Includes a trace output to see what's going on
- Includes error handling for common errors
- Is not optimized for performance
Download | ||||||||||||||||||||||||||
VB6: SendSMS_AT_VB6_20041025.zip | ||||||||||||||||||||||||||
Encoding SMS messages for PDU modeThis demonstrates how to create an SMS-SUBMIT PDU for a simple text message.
<EOF> = ASCII 26 = CTRL+Z |
Using AT commands to read SMS messages
Using AT commands you're not restricted to a specific phone model, as long as the phone supports the commands you are using.This program uses the text mode for reading the messages, which is good for learning how it works, but it may not be supported by every phone. You may have to change character sets depending on the characters used in the messages to get the original text back.
Download | |||
C#: ReadSMS_AT_CS20_20060718.zip Requires .NET Framework 2.0 |
Basically there are two ways to send SMS.
- Connect a mobile phone or GSM/GPRS modem to a computer / PC. Then use the computer / PC and AT commands to instruct the mobile phone or GSM/GPRS modem to send SMS messages.
- Connect the computer / PC to the SMS center (SMSC) or SMS gateway of a wireless carrier or SMS service provider. Then send SMS messages using a protocol / interface supported by the SMSC or SMS gateway.
Lets Start..
Step-1
Open Visual Studio, Create a New Project with the Name SMS. (In this tutorial I'm not going to show you how to create a new project, I'm skipping the detail about it.)
Step-2
In the solution Explorer, Right Click on the Project and Click on Add -> Add New Item and Add New Class with the name SmsClass.cs copy the following code in the class.
SmsClass.cs
using System;Step-3
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
using System.Windows.Forms;
namespace SMS
{
class SmsClass
{
SerialPort serialPort;
public SmsClass(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
}
public bool sendSms(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine(">" + messages + (char)(26));
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
}
return true;
}
else
return false;
}
public void Opens()
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Closes()
{
if (this.serialPort.IsOpen == true)
{
this.serialPort.Close();
}
}
}
}
Now on the Form1, we'll use
- combo Box (cboPorts) which will show the available ports on the computer.
- Two TextBoxes One for Receivers Cell No. (txtphone) and other for Message body (txtMessage) with Multiline property set to True.
- Send Button (btnSend) to Send SMS.
Copy and Paste the following code in the Form1 Code.
Form1
using System;Now , You Just need to connect your GSM modem/mobile to your PC through USB or Serial cable.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SMS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
loadPorts();
}
private void loadPorts()
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cboPorts.Items.Add(port);
}
}
private void btnSend_Click(object sender, EventArgs e)
{
SmsClass sm = new SmsClass(cboPorts.Text);
sm.Opens();
sm.sendSms(txtPhone.Text, txtMessage.Text);
sm.Closes();
MessageBox.Show("Message Sent!");
}
}
}
and Run the Project. From the main Window Select COM Port on which your Modem/Phone is Connected to.
Note: This application is Tested using Nokia N82 By Me...
Download Source Code:
http://www.multiupload.com/1E2JGHS1ZF
Sir, can I use these Codes for my Web Application?
ReplyDeleteYES YOU CAN this code for web application but your webserver must connected with GSM Deveice (or mobile phone)....To send and Receive sms
ReplyDeleteHi sir,
ReplyDeletecan i use vb6 codes for my application?and how can i connect my mobile to webserver?give details.thnxs
yes you can use vb6 codes for your application ...... And for connecting your mobile to web-server there are two possibilities
ReplyDelete1) create a web service which input a Cell number and Message and send sms.
2) save your messages (which you want to send) in database table and create a windows service which continuously reading this table and if new records for sending sms is came then read information from this table and send SMS.