Forum Discussion
Altera_Forum
Honored Contributor
15 years ago#include <string.h># include <unistd.h># include <fcntl.h># include <errno.h># include <termios.h>
int main(void)
{
char buf;
int fd1;
volatile int count;
fd1 = open("/dev/urandom", O_RDWR | O_NOCTTY | O_NDELAY); //urandom for test.
if (fd1 == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
exit(1);
}
fcntl(fd1, F_SETFL, FNDELAY);
for(count = 0; count < 65556; count ++); // delay //it will be delay if count is volatile. And it's a bad way to set delay.
if(count = read(fd1, buf, 10) < 0)
{
perror("reading failed ");
exit(2);
}
printf("%s", buf);
close(fd1);
return 0;
}
~ And 65556 is very short delay.