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

This is a discussion on why does select syscall returns evenif no data in serial port buffer - Unix ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

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

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

    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");
    }


    }


  2. Re: why does select syscall returns evenif no data in serial port buffer

    In article <1182166240.058906.274220@z28g2000prd.googlegroups. com>,
    alok wrote:

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


    Is read() returning 0? That means EOF, and it will cause select() to
    return.

    >
    > 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");
    > }
    >
    >
    > }


    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  3. Re: why does select syscall returns evenif no data in serial port buffer

    On Jun 19, 5:33 am, Barry Margolin wrote:
    > In article <1182166240.058906.274...@z28g2000prd.googlegroups. com>,
    >
    > alok wrote:
    > > 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.

    >
    > Is read() returning 0? That means EOF, and it will cause select() to
    > return.
    >
    >
    >
    >
    >
    > > 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");
    > > }

    >
    > > }

    >
    > --
    > Barry Margolin, bar...@alum.mit.edu
    > Arlington, MA
    > *** PLEASE post questions in newsgroups, not directly to me ***
    > *** PLEASE don't copy me on replies, I'll read them in the group ***


    No read returns number of 0s in buffer . So when every time select
    returns and reads the buffer, it found some number of 0s even if this
    system is not connected .


  4. Re: why does select syscall returns evenif no data in serial port buffer

    In article <1182227238.026800.9090@e9g2000prf.googlegroups.com>,
    alok wrote:

    > On Jun 19, 5:33 am, Barry Margolin wrote:
    > > In article <1182166240.058906.274...@z28g2000prd.googlegroups. com>,
    > >
    > > alok wrote:
    > > > 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.

    > >
    > > Is read() returning 0? That means EOF, and it will cause select() to
    > > return.
    > >
    > >
    > >
    > >
    > >
    > > > 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");
    > > > }

    > >
    > > > }

    > >
    > > --
    > > Barry Margolin, bar...@alum.mit.edu
    > > Arlington, MA
    > > *** PLEASE post questions in newsgroups, not directly to me ***
    > > *** PLEASE don't copy me on replies, I'll read them in the group ***

    >
    > No read returns number of 0s in buffer . So when every time select
    > returns and reads the buffer, it found some number of 0s even if this
    > system is not connected .


    Someone else responded to your duplicate post in comp.unix.programmer.
    See his comments on the mistakes in your code.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread