configuring the serial port is given below
// 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 <0)
perror(MODEMDEVICE);
tcgetattr(fd,&SerialPortSettings); /* save current serial port settings */
/* Set Baud Rate */
cfsetospeed (&SerialPortSettings, (speed_t)B230400);
cfsetispeed (&SerialPortSettings, (speed_t)B230400);
SerialPortSettings.c_iflag &= ~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 &= ~PARENB; /* No Parity */
SerialPortSettings.c_cflag &= ~CSTOPB; /* Stop bits = 1 */
SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the Mask */
SerialPortSettings.c_cflag |= CS8; /* Set the data bits = 8 */
SerialPortSettings.c_cflag &= ~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 &= ~(IXON | IXOFF | IXANY); /* Turn off software based flow control */
tcsetattr ( fd, TCSANOW, &SerialPortSettings ); //TCSANOW tells to make the changes now without waiting
below given the expected output, which is coming 5 in 3-4 times
14-Jun-16 15:41:32.300 [RX] - :010400000036C5<CR><LF>
14-Jun-16 15:41:32.316 [TX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5<CR><LF>
14-Jun-16 15:41:32.341 [RX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5<CR><LF>
below is the output which I am getting 1 time in every 5 times
14-Jun-16 15:41:32.596 [RX] - :010400000036C5<CR><LF>
14-Jun-16 15:41:32.602 [TX] - :01046C00009FDA740049FF000085066AEB1E0F00003AFE00007B1F00040000000B000400000000000000003F8000002B4DDEB375E0EEA0000000044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5<CR><LF>
14-Jun-16 15:41:32.608 [RX] - 2E<NAK>ꢂ‚¢Ê2e<ENQ>‚‚‚ª‚²²<LF>
U%**<ENQ>2<ENQ>‚‚‚š<LF>
eU<LF>
‚‚‚º<DC2><NAK>2<ENQ>‚‚¢‚‚‚‚‚‚‚<DC2><ENQ>‚‚¢‚‚‚‚‚‚‚‚‚‚‚‚‚‚‚‚š2…‚‚‚‚‚'<DC2>E"EUJjÓSS<DC4>¦TT(&LL˜˜00044E1DD31400001F1E4D42312E302E300022D0837A33303030525300C6BB4187C05445542F414900AF6EFDFBFF937EA47A5F3D65BFA5<CR><LF>
Can anyone help me, I am confused. Did I missed any configuration settings or ?