Forum Discussion
Altera_Forum
Honored Contributor
16 years ago"Resource temporarily unavailable" while reading from "dev/ttyS0"
Hi all, i have ported uClinux on DE2 2c35 board and i want to use RS232 port on the board to communicate with a PC. I understand that I can use "dev/ttyS0" for that purpose. I can open and write ...
Altera_Forum
Honored Contributor
16 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.