Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Can not read from "dev/ttyS0"

Altera_Forum
Honored Contributor II
1,186 Views

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; }
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
425 Views

1. print errno. It will say what happening.  

2. Show  

ls -l /dev/ttyS0 

Maybe you have no ttyS0 or you have not permission.
0 Kudos
Altera_Forum
Honored Contributor II
425 Views

the read function always returns to -1 and it tells " Resource temporarily unavailable". i really don't know why, :(

0 Kudos
Reply