In my application I send some AT commands to a modem and expect to get a response. The response is composed of the echo of the command + OK. To read the response out of the tty I use read().
after opening a tty port as nonblocking I would expect that read() returns with -1 and EAGAIN==errno if after sending some bytes the response is not yet available. However it returns with 0.
If I use select() to trigger read(), it reads some bytes and returns with the number of read bytes as expected. However if I call read() the second time to get the rest of the response it returns 0 and and writs nothing in to the buffer.
could somebody tell me whats wrong?
fd_1 = open("/dev/ttyBF1", O_RDWR | O_NOCTTY | O_NONBLOCK);
n = read(fd_1,rx, 20);
printf( "\n,%d,received_bytes\n", n ); <--returns 0 thats correct
n = send2tty(fd_1,SELINT_2); //send command to modem
n = read(fd_1,rx, 20); //response not yet available therefor -1 and EAGAIN (what I would expect ...)
printf( "\n,%d,-received_bytes\n", n ); //but it returns 0 ????
n = read(fd_1,rx, 20); //response is now in the buffer
printf( "\n,%d,-received_bytes\n", n ); //response read completely
n = read(fd_1,rx, 20); //buffer again empty read() returns 0 OK
printf( "\n,%d,-received_bytes\n", n );