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]