By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

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

P: n/a
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");
}
}

Jun 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <11**********************@o11g2000prd.googlegroups .com>,
alok <al******@gmail.comwrote:
>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.
Jun 18 '07 #2

P: n/a
alok <al******@gmail.comwrites:
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.
Jun 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.