I am new to C and Linux. I am trying to read some data from the serial port by using the read()
system call, and it is working fine. Problem is that read()
is not returning a negative value even if I unplug the serial cable while the code is running.Please help
Please feel free to ask if the scenario is not clear.Thanks for your time
Edit: It returns a Zero when I unplug the cable.
char cBuff[100];
buffptr = cBuff;
while (( nbytes = read(fd, buffptr, cBuff + sizeof(cBuff) - buffptr - 1)) > 0)
{
//Do something
}
if(nbytes < 0 )
{
perror("Serial Read Thread ERROR:");
}
else if(nbytes >= 0 )
{
//Do something
}