Missing Data Read From Qt
-
Hi, ı am ne in Qt. I was trying to send data from STM32f407vg to Qt. The data is produced by RTC module and gives time, date (for example, 2024-03-11T17:01:24+08:00Monday). However the data read by Qt is not full in text edit always. It is like a loop below and repeated always.
2 2 2 20 20 20 202 202 202 2024 2024 2024 2024- 2024- 2024- 2024-0 2024-0 2024-0 2024-03 2024-03 2024-03 2024-03- 2024-03- 2024-03- 2024-03-1 2024-03-1 2024-03-1 2024-03-11 2024-03-11 2024-03-11 2024-03-11T 2024-03-11T 2024-03-11T 2024-03-11T1 2024-03-11T1 2024-03-11T1 2024-03-11T17 2024-03-11T17 2024-03-11T17 2024-03-11T17: 2024-03-11T17: 2024-03-11T17: 2024-03-11T17:0 2024-03-11T17:0 2024-03-11T17:0 2024-03-11T17:01 2024-03-11T17:01 2024-03-11T17:01 2024-03-11T17:01: 2024-03-11T17:01: 2024-03-11T17:01: 2024-03-11T17:01:1 2024-03-11T17:01:1 2024-03-11T17:01:1 2024-03-11T17:01:17 2024-03-11T17:01:17 2024-03-11T17:01:17 2024-03-11T17:01:17+ 2024-03-11T17:01:17+ 2024-03-11T17:01:17+ 2024-03-11T17:01:17+0 2024-03-11T17:01:17+0 2024-03-11T17:01:17+0 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday (the loop always repeated)
When ı tested in termit terminal, the data is read properly like
2024-03-11T17:01:17+08:00Monday
The data is transmitted in stm32
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d%+03d:%02d%s\n", year, month, date, hour, minute, second, zone_hr, zone_min, DAYS_OF_WEEK[dow]); HAL_UART_Transmit(&huart3, buffer, strlen(buffer), 1000);
The data is read by qt code
void Widget::Read_Data() { //to make debug: serialData = serialPort.readAll(); serialBuffer += QString::fromStdString(serialData.toStdString()); qDebug() << serialBuffer; QStringList bufferSplit = serialBuffer.split("\n"); if(bufferSplit.length() < 3) { serialData = serialPort.readAll(); serialBuffer += QString::fromStdString(serialData.toStdString()); } else //bufferSplit[0] is a good value { qDebug() << bufferSplit; serialBuffer = ""; } ui->display_line->append(bufferSplit[0]); }
The data is splitted (according to \n) and stored in the buffer to be read.
The bufferlist is below and ı have taken 0. index
QList("2024-03-11T17:01:24+08:00Monday", "2024-03-11T17:01:25+08:00Monday", "")
-
@MG33 said in Missing Data Read From Qt:
QStringList bufferSplit = serialBuffer.split("\n");
if(bufferSplit.length() < 3)
{
serialData = serialPort.readAll();
serialBuffer += QString::fromStdString(serialData.toStdString());
}What's the point to call readAll() again here? You already read all available data above.
You will get more data next time Read_Data is called. And you only should set the data in UI if you got complete data, currently you always set it, doesn't matter whether you got everything or not. -
@MG33
Don't understand what you are asking now.
Let me know when you fancy answering when and how often you callRead_Data()
. Your output indicates it is being called repeatedly 3 times per each byte individually received.
And no indication of any missing data. -
@MG33
The output you display shows groups of 3 lines at a time, after each of which another single character is appended, building towards the whole string having been received. You could check how many bytes are being received by eachrealAll()
call.Is there any chance you have executed that
connect()
statement 3 times?At this point you should make the rest of the code as minimal as possible and show it.
There shouldn't be any need of a
QTextEdit
or anything else in a UI to test/debug your issue, whatever it is. -
@JonB my point is read the data like
2024-03-11T17:01:24+08:00Monday 2024-03-11T17:01:25+08:00Monday 2024-03-11T17:01:26+08:00Monday 2024-03-11T17:01:27+08:00Monday
however the data flows like that
2 2 2 20 20 20 202 202 202 2024 2024 2024 2024- 2024- 2024- 2024-0 2024-0 2024-0 2024-03 2024-03 2024-03 2024-03- 2024-03- 2024-03- 2024-03-1 2024-03-1 2024-03-1 2024-03-11 2024-03-11 2024-03-11 2024-03-11T 2024-03-11T 2024-03-11T 2024-03-11T1 2024-03-11T1 2024-03-11T1 2024-03-11T17 2024-03-11T17 2024-03-11T17 2024-03-11T17: 2024-03-11T17: 2024-03-11T17: 2024-03-11T17:0 2024-03-11T17:0 2024-03-11T17:0 2024-03-11T17:01 2024-03-11T17:01 2024-03-11T17:01 2024-03-11T17:01: 2024-03-11T17:01: 2024-03-11T17:01: 2024-03-11T17:01:1 2024-03-11T17:01:1 2024-03-11T17:01:1 2024-03-11T17:01:17 2024-03-11T17:01:17 2024-03-11T17:01:17 2024-03-11T17:01:17+ 2024-03-11T17:01:17+ 2024-03-11T17:01:17+ 2024-03-11T17:01:17+0 2024-03-11T17:01:17+0 2024-03-11T17:01:17+0 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08: 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:0 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00M 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mo 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mon 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Mond 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monda 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday 2024-03-11T17:01:17+08:00Monday
how can ı solve that ?
-
@MG33 I already told you what you're doing wrong. Just read it and act accordingly instead of repeating same information again and again.
Accumulate data in a buffer until you got a complete package and then parse it and update your UI.