Hi everyone , i'm newbie to QT. Just struggled with QT about 2 months but i got basic informations about my project. I tried to explain my issue in the best way. Sorry for writing errors.

Here is the deal. I'm trying to get sensor values from T.I instruments' Hercules Board which have TMS570LS1227 microcontroller. Main purpose is getting the desired packages from sensor which is connected to board and log it to text file. I managed sending or receiving , logging tasks. But i read so much about QSerialPort losing data and etc. topics. I couldn't figure it out.

For testing the data i'm getting from board i'm only sending 5 byte short number. 1st byte is TypeCheck ( float,decimal and bla bla) for parsing the received package. 2nd and 3rd byte is the short value ( have a union struct no error about it) and the other 2 bytes is CRC(Cyclic Redundancy Check) value of the package.
This was just an information about what i'm trying to do.

I'm sending an counter variable to QT. Sending frequency have to be 10kHz. Means that 10000*5(bytes)*8(bit) = 400000 bit baudrate i should have. I searched forums about QT and it's saying that baudrate 600000 is available in QT. So i set my serial port according to that.

The struggle is that : When i'm getting data from board, first package is not coming like just "5 bytes to read". Incoming bytes in internal serial read buffer showing sometimes 10, sometimes 35, sometimes 500, it depends on how fast i'm doing the job on QT. I managed it with using a Circular Buffer to keep data without losing any of it. E.g: With debugging i saw that; when first package came to QT i'm getting let's say 50 bytes. I'm checking the values of the buffer and it's true.( in this case 50/5=10; last sended number i have to receive is 10). But then second package is coming and i'm checking the received buffer and first 5 byte didn't equal to "11". It can be "45". Then it follows "45,46,47.." .

This means i'm losing data. Why i'm struggling with that ? Is QT doesn't support higher baudrate in QSerialPort ?

I wanted to give the codes as well. You guys can check anything about it. Feel free to critisize my coding as well i wanted my skills to developed .

ReadyRead Signal is connected to the slot like that.

Qt Code:
  1. serial = new QSerialPort(this);
  2. connect(serial,SIGNAL(readyRead()),this,SLOT(toReadThePort()),Qt::QueuedConnection);
To copy to clipboard, switch view to plain text mode 


Initializing Serial Port code:


Qt Code:
  1. void MyObject::InitSerialPort()
  2. {
  3. /*Circular Buffer Initializing*/
  4.  
  5. CircularBufferManager_ApiInit(&SerialCircularBufferManager_s,
  6. &SerialBuffer[0],
  7. 1,
  8. 3000);
  9.  
  10. //Configure Port Settings;
  11.  
  12. static bool PortIsOpen;
  13. serial->setPortName("COM7");
  14. serial->setBaudRate(600000); // 460800
  15. serial->setDataBits(QSerialPort::Data8);
  16. serial->setParity(QSerialPort::NoParity);
  17. serial->setStopBits(QSerialPort::OneStop);
  18. serial->setFlowControl(QSerialPort::NoFlowControl);
  19. serial->setReadBufferSize(400);
  20.  
  21. if(!serial->isOpen())
  22. {
  23. PortIsOpen = serial->open(QIODevice::ReadWrite); // Open the Port;
  24. if(PortIsOpen == 1)
  25. qDebug()<<"Port Has Opened !";
  26. }
  27. serial->clear(QSerialPort::AllDirections);
  28.  
  29.  
  30. LogData(GonnaBeWrittenFile,StrBuffer); // Just for writing Header part of the log text.
  31.  
  32. }
To copy to clipboard, switch view to plain text mode 

Here is the ReadyRead Signal's connected slot code:



Qt Code:
  1. void MyObject::toReadThePort()
  2. {
  3.  
  4. static uint8 testData[400];
  5. static int counter=0;
  6.  
  7. NumberOfBytesToRead = serial->bytesAvailable();
  8. if(NumberOfBytesToRead > 0 && serial->isReadable())
  9. {
  10.  
  11. ArrayBuffer.clear();
  12. ArrayBuffer = serial->readAll();
  13. remain = (NumberOfBytesToRead % ExpectedPacketLength);
  14.  
  15. memcpy(testData,ArrayBuffer,(NumberOfBytesToRead-remain));
  16.  
  17. for(counter=0; counter < (NumberOfBytesToRead-remain); counter++)
  18. {
  19. CircularBufferManager_ApiPush(&SerialCircularBufferManager_s,(void*)&testData[counter]);
  20. }
  21. procCounter += (NumberOfBytesToRead-remain);
  22. serial->clear(QSerialPort::AllDirections); // Clear Serial Write and Read Internal Buffers
  23.  
  24. receiveData();
  25.  
  26. }
  27.  
  28. }
To copy to clipboard, switch view to plain text mode 

For last concern receivedata() function is that just the concerned part :



Qt Code:
  1. while(pulledData !='s')
  2. {
  3. CircularBufferManager_ApiPull(&SerialCircularBufferManager_s,&pulledData);
  4. qCnt++;
  5. }
  6.  
  7.  
  8. for(qCnt=0; qCnt<(NumberOfBytesToRead-remain); qCnt += ExpectedPacketLength)
  9. // for(qCnt; qCnt<procCounter; qCnt+= ExpectedPacketLength)
  10. {
  11. dummy=0;
  12. if(!(((NumberOfBytesToRead-remain)-qCnt) < ExpectedPacketLength))
  13. {
  14. for(dummyCounter=0;dummyCounter<ExpectedPacketLength;dummyCounter++)
  15. {
  16.  
  17. dummyArray[dummyCounter] = pulledData;
  18. shortArray[dummyCounter] = pulledData;
  19. CircularBufferManager_ApiPull(&SerialCircularBufferManager_s,&pulledData);
  20.  
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

Note: remain variable is required for circular buffer to don't getting the wrong package data.
Note: ExpectedPacketLength is define variable which can vary but in this code its "5".