Altera_Forum
Honored Contributor
15 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 data to PC by using write function. But the problem is I can't read from "dev/ttyS0". Every time I use read function, I get "Resource temporarily unavailable". Can u guys tell me how to solve this problem? anyways, I enabled both "Altera JTARG UART support" and "Altera UART support". Was I wrong? here my C code:
# include <string.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# include <termios.h>
int main(void)
{
char buf;
int fd1, count;
fd1 = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd1 == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
exit(1);
}
fcntl(fd, F_SETFL, FNDELAY);
for(count = 0; count < 65556; count ++); // delay
if(count = read(fd1, buf, 10) < 0)
{
perror("reading failed ");
exit(2);
}
fprintf(stdout, "%s", buf);
close(fd1);
return 0;
}