serial port getting stuck at read() data
<p>I have connected an HC-05 bluetooth module to microZed board and trying to send and receive data via uart in Linux, Now the the send code is working when I send data from my board to the app it works perfectly given below is my code for sending</p>

<pre><code>#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;assert.h&gt;
#include &lt;pthread.h&gt; /* for threads */
#include &lt;termios.h&gt; /* uart */
#include &lt;fcntl.h&gt; /* uart */
#include &lt;unistd.h&gt; /* uart */
#define MODEMDEVICE "/dev/ttyPS1"
int main()
{
 printf("Opening %s\n", MODEMDEVICE);
 int portfd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
 if (portfd &lt; 0) {
 printf("ERROR coultn't open %s\n", MODEMDEVICE);
 return -1;
 }
 /* set terminal settings */
 struct termios tty;
 tcgetattr(portfd, &amp;tty);

 cfsetospeed(&amp;tty, (speed_t)B9600);
 cfsetispeed(&amp;tty, (speed_t)B9600);
 tty.c_cflag = (tty.c_cflag &amp; ~CSIZE) | CS8;
 tty.c_iflag = IGNBRK;
 tty.c_lflag = ICANON;
 tty.c_oflag = 0;
 tty.c_cflag |= CLOCAL | CREAD;
 tty.c_cc[VTIME] = 0;
 tty.c_cc[VMIN] = 1;
 tty.c_iflag &amp;= ~(IXON | IXOFF | IXANY);
 tty.c_cflag &amp;= ~(PARENB | PARODD);
 tty.c_cflag |= PARENB;
 tty.c_cflag &amp;= ~CSTOPB;
 tcsetattr(portfd, TCSANOW, &amp;tty);
 /* sleep a bit */
 usleep(200000);
 /* flush possible characters in the input buffer */
 tcflush(portfd, TCIOFLUSH);
 char buf;

 int i;

 while(1) {

    buf++;
    write(portfd, &amp;buf, 1);
    write(portfd, "\r\n", 2);
    usleep(200000);

 }
 return 0;
}
</code></pre>

<p>Now the problem arises when I try send data from the app to the Bluetooth module , sometimes the program stops and says "random nonblocking pool initialized" or it gets stuck at <code>i = read(portfd, buf, 20);</code> in the code given below</p>

<pre><code>#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;assert.h&gt;
#include &lt;pthread.h&gt; /* for threads */
#include &lt;termios.h&gt; /* uart */
#include &lt;fcntl.h&gt; /* uart */
#include &lt;unistd.h&gt; /* uart */
#define MODEMDEVICE "/dev/ttyPS1"
int main()
{
 printf("Opening %s\n", MODEMDEVICE);
 int portfd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
 if (portfd &lt; 0) {
 printf("ERROR coultn't open %s\n", MODEMDEVICE);
 return -1;
 }

    printf("hello1\n\r");
 /* set terminal settings */
 struct termios tty;
 tcgetattr(portfd, &amp;tty);

 cfsetospeed(&amp;tty, (speed_t)B9600);
 cfsetispeed(&amp;tty, (speed_t)B9600);
 tty.c_cflag = (tty.c_cflag &amp; ~CSIZE) | CS8;
 tty.c_iflag = IGNBRK;
 tty.c_lflag = ICANON;
 tty.c_oflag = 0;
 tty.c_cflag |= CLOCAL | CREAD;
 tty.c_cc[VTIME] = 0;
 tty.c_cc[VMIN] = 1;
 tty.c_iflag &amp;= ~(IXON | IXOFF | IXANY);
 tty.c_cflag &amp;= ~(PARENB | PARODD);
 tty.c_cflag |= PARENB;
 tty.c_cflag &amp;= ~CSTOPB;
 tcsetattr(portfd, TCSANOW, &amp;tty);
 /* sleep a bit */
    printf("hello2\n\r");
 usleep(200000);
 /* flush possible characters in the input buffer */
 tcflush(portfd, TCIOFLUSH);
 char buf[20];
        printf("hello3\n\r");
 int i;

 while(1) {
    i = read(portfd, buf, 20); 
        printf("hello\n\r");

    buf[i] = 0;
    printf("%s", buf);
    printf("\n\r");

 }
 return 0;
}
</code></pre>

<p>Any suggestions how can I fix this ?</p>