I have a serial device connected to my PI that I read data from it... everything is good , but sometime the cable move or the serial device is unplug.
then the
line = r.readLine();
get stuck
I have try to overcome this problem by:
BufferedReader r = new BufferedReader (newnputStreamReader(p.getInputStream()));
try
{
line = r.readLine();
if (line.length() == 0)
{
logfile.append("problem");
logfile.close();
System.out.println("Problem");
TimeUnit.SECONDS.sleep(5);
break;
}
}
catch (IOException e)
{
logfile.append(line);
logfile.close();
}
but it doens't do nothing (because I geuss he is still waiting for data) not even throw an exception how can I make him say I have a problem ? maybe to use a timer or something like this ? if no data for 5 seconds ?
Thanks ,