Reputation: 2696
I´m using QExtSerialPort to read out an usb device, but I have an issue with reading the data send through the serial port. The data is send at rates of between 100 and 1000Hz and sometimes the data is stuck together. For example if the data has size of 18 bytes, mostly it is read as 18 bytes, but sometimes it reads 36 or 54, etc bytes. This espicially happens when I let my computer do other things. The code I use is the following:
QextSerailPort port = new QextSerialPort("COM11")
QByteArray data;
connect(port, SIGNAL(readyRead()),this, SLOT(DataAvailable()));
void MainWindow::DataAvailable()
{
while(!(port->bytesAvailable()));
data = port->readAll();
qDebug() << data.toHex();
}
Does anybody have a solution?
Upvotes: 0
Views: 323
Reputation: 24847
Serial ports, like TCP links, are byte-streams. You cannot transfer messages, strings, structs or anything larger than one byte.
You have to have a protocol that can parse out the messages/whatever from the byte stream. there is no other way.
Upvotes: 2