PDA

View Full Version : Not reading the serial port data fully using QExserialports readyread of singal slot



arunkumaraymuo1
21st January 2013, 08:56
OS:Ubuntu 11
QExtSerialport 1.2 beta


I am creating an application to write an instruction to a device and receive its response from the device. I connected the readyread() singal to onReadyRead() slot. but sometime its getting only the partial data from the device to the onReadyRead() slot.

I am writing *Read to device
and getting
*Read<Values>
P=122
C=0.33
sometime I got only the partial result in my onReadyRead()

I tried event driven and Polling methods.Still the issue exist.How I can completely read the device input in my onReadyRead().
I checked this on putty software also. its working perfectly in there.

my code sample is given below


void Reader::Create()
{
PortSettings settings = {BAUD19200, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 20};
port = new QextSerialPort(m_strPortName, settings, QextSerialPort::EventDriven);

timer = new QTimer(this);
timer->setInterval(20);



connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));

if (!port->isOpen())
{
port->setPortName(m_strPortName);
port->open(QIODevice::ReadWrite);
}
else {
// port->close();
}

if (port->isOpen() && port->queryMode() == QextSerialPort::Polling)
timer->start();
else
timer->stop();

}

void Reader::onReadyRead()
{
if (port->bytesAvailable())
{
m_strData= port->readAll();
}
}

wysota
21st January 2013, 10:56
Your slot will be called again when more data is available.

Lesiok
21st January 2013, 11:44
Remember that the slot can be called after the first byte of data.

arunkumaraymuo1
21st January 2013, 12:10
How can I get the full data to a string with a single call.

I want to read the full data to a string before next input to the serial device

wysota
21st January 2013, 12:12
How can I get the full data to a string with a single call.
You can't. The speed of data transmission over the wire is finite.


I want to read the full data to a string before next input to the serial device
Aggregate incoming data in a buffer and once you detect(*) all of it has arrived, you can start processing it.

*) how to do that depends on your application protocol