Some times serial port read giving converted values [ Junk values]
<p>configuring the serial port is given below</p>

<pre><code>// open serial port
/*  O_RDWR means that the port is opened for both reading and writing
 *  O_NOCTTY means that no terminal will control the process opening the serial port
 */
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY ); // /dev/ttyS1
if (fd &lt;0)
    perror(MODEMDEVICE);

tcgetattr(fd,&amp;SerialPortSettings); /* save current serial port settings */

/* Set Baud Rate */
cfsetospeed (&amp;SerialPortSettings, (speed_t)B230400);
cfsetispeed (&amp;SerialPortSettings, (speed_t)B230400);

SerialPortSettings.c_iflag &amp;= ~IGNBRK;         // disable break processing
SerialPortSettings.c_lflag = 0;                // no signaling chars, no echo, no canonical processing
SerialPortSettings.c_oflag = 0;                // no remapping, no delays

/* Setting other Port Stuff */
SerialPortSettings.c_cflag     &amp;=  ~PARENB;              /* No Parity            */
SerialPortSettings.c_cflag     &amp;=  ~CSTOPB;              /* Stop bits = 1         */
SerialPortSettings.c_cflag     &amp;=  ~CSIZE;               /* Clears the Mask       */
SerialPortSettings.c_cflag     |=  CS8;                  /* Set the data bits = 8 */

SerialPortSettings.c_cflag     &amp;=  ~CRTSCTS;           /* Turn off hardware based flow control */
SerialPortSettings.c_cc[VMIN]   =  0;                  // read doesn't block // specifies the minimum number of characters that should be read before the read() call returns
SerialPortSettings.c_cc[VTIME]  =  10;                 // 1 seconds read timeout
SerialPortSettings.c_cflag     |=  CREAD | CLOCAL;     /* Turn on the receiver of the serial port */
SerialPortSettings.c_iflag &amp;= ~(IXON | IXOFF | IXANY); /* Turn off software based flow control  */


tcsetattr ( fd, TCSANOW, &amp;SerialPortSettings ); //TCSANOW tells to make the changes now without waiting
</code></pre>

<p>below given the expected output, which is coming 5 in 3-4 times </p>

<pre><code>14-Jun-16 15:41:32.300 [RX] - :010400000036C5&lt;CR&gt;&lt;LF&gt;
14-Jun-16 15:41:32.316 [TX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5&lt;CR&gt;&lt;LF&gt;
14-Jun-16 15:41:32.341 [RX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5&lt;CR&gt;&lt;LF&gt;
</code></pre>

<p>below is the output which I am getting 1 time in every 5 times</p>

<pre><code>14-Jun-16 15:41:32.596 [RX] - :010400000036C5&lt;CR&gt;&lt;LF&gt;
14-Jun-16 15:41:32.602 [TX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5&lt;CR&gt;&lt;LF&gt;
14-Jun-16 15:41:32.608 [RX] - 2E&lt;NAK&gt;ê¢‚‚¢Ê2e&lt;ENQ&gt;‚‚‚Âª‚²²&lt;LF&gt;
U%**&lt;ENQ&gt;2&lt;ENQ&gt;‚‚‚š&lt;LF&gt;
eU&lt;LF&gt;
‚‚‚º&lt;DC2&gt;&lt;NAK&gt;2&lt;ENQ&gt;‚‚¢‚‚‚‚‚‚‚&lt;DC2&gt;&lt;ENQ&gt;‚‚¢‚‚‚‚‚‚‚‚‚‚‚‚‚‚‚‚š2…‚‚‚‚‚'&lt;DC2&gt;E"EUJjÓSS&lt;DC4&gt;¦TT(&amp;LL˜˜00044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5&lt;CR&gt;&lt;LF&gt;
</code></pre>

<p>Can anyone help me, I am confused. Did I missed any configuration settings or ?</p>