QSerialport receive delay
-
I found an issue with the serial port assistant written in Qt. When receiving high-speed data, the data cannot be read in real-time and it always reads multiple data packets at once within a short period of time. This issue exists not only in my own Qt program, but also in other serial port programs written in Qt that I downloaded from Github.
For example, I am receiving data sent every 10ms, with each data packet containing 60 bytes of data. In my own program, Serial Studio, and other serial port assistants written in Qt, I receive 66 data packets once every 660ms.
Here is the code:
connect(serialPort, &QSerialPort::readyRead, this, &SerialPort::readserialPort); void SerialPort::readIMUPort() { QByteArray readData = imuPort->readAll(); buffer.append(readData); qDebug()<<readData .size() / PACKET_LENGTH; //len = 60 bytes } -
I found an issue with the serial port assistant written in Qt. When receiving high-speed data, the data cannot be read in real-time and it always reads multiple data packets at once within a short period of time. This issue exists not only in my own Qt program, but also in other serial port programs written in Qt that I downloaded from Github.
For example, I am receiving data sent every 10ms, with each data packet containing 60 bytes of data. In my own program, Serial Studio, and other serial port assistants written in Qt, I receive 66 data packets once every 660ms.
Here is the code:
connect(serialPort, &QSerialPort::readyRead, this, &SerialPort::readserialPort); void SerialPort::readIMUPort() { QByteArray readData = imuPort->readAll(); buffer.append(readData); qDebug()<<readData .size() / PACKET_LENGTH; //len = 60 bytes }If you require ms precise serial data transmission then you need to use a hard RTOS or bare-metal programming on microcontroller.
Just because "a lot" of folks do it, doesn't make it correct. The pros know better.
-
I found an issue with the serial port assistant written in Qt. When receiving high-speed data, the data cannot be read in real-time and it always reads multiple data packets at once within a short period of time. This issue exists not only in my own Qt program, but also in other serial port programs written in Qt that I downloaded from Github.
For example, I am receiving data sent every 10ms, with each data packet containing 60 bytes of data. In my own program, Serial Studio, and other serial port assistants written in Qt, I receive 66 data packets once every 660ms.
Here is the code:
connect(serialPort, &QSerialPort::readyRead, this, &SerialPort::readserialPort); void SerialPort::readIMUPort() { QByteArray readData = imuPort->readAll(); buffer.append(readData); qDebug()<<readData .size() / PACKET_LENGTH; //len = 60 bytes }@IPlayGenji6 The connect() call and the slot code you posted do not seem to be related.
As for the time between slot invocations, this will depend very much on what else is happening in your program and on your system. Qt cannot respond to data received if your operating system serial driver does not announce it. Qt cannot dispatch a signal to your slot if it is busy doing something else e.g., updating a display overly often or processing something long running in another slot.
-
I IPlayGenji6 has marked this topic as solved on