Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
http://imageshack.com/a/img22/7094/iw4j.jpg

I want to send and receive SMS from mobile to mobile using C# application. Mobile must connect to computer using USB port.

If any one can help me please please help me and send me sample project.
Posted
Updated 20-Feb-14 5:58am
v2

1 solution

C#
<pre><pre lang="css">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<ShortMessage>
   {
   }









#region Read SMS

        public AutoResetEvent receiveNow;

        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;

        }
        public ShortMessageCollection ParseMessages(string input)
        {
            ShortMessageCollection messages = new ShortMessageCollection();
            try
            {
                Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
                Match m = r.Match(input);
                while (m.Success)
                {
                    ShortMessage msg = new ShortMessage();
                    //msg.Index = int.Parse(m.Groups[1].Value);
                    msg.Index = m.Groups[1].Value;
                    msg.Status = m.Groups[2].Value;
                    msg.Sender = m.Groups[3].Value;
                    msg.Alphabet = m.Groups[4].Value;
                    msg.Sent = m.Groups[5].Value;
                    msg.Message = m.Groups[6].Value;
                    messages.Add(msg);

                    m = m.NextMatch();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return messages;
        }

        #endregion
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900