why does select syscall returns evenif no data in serial port buffer

Discussion in 'C Programming' started by alok, Jun 18, 2007.

  1. alok

    alok Guest

    Hi

    I have opened a serial port and then blocked on a select system call .
    but select returns even if no data is comming from other end. So when
    I read the buffer after select returns, I only found 0s nad this
    continues . So the problem is select returns even if there is no data
    in serial port buffer.

    void main()
    {
    int fd_uart =-1 ;
    int retval,cErr;
    fd_set read_fds;
    int max_fd = 0;

    /* intialize the data set */
    if( fd_uart = open("/dev/ttyS0", O_RDWR | O_NOCTTY ) == -1)
    {
    exit(0);
    }

    FD_ZERO( &read_fds );
    FD_SET(fd_uart, &read_fds );
    max_fd = fd_uart;

    while(1)

    {
    select( max_fd + 1, &read_fds, 0, 0, NULL);
    printf("\nData\n");
    }


    }
     
    alok, Jun 18, 2007
    #1
    1. Advertising

  2. In article <>,
    alok <> wrote:

    >I have opened a serial port and then blocked on a select system call .


    You need to ask this on a unix newsgroup.

    >but select returns even if no data is comming from other end. So when
    >I read the buffer after select returns, I only found 0s nad this
    >continues .


    But I notice you don't test the return value from select(), and you
    seem to think that the buffer should be changed after select() returns,
    but in fact select() only tells you whether a read() would return
    immediately - it doesn't read any data itself.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Jun 18, 2007
    #2
    1. Advertising

  3. alok <> writes:

    > Hi
    >
    > I have opened a serial port and then blocked on a select system call.


    Wrong group. I happen to have spotted what is wrong and will mail you
    a reply (I don't read any of the right groups!).

    --
    Ben.
     
    Ben Bacarisse, Jun 18, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,250
    Smokey Grindel
    Dec 2, 2006
  2. Pom
    Replies:
    2
    Views:
    1,796
    Bas-i
    Jan 31, 2007
  3. Wills

    buffer size of serial port

    Wills, Sep 20, 2007, in forum: Java
    Replies:
    3
    Views:
    850
    Knute Johnson
    Sep 26, 2007
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    674
    David A. Black
    Jul 2, 2008
  5. msalerno
    Replies:
    3
    Views:
    442
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page