I am facing a weird behavior of readyRead(). I use QextSerialPort for my serial communication and connect readyRead() with my reading slot. For example, I am writing 45 bytes to port and expecting to read 45 bytes but what happens, my readyRead() signal is emitted more than once, meaning it will read 38 bytes first then read 7 bytes. How can I make it read the whole chunk of data?
//Port setup
m_pSerialPort = new QextSerialPort(pduPortName, m_PortSettings, QextSerialPort::EventDriven);
m_pSerialPort->setBaudRate(m_PortSettings.BaudRate);
m_pSerialPort->setDataBits(m_PortSettings.DataBits);
m_pSerialPort->setFlowControl(m_PortSettings.FlowControl);
m_pSerialPort->setParity(m_PortSettings.Parity);
m_pSerialPort->setStopBits(m_PortSettings.StopBits);
m_pSerialPort->setTimeout(500);
m_pSerialPort->flush();
m_pSerialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered );
connect(m_pSerialPort, SIGNAL(readyRead()), this, SLOT(readSerialData()));
//write
qint64 bytesWritten = pSerialPort->write(data, bytes_to_write);
//Read
qint64 availableBytes = pSerialPort->bytesAvailable();
if (availableBytes >= SIZE)
bytesRead = pSerialPort->read(data , availableBytes);
I hope I explained my problem well. Please help!
Note: am using STANAG protocol for my messages.