471,120 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

Read sms using serial port communication in c#

250 100+
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()
{
InitializeComponent();
}

private void Form1_Load(object 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.Exception ex)
{
lblError.Text = ex.Message;
}
}

private void btnWrite_Click(object sender, EventArgs e)
{

try
{

//Write line to serial port
sp.WriteLine(texSms.Text + "\r");
texSms.Text = "";
sp.DiscardInBuffer();

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

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


}



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

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

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

}


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

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


}[/PHP]
May 9 '08 #1
0 4354

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by collinm | last post: by
3 posts views Thread by collinm | last post: by
7 posts views Thread by Michael Chong | last post: by
6 posts views Thread by Casey Bralla | last post: by
15 posts views Thread by xkenneth | last post: by
4 posts views Thread by rowan | last post: by
4 posts views Thread by Adrian Chen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.