Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Can 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;
     
}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1. print errno. It will say what happening.

    2. Show

    ls -l /dev/ttyS0

    Maybe you have no ttyS0 or you have not permission.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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