For asynchronous data I generally create a timer to test if there is still data comiing in.
The method below uses two counters, when one counter stops incrementing form comm events and the timer is called, a second coounter starts to increment. When the second counter hits 10 or 1 second for the example below I set a boolean to let the application know there is no data coming in.
private void startComTimer()
{
tmrCOM.Interval = 100;
tmrCOM.Enabled = true;
}
...
try
{
serialPort.Open();
PortOpen = true;
comError = false;
}
catch (IOException)
{
comError = true;
PortOpen = false;
}
...
void _serialComm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
...
COMcnt_1++;
COMcnt_2 = 0;
...
datGood = true;
...
}
private void tmrCOM_Tick(object sender, EventArgs e)
{
if (PortOpen)
{
if (COMcnt_1 == lastCOMcnt)
{
COMcnt_2++;
}
lastCOMcnt = COMcnt_1;
if (COMcnt_2 >= 10)
{
datGood = false;
}
}
else
{
datGood = false;
}
}
Good Luck.