www codeproject com
DESCRIPTION
codeTRANSCRIPT
10,122,835 members (54,768 on lin e)
Sign in
home quick answers discussions features community
helpSearch fo r articles, qu estion s, tip s
Articles » Languages » C# » Applications
Article
Browse Code
Stats
Revisions
Alternatives
Comments &Discussions (907)
About Article
SMS Client - ServerSoftware is used forsending, reading, deletingmessages. It uses GSMmodem for sending SMS. Itlistens for incomingmessages to arrive,processes the read messageand takes actionaccordingly. This SMSsoftware requiresGSMComm Library whichyou can also download.
Type Article
Licence Apache
First Posted 10 Sep 2007
Views 2,010,779
Downloads 51,604
Bookmarked 379 times
.NET1.1 VS.NET2003
C#1.0 Windows Dev , +
Top News
Tim Cook slams Android,citing low usage
Get the Insider News free eachmorning.
Related Videos
Related ArticlesSend and Read SMS through aGSM Modem using ATCommands
Implementing an SMS QuizServer Using a GSM ModemEnabled Mobile Phone
Introduction to AT commandsand its uses
How to Send SMS Messagesfrom C# using an SQL Database
How to add SMS functionalityto websites
How to conduct an SMS surveyusing a cell phone connectedSMS gateway and MS Access
vb.net AT commands to sendSMS
SMS Service
RS232 Modem Wrapper
3G Modem Internet Dialer
Encoding / Decoding 7 bit UserData for SMS PDU (PDU BitPacker)
Using VB.NET to Encode SMSand EMS
Bulk SMS Sender
.NET Phone CommunicationLibrary Part IV - Receive SMS
Sending SMS using .NET
Make Call Blocker Applicationon Windows mobile
Next
Sign Up to vote
How To Send and Receive SMS using GSM ModemBy Ranjan.D, 10 Sep 2007
Download source files - 295.1 KB
IntroductionSMS client and server is an application software which is used for sending and receiving messages(SMS). Itlistens for incoming messages to arrive, processes the message if it's in a valid format. Note the processingof arrived messages depends on the application which will be discussed later. I am going to explain thefollowing things:
1. Communication Port Settings2. Receive Incoming Message3. Send Messages4. Read All Messages (Sent by the users)5. Delete Messages (One or All)
I have used the GSMComm Library for Sending and Receiving SMS. You require a GSM modem or phone forsending an SMS.
Using the code
1) Communication Port Settings
CommSetting class is used for storing comm port settings:
Co llapse | Copy Code
public class CommSetting{ public static int Comm_Port=0; public static Int64 Comm_BaudRate=0; public static Int64 Comm_TimeOut=0; public static GsmCommMain comm;
public CommSetting() { // // TODO: Add constructor logic here // }}
Comm is an object of type GsmCommMain which is required for sending and receiving messages. We have toset the Comm port, Baud rate and time out for our comm object of type GsmCommMain. Then try to openwith the above settings. We can test the Comm port settings by clicking on the Test button after selectingthe Comm port, baud rate and Time out. Sometimes if the comm port is unable to open, you will get a
4.88 (86 votes)Like 58
4 TweetTweet 1
articles
converted by Web2PDFConvert.com
on Windows mobile
Server pinger and SMS reportervia GSM Modem ATCOMMAND
Serial Communication in C#
How to send SMS using Javawith a HSDPA Dongle.
Using VB.NET to Decode PDUstring
message "No phone connected". This is mainly due to Baud rate settings. Change the baud rate and checkagain by clicking the Test button until you get a message "Successfully connected to the phone."
Before creating a GSMComm object with settings, we need to validate the port number, baud rate andTimeout.
The EnterNewSettings() does validation, returns true if valid, and will invokeSetData(port,baud,timeout) for comm setting.
The following block of code will try to connect. If any problem occurs "Phone not connected" messageappears and you can either retry by clicking on the Retry button or else Cancel.
Co llapse | Copy Code
GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);try{ comm.Open(); while (!comm.IsConnected()) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "No phone connected.", "Connection setup", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { comm.Close(); return; } Cursor.Current = Cursors.WaitCursor; }
// Close Comm port connection (Since it's just for testing // connection) comm.Close();}catch(Exception ex){ MessageBox.Show(this, "Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;}
// display message if connection is a success.MessageBox.Show(this, "Successfully connected to the phone.","Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
2) Receive Incoming Message
We are going to register the following events for GSMComm object comm.
1. PhoneConnectedThis event is invoked when you try to open the Comm port. The event handler for Phoneconnected is comm_PhoneConnected which will invoke OnPhoneConnectionChange(boolconnected) with the help of Delegate ConnectedHandler.
2. MessageReceivedThis event is invoked when a message arrives at the GSM phone. We will register withMessageReceivedEventHandler. When the incoming message arrives, thecomm_MessageReceived method will be invoked which in turn calls the MessageReceived()method in order to process the unread message. GSMComm object comm has a methodReadMessages which will be used for reading messages. It accepts the following parameters phonestatus (All, ReceivedRead, ReceivedUnread, StoredSent, and StoredUnsent) and storagetype: SIM memory or Phone memory.
Co llapse | Copy Code
private void MessageReceived(){ Cursor.Current = Cursors.WaitCursor; string storage = GetMessageStorage(); DecodedShortMessage[] messages = CommSetting.comm.ReadMessages (PhoneMessageStatus.ReceivedUnread, storage); foreach(DecodedShortMessage message in messages) { Output(string.Format("Message status = {0}, Location = {1}/{2}", StatusToString(message.Status), message.Storage, message.Index)); ShowMessage(message.Data); Output(""); }
Output(string.Format("{0,9} messages read.", messages.Length.ToString())); Output("");}
The above code will read all unread messages from SIM memory. The method ShowMessage is used fordisplaying the read message. The message may be a status report, stored message sent/un sent, or areceived message.
3) Send Message
converted by Web2PDFConvert.com
You can send an SMS by keying in the destination phone number and text message.
If you want to send a message in your native language (Unicode), you need to check in Send asUnicode(UCS2). GSMComm object comm has a SendMessage method which will be used for sending SMS toany phone. Create a PDU for sending messages. We can create a PDU in straight forward version as:
Co llapse | Copy Code
SmsSubmitPdu pdu = new SmsSubmitPdu (txt_message.Text,txt_destination_numbers.Text,"");
An extended version of PDU is used when you are sending a message in Unicode.
Co llapse | Copy Code
try{ // Send an SMS message SmsSubmitPdu pdu; bool alert = chkAlert.Checked; bool unicode = chkUnicode.Checked;
if (!alert && !unicode) { // The straightforward version pdu = new SmsSubmitPdu (txt_message.Text, txt_destination_numbers.Text,""); } else { // The extended version with dcs byte dcs; if (!alert && unicode) dcs = DataCodingScheme.NoClass_16Bit; else if (alert && !unicode) dcs = DataCodingScheme.Class0_7Bit; else if (alert && unicode) dcs = DataCodingScheme.Class0_16Bit; else dcs = DataCodingScheme.NoClass_7Bit;
pdu = new SmsSubmitPdu (txt_message.Text, txt_destination_numbers.Text, "", dcs); }
// Send the same message multiple times if this is set int times = chkMultipleTimes.Checked ? int.Parse(txtSendTimes.Text) : 1;
// Send the message the specified number of times for (int i=0;i<times;i++) { CommSetting.comm.SendMessage(pdu); Output("Message {0} of {1} sent.", i+1, times); Output(""); }}catch(Exception ex){ MessageBox.Show(ex.Message);}
Cursor.Current = Cursors.Default;
4) Read All Messages
converted by Web2PDFConvert.com
You can read all messages from the phone memory of SIM memory. Just click on "Read All Messages"button. The message details such as sender, date-time, text message will be displayed on the Data Grid.Create a new row for each read message, add to Data table and assign the Data table to datagrid's source
Co llapse | Copy Code
private void BindGrid(SmsPdu pdu){ DataRow dr=dt.NewRow(); SmsDeliverPdu data = (SmsDeliverPdu)pdu;
dr[0]=data.OriginatingAddress.ToString(); dr[1]=data.SCTimestamp.ToString(); dr[2]=data.UserDataText; dt.Rows.Add(dr);
dataGrid1.DataSource=dt;}
The above code will read all unread messages from SIM memory. The method ShowMessage is used fordisplaying the read message. The message may be a status report, stored message sent/un sent, or areceived message. The only change in processing Received message and Read message is the firstparameter.
For received message
Co llapse | Copy Code
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, storage);
For read all messages
Co llapse | Copy Code
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
5) Delete Messages (One or All)
All messages which are sent by the users will be stored in SIM memory and we are going to display themin the Data grid. We can delete a single message by specifying the message index number. We can deleteall messages from SIM memory by clicking on "Delete All" button. Messages are deleted based on theindex. Every message will be stored in memory with a unique index.
The following code will delete a message based on index:
Co llapse | Copy Code
// Delete the message with the specified index from storageCommSetting.comm.DeleteMessage(index, storage);
To delete all messages from memory( SIM/Phone)
Co llapse | Copy Code
// Delete all messages from phone memoryCommSetting.comm.DeleteMessages(DeleteScope.All, storage);
converted by Web2PDFConvert.com
Ranjan.DWeb Developer United States
Profile Around 8 years of professional software development experience in analysis, design, development,testing and implementation of enterprise web applications for healthcare domain with goodexposure to object-oriented design, software architectures, design patterns, test-drivendevelopment and agile practices. In Brief Analyse and create High Level , Detailed Design documents. Use UML Modelling and create Use Cases , Class Diagram , Component Model , DeploymentDiagram, Sequence Diagram in HLD. Area of Working : Dedicated to Microsoft .NET Technologies
The DeleteScope is an Enum which contains:
1. All2. Read3. ReadAndSent4. ReadSentAndUnsent
ApplicationsHere are some interesting applications where you can use and modify this software.
1) Pre paid Electricity
Scenario (Customer)
The customer has agreed for pre paid electricity recharges with the help of recharge coupons. The couponis made available at shops. The customer will first buy the coupons from shops; every coupon consists ofCoupon PIN which will be masked, the customer needs to scratch to view the PIN number. The customerwill send an SMS to the SMS Server with a specified message format for recharging.
Message Format for Recharging:RECHARGE <Coupon No> <Customer ID>
Scenario (Server Database)
On the Server, the Database consists of Customer information along with his telephone number, there willa field named Amount which will be used and updated when the customer recharged with some amount.This application becomes somewhat complex, an automatic meter reading software along with hardwareneeds to be integrated with this. Automatic meter reading systems will read all meter readings andcalculate the amount to be deducted for the customer.
2) Astrology
You can implement as astrology software. The user will send an SMS with his zodiac sign. The SMS serverwill maintain an Astrology Database with zodiac sign and a text description which contains a message forthe day. The Database is required to be updated daily for all zodiac signs.
Message Format which will be used by the user to get message of the day:Zodiac Sign
3) Remote Controlling System
We can implement a remote controlling system, for example you need to:
1. Shutdown2. Restart3. Log off system
You can send an SMS. The SMS server will listen and then process the message. Based on the messageformat sent by the user we can take action. Example if message format is: SHUTDOWN Send to SMS phone number.
ConclusionThis project wouldn't be completed unless I thank the GSMComm Lib developer "Stefan Mayr". I customizedmy application using this Library. You can download the sample project, library from the web link which Iprovided under the Reference section.
Referencehttp://www.scampers.org/steve/sms/index.htm
LicenseThis article, along with any associated source code and files, is licensed under The Apache License, Version2.0
About the Author
converted by Web2PDFConvert.com
Permalin k | Advertise | Privacy | Mob ile W eb02 | 2.6.1309030.1 | Last U pdated 10 Sep2007
Article Copyrigh t 2007 by Ran jan .DEver yth in g else Copyrigh t © CodePro ject, 1999-2013
Terms o f U se
Layou t: f ixed | f lu id
Experience with : C# , J2EE , J2ME, Windows Phone 8, Windows Store AppProficient in: C# , XML , XHTML, XML, HTML5, Javascript, Jquery, CSS, SQL, LINQ Software Development Database: Microsoft SQL Server, FoxProDevelopment Frameworks: Microsoft .NET 1.1, 2.0, 3.5, 4.5UI: Windows Forms, Windows Presentation Foundation, ASP.NET Web Forms and ASP.NET MVC3,MVC4Coding: WinForm , Web Development, Windows Phone, WinRT Programming Healthcare Domain Experience CCD, CCR, QRDA, HIE, HL7 V3, Healthcare Interoperability Others: TTD, BDD Education B.E (Computer Science) CodeProject Contest So Far: 1. Windows Azure Developer Contest - HealthReunion - A Windows Azure based healthcareproduct , link - http://www.codeproject.com/Articles/582535/HealthReunion-A-Windows-Azure-based-healthcare-pro 2. DnB Developer Contest - DNB Business Lookup and Analytics , link -http://www.codeproject.com/Articles/618344/DNB-Business-Lookup-and-Analytics 3. Intel Ultrabook Contest - Journey from development, code signing to publishing my App toIntel AppUp , link - http://www.codeproject.com/Articles/517482/Journey-from-development-code-signing-to-publishin
Article Top
Search this forum Go
Comments and Discussions
You must Sign In to use this message board.
Profile popups Spacing Relaxed Noise Ver y High Layout Normal Per page
10 Update
First Prev Next
ahmadomar 29-Sep-13 1:54
dushman40 5-Sep-13 3:16
Member 10220821 31-Aug-13 23:47
Ranjan.D 2-Sep-13 0:43
Member 10220821 2-Sep-13 1:16
Ravi Kumar 12-Aug-13 2:01
almofi 28-Jul-13 7:12
KanavKathuria 11-Jul-13 21:55
SoftMise 7-Jul-13 5:38
Le@rner 2-May-13 1:45
Last Visit: 31-Dec-99 18:00 Last Update: 3-Oct-13 7:21 Refresh 1 2 3 4 5 6 7 8 9 10 11 Next »
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Message service error 500 occurred - Error Pin
make a voice call with dongle
comment
Re: comment
Re: comment
Error
vb.net
error
message service error 331
CMS error 500
converted by Web2PDFConvert.com