Altera_Forum
Honored Contributor
21 years agouart nonblocking
How can I do nonblocking io with uart
I have a singlethread enviroment and need nonblocking io for uart I tried the following code, but it does not work correctly int fd; fd = open("/dev/uart_0", O_RDWR | O_NONBLOCK); while(1) { res=read(fd,test,25); // res=fgets(test,25,fd); // res=fread(test,1,25,fd); if(res>0) { for(i=0;i<res;i++) { if(test=='\r') {*prxbuff=0;
printf("rx:count:%d:<%s>\r\n",rxcount,rxbuff);
rxcount=0;
prxbuff=rxbuff;
}
else {
*prxbuff++=test; rxcount++; } } } Sorry I´ve forgot to append the output of the code. the output of the above code is sometimes missing some characters, however the uart works correct, echo of uart is ok. output in terminal: TestRS232 RX:COUNT:8:<TesRS232> TestRS232 RX:COUNT:9:<TestRS232> TestRS232 RX:COUNT:7:<estRS32> TestRS232 RX:COUNT:8:<TestR232> TestRS232 RX:COUNT:8:<TestS232> TestRS232 RX:COUNT:9:<TestRS232> TestRS232 RX:COUNT:8:<TestRS22> TestRS232 RX:COUNT:8:<TestR232> TestRS232 RX:COUNT:7:<TstRS22> TestRS232 RX:COUNT:7:<TstRS22> TestRS232 RX:COUNT:8:<TesRS232> TestRS232 RX:COUNT:8:<TesRS232>