AnsweredAssumed Answered

read() function

Question asked by feucom on Sep 2, 2012
Latest reply on Sep 18, 2012 by feucom

Hi,

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?

thanks

ralph

 

 

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 ????

 

    sleep(1);

    n = read(fd_1,rx, 20);                              //response is now in the buffer

    printf( "\n,%d,-received_bytes\n", n );     //response read completely

 

    sleep(2);

    n = read(fd_1,rx, 20);                              //buffer again empty read() returns 0  OK

    printf( "\n,%d,-received_bytes\n", n );

 

    close(fd_1);

Outcomes