Forum Discussion
Altera_Forum
Honored Contributor
15 years agothanks for replying Mr actris, I have solved that problem by updating to nios2-linux 2009 version. I can open and write data to "dev/ttyS0" well.
But I encounter another problem now. I can't read from "dev/ttyS0" by using read or fread functions. :( 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, fd2, count;
fd1 = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
fd2 = open("/mnt/SD/t.txt",O_WRONLY);
if (fd1 == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
while(count = read(fd1, buf, 10) > 0)
write(fd2, buf, 10);
close(fd1);
close(fd2);
//return (fd);
}