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

A

alok

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


}
 
R

Richard Tobin

alok said:
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
 
B

Ben Bacarisse

alok said:
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!).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top