want to make an application which can send sms or recieve sms from gsm modem to tracking unit device. i want to write my own whole code means no outer libraries have to use within it. i want to write it my ownself . i have to made not for mobile device, i attached
gsm modem with my computer through PCM slot.
c#
Please mark as Answer, if it helps you
________________________
maifs
Here is a good article on Sending SMS in C# using AT Command GSM Modem. There is a Sample Project for Download. If you need more information on this please feel free to ask to CodeGlobe Contributors
//Console.Write("Enter the port name your phone is connected to: ");
//string portname = Console.ReadLine();
string portname = txtPortName.Text;
port = EstablishConnection(portname);
string recievedData = ExecuteCommand("AT",
300); // Hang On this Line
recievedData = ExecuteCommand(
"AT+CMGF=1", 300);
// Console.Write("Enter the phone number you want to send message to: ");
//String phoneNumber = Console.ReadLine();
String phoneNumber = txtPhoneNumber.Text;
String command =
"AT+CMGS=\"" + phoneNumber +
"\"";
//Console.Write("Enter the message you want to send: ");
Please check your connection details, might be the problem with the port i think it is not connected properly, and one more thing according to me the baud rate must be around 11,000 .
test the connection with hyper terminal with the same parameter that ur setting in the program and test the AT commands.
i am facing a problem when sendig or receiving messages from GSM modem.
when i try to debug this below code then it throws an exception such as:
{System.ArgumentException: The given port name does not start with COM/com or does not resolve to a valid serial port.
Parameter name: portName
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at _Default.EstablishConnection(String portName) in e:\Lectures\sullAll\lectures\finalProject\Final Project Application\VehicleTrackingSystem\Default.aspx.cs:line 106
at _Default.btnSubmit_Click(Object sender, EventArgs e) in e:\Lectures\sullAll\lectures\finalProject\Final Project Application\VehicleTrackingSystem\Default.aspx.cs:line 33}
i am trying this..
}
Please mark as Answer, if it helps you
________________________
maifs
maifs
Member
375 Points
378 Posts
sending sms or recieving sms from gsm modem to tracking unit
Apr 10, 2009 10:49 AM|LINK
c#
Please mark as Answer, if it helps you
________________________
maifs
SurendraKish...
Contributor
2078 Points
376 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
Apr 10, 2009 01:16 PM|LINK
Checkout this article. this might help u out.
http://www.codeproject.com/KB/cs/SMS.aspx?fid=457949&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=51
THIS REDUCES TIME FOR OTHERS..!
maifs
Member
375 Points
378 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
Apr 10, 2009 03:06 PM|LINK
Please mark as Answer, if it helps you
________________________
maifs
irisweb
Member
26 Points
9 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
Apr 23, 2009 10:22 AM|LINK
Here is a good article on Sending SMS in C# using AT Command GSM Modem. There is a Sample Project for Download. If you need more information on this please feel free to ask to CodeGlobe Contributors
http://codeglobe.blogspot.com/2009/02/sending-sms-in-cnet-using-gsm-modem-and.html
Also there is AT Command Set of Sony Ericssion
http://codeglobe.blogspot.com/2009/02/at-command-set-for-sony-ericsson.html
C#.Net SMS in c# SMS from web application
syedyaserahm...
Member
209 Points
200 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
Apr 23, 2009 01:11 PM|LINK
Here is the C# code for sending and receiving sms
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static AutoResetEvent readNow = new AutoResetEvent(false);
static SerialPort port;
static void Main(string[] args)
{
try
{
Console.Write("Enter the port name your phone is connected to: ");
string portname = Console.ReadLine();
port = EstablishConnection(portname);
string recievedData = ExecuteCommand("AT", 300);
recievedData = ExecuteCommand("AT+CMGF=1", 300);
Console.Write("Enter the phone number you want to send message to: ");
String phoneNumber = Console.ReadLine();
String command = "AT+CMGS=\"" + phoneNumber + "\"";
Console.Write("Enter the message you want to send: ");
recievedData = ExecuteCommand(command, 300);
string message = Console.ReadLine();
command = message + char.ConvertFromUtf32(26) + "\r";
recievedData = ExecuteCommand(command, 300);
if (recievedData.EndsWith("\r\nOK\r\n")) recievedData = "Message sent successfully";
if (recievedData.Contains("ERROR"))
{
string recievedError = recievedData;
recievedError = recievedError.Trim();
recievedData = "Following error occured while sending the message" + recievedError;
}
Console.WriteLine(recievedData);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error Message: "+e.Message.Trim()+"\r\nHit any key to Exit"); Console.ReadLine();
}
finally
{
if (port != null)
{
port.Close();
port.DataReceived -= new SerialDataReceivedEventHandler(DataReceived);
port = null;
}
}
}
static string ExecuteCommand(string command,int timeout)
{
port.DiscardInBuffer();
port.DiscardOutBuffer();
readNow.Reset();
port.Write(command+"\r");
string recieved = receive(timeout);
return recieved;
}
static string receive(int timeout)
{
string buffer = string.Empty;
do
{
if (readNow.WaitOne(timeout, false))
{
string t = port.ReadExisting();
buffer += t;
}
}
while (!buffer.EndsWith("\r\nOK\r\n") && !buffer.EndsWith("\r\n> ") && !buffer.Contains("ERROR"));
return buffer;
}
static SerialPort EstablishConnection(string portName)
{
SerialPort port = new SerialPort();
port.PortName = portName;
port.BaudRate = 19200;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None; port.ReadTimeout = 300;
port.WriteTimeout = 300;
port.Encoding = Encoding.GetEncoding("iso-8859-1");
port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
return port;
}
static void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars) readNow.Set();
}
}
}
Please mark as answer if helpful this is not using any external libraries
rastogi.mahe...
Member
117 Points
47 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
May 29, 2009 08:49 AM|LINK
Hi,
I am using this code on Windows form but Code string recievedData = ExecuteCommand("AT", 300); Hang at this Line
Code is given below
static AutoResetEvent readNow = new AutoResetEvent(false); static SerialPort port; private void btnActive_Click(object sender, EventArgs e){
try{
//Console.Write("Enter the port name your phone is connected to: "); //string portname = Console.ReadLine(); string portname = txtPortName.Text;port = EstablishConnection(portname);
string recievedData = ExecuteCommand("AT", 300); // Hang On this LinerecievedData = ExecuteCommand(
"AT+CMGF=1", 300); // Console.Write("Enter the phone number you want to send message to: "); //String phoneNumber = Console.ReadLine(); String phoneNumber = txtPhoneNumber.Text; String command = "AT+CMGS=\"" + phoneNumber + "\""; //Console.Write("Enter the message you want to send: ");recievedData = ExecuteCommand(command, 300);
//string message = Console.ReadLine(); string message = txtMessage.Text;command = message +
char.ConvertFromUtf32(26) + "\r"; recievedData = ExecuteCommand(command, 300); if (recievedData.EndsWith("\r\nOK\r\n"))recievedData =
"Message sent successfully"; if (recievedData.Contains("ERROR")){
string recievedError = recievedData;recievedError = recievedError.Trim();
recievedData = "Following error occured while sending the message" + recievedError;}
//Console.WriteLine(recievedData); MessageBox.Show(recievedData); //Console.ReadLine();}
catch (Exception ex){
//Console.WriteLine("Error Message: " + ex.Message.Trim() + "\r\nHit any key to Exit"); //Console.ReadLine(); MessageBox.Show(ex.ToString());}
finally{
if (port != null){
port.Close();
port.DataReceived -= new SerialDataReceivedEventHandler(DataReceived); port = null;}
}
}
static string ExecuteCommand(string command, int timeout){
port.DiscardInBuffer();
port.DiscardOutBuffer();
readNow.Reset(); port.Write(command + "\r");string recieved = receive(timeout); return recieved;}
static string receive(int timeout){
string buffer = string.Empty; do{
if (readNow.WaitOne(timeout, false)){
string t = port.ReadExisting();buffer += t;
}
}
while (!buffer.EndsWith("\r\nOK\r\n") && !buffer.EndsWith("\r\n> ") && !buffer.Contains("ERROR"));return buffer;}
static SerialPort EstablishConnection(string portName){
SerialPort port = new SerialPort();port.PortName = portName;
port.BaudRate = 19200;
//port.BaudRate = 9600;port.DataBits = 8;
port.StopBits = StopBits.One;port.Parity = Parity.None;port.ReadTimeout = 300;
port.WriteTimeout = 300;
port.Encoding = Encoding.GetEncoding("iso-8859-1");port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);port.Open();
port.DtrEnable =
true; port.RtsEnable = true; return port;}
static void DataReceived(object sender, SerialDataReceivedEventArgs e){
if (e.EventType == SerialData.Chars) readNow.Set();}
Please help me. It's Urgent
syedyaserahm...
Member
209 Points
200 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
May 30, 2009 07:32 AM|LINK
Hi! Rastogi
Please check your connection details, might be the problem with the port i think it is not connected properly, and one more thing according to me the baud rate must be around 11,000 .
test the connection with hyper terminal with the same parameter that ur setting in the program and test the AT commands.
i hope this will solve your problem .
maifs
Member
375 Points
378 Posts
Re: sending sms or recieving sms from gsm modem to tracking unit
Nov 20, 2009 09:01 PM|LINK
i am facing a problem when sendig or receiving messages from GSM modem.
when i try to debug this below code then it throws an exception such as:
{System.ArgumentException: The given port name does not start with COM/com or does not resolve to a valid serial port.
Parameter name: portName
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at _Default.EstablishConnection(String portName) in e:\Lectures\sullAll\lectures\finalProject\Final Project Application\VehicleTrackingSystem\Default.aspx.cs:line 106
at _Default.btnSubmit_Click(Object sender, EventArgs e) in e:\Lectures\sullAll\lectures\finalProject\Final Project Application\VehicleTrackingSystem\Default.aspx.cs:line 33}
i am trying this..
Please mark as Answer, if it helps you
________________________
maifs
jayakumari
Member
6 Points
4 Posts
Re: sending sms or recieving sms from with our gsm modem
Nov 23, 2009 10:15 AM|LINK
i need a asp.net coding to send sms from pc