I've developed a simple windows form application in c# which is used to send and receive data using serial ports. but when I click my READ button while there is no device connected, the whole application stops working an I have to close it with force! so I need a method to recognize whether a device is connected or not before I click on READ button. please help me get through it.
private void button2_Click(object sender, EventArgs e)
{
try
{
textBox2.Text = serialPort1.ReadLine();
}
catch (TimeoutException)
{
textBox2.Text = "Timeout Exception";
}
}