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++
12600 Discussions

"Resource temporarily unavailable" while reading from "dev/ttyS0"

Altera_Forum
Honored Contributor II
5,898 Views

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

You can send data to UART with  

ls > /dev/ttyS0 

Or  

cat "any_file" > /dev/ttyS0
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

yes, i was successful using cat application and write function to send data through "/dev/ttyS0" but i can not read data using read function

0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

#include <string.h># include <unistd.h># include <fcntl.h># include <errno.h># include <termios.h> int main(void) { char buf; int fd1; volatile int count; fd1 = open("/dev/urandom", O_RDWR | O_NOCTTY | O_NDELAY); //urandom for test. if (fd1 == -1) { perror("open_port: Unable to open /dev/ttyS0 - "); exit(1); } fcntl(fd1, F_SETFL, FNDELAY); for(count = 0; count < 65556; count ++); // delay //it will be delay if count is volatile. And it's a bad way to set delay. if(count = read(fd1, buf, 10) < 0) { perror("reading failed "); exit(2); } printf("%s", buf); close(fd1); return 0; } ~  

 

And 65556 is very short delay.
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

Hi ARTEM_BOND,  

thanks for replying! 

I know using delay is a bad way. Can u plz tell me another way to wait data from the host? 

I tried fcntl(fd1, F_SETFL, 0);, but i had to a long time without receive any data.
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

 

--- Quote Start ---  

Hi ARTEM_BOND,  

thanks for replying! 

I know using delay is a bad way. Can u plz tell me another way to wait data from the host? 

I tried fcntl(fd1, F_SETFL, 0);, but i had to a long time without receive any data. 

--- Quote End ---  

 

Set timeout.  

 

http://linux.die.net/man/2/select 

http://www.linux.org/docs/ldp/howto/serial-programming-howto/x115.html 

 

Also you can make you own module (driver) for UART. And write you own UART with hardware time-out timer on Verilog.
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

hi ARTEM_BOND, 

thanks for ur instructions!  

I have set the timeout and wait for a long time. But but I still got no data. specially, every time i try to get data sent from the host by using read function or cat application, both rxd and txd leds on de2 board flash concurrently. I really do not understand the reason. I do not send data from the board.:confused:
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

thanks for replying and reading everybody,  

I finally solved this problem by the instructions in this link: http://www.linux.org/docs/ldp/howto/serial-programming-howto/x115.html
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

 

--- Quote Start ---  

thanks for replying and reading everybody,  

I finally solved this problem by the instructions in this link: http://www.linux.org/docs/ldp/howto/serial-programming-howto/x115.html 

--- Quote End ---  

 

 

Dear Nguyen, The website you told us you found in it instructions to solve this problem does not exist anymore. Would you like please tell us how you solved this problem because I have the same problem in linux ubuntu 12.04. 

 

Thank you, Rachid
0 Kudos
Altera_Forum
Honored Contributor II
2,837 Views

 

--- Quote Start ---  

thanks for replying and reading everybody,  

I finally solved this problem by the instructions in this link: http://www.linux.org/docs/ldp/howto/serial-programming-howto/x115.html 

--- Quote End ---  

 

 

Dear Nguyen, Would you like please tell us how you cured the problem as the link you mentioned where you found in it the instructions to solve the problem does not exist anymore. 

 

Thank you, Rachid
0 Kudos
Reply