Altera_Forum
Honored Contributor
15 years agoCan not read from "dev/ttyS0"
Hi all,
I have ported uClinux onto an DE2 2C35 board and i want to communicate with my PC using the RS232 port. I can open and write data to "dev/ttyS0" well. But I can't read from "dev/ttyS0" by using read or fread functions. :confused: Can u guys tell me how to solve this problem? Thanks for reading :):) here's my 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 - ");
}
while(count = read(fd1, buf, 10) > 0)
printrf("%s", buf);
close(fd1);
return 0;
}