Read sms using serial port communication in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Read sms using serial port communication in c#

    I want to read sms from GSM modem using C# in serial communication. I wrote the code. But i want to do it automatically. I put my code here and please tell me how can i do it automatically.

    [PHP] public partial class SMS : Form
    {

    //create an Serial Port object
    SerialPort sp = new SerialPort();

    public SMS()
    {
    InitializeCompo nent();
    }

    private void Form1_Load(obje ct sender, EventArgs e)
    {

    }

    private void btnStart_Click( object sender, EventArgs e)
    {
    sp.BaudRate = 19200;


    try
    {
    //Open serial port
    sp.PortName = "COM1";
    sp.Open();

    }
    catch (System.Excepti on ex)
    {
    lblError.Text = ex.Message;
    }
    }

    private void btnWrite_Click( object sender, EventArgs e)
    {

    try
    {

    //Write line to serial port
    sp.WriteLine(te xSms.Text + "\r");
    texSms.Text = "";
    sp.DiscardInBuf fer();

    }
    catch(System.Ex ception ex)
    {
    lblError.Text = ex.Message;
    }

    //Set time delay
    //System.Threadin g.Thread.Sleep( 30);
    // sp.WriteTimeout = 200;


    }



    private void btnRead_Click(o bject sender, EventArgs e)
    {
    try
    {
    //Cler text box

    //Read serial port and displayed the data in text box
    texSms.Text = sp.ReadLine();
    //sp.Write("Conne cted" + "\n");

    }
    catch (System.Excepti on ex)
    {
    lblError.Text = ex.Message;
    }

    }


    private void SMS_formClosing (object sender, FormClosingEven tArgs e)
    {
    MessageBox.Show ("Do u want to Close the App");
    sp.Close();
    }

    private void btnStop_Click(o bject sender, EventArgs e)
    {
    texSms.Text = "";
    sp.Close();
    }


    }[/PHP]
Working...