Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: QSerialPort High Speed Serial Reading from board and Logging Issue

  1. #1
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Question QSerialPort High Speed Serial Reading from board and Logging Issue

    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".

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Why are You clearing serial port buffers in MyObject::toReadThePort() ???? This is the place where you lose data.

  3. #3
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    Why are You clearing serial port buffers in MyObject::toReadThePort() ???? This is the place where you lose data.
    Because, i'm reading the data before clearing the serial port. Data is keep coming consistently if i don't clear port there , the other incoming bytes will not going to take a place in buffer.(I thought like that actually.) I think i'm getting all data in buffer then clearing it. If it is wrong where should i clear my serial port for not losing data ?

    Thanks for the quick reply by the way.

  4. #4
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Hi, franbogaz.

    Verifies that by moving QSerialPort :: Data8 to QSerialPort :: Data5 your project stabilizes.

    You can test from QSerialPort :: Data5 to QSerialPort :: Data8.

    Qt Code:
    1. enum QSerialPort::DataBits
    2.  
    3. This enum describes the number of data bits used.
    4.  
    5. Constant Value Description
    6. QSerialPort::Data5 5 The number of data bits in each character is 5. It is used for Baudot code. It generally only makes sense with older equipment such as teleprinters.
    7. QSerialPort::Data6 6 The number of data bits in each character is 6. It is rarely used.
    8. QSerialPort::Data7 7 The number of data bits in each character is 7. It is used for true ASCII. It generally only makes sense with older equipment such as teleprinters.
    9. QSerialPort::Data8 8 The number of data bits in each character is 8. It is used for most kinds of data, as this size matches the size of a byte. It is almost universally used in newer applications.
    10. QSerialPort::UnknownDataBits -1 Unknown number of bits. This value is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcos.miranda; 19th January 2017 at 13:16.

  5. #5
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by marcos.miranda View Post
    Hi, franbogaz.

    Verifies that by moving QSerialPort :: Data8 to QSerialPort :: Data5 your project stabilizes.

    You can test from QSerialPort :: Data5 to QSerialPort :: Data8.

    Qt Code:
    1. enum QSerialPort::DataBits
    2.  
    3. This enum describes the number of data bits used.
    4.  
    5. Constant Value Description
    6. QSerialPort::Data5 5 The number of data bits in each character is 5. It is used for Baudot code. It generally only makes sense with older equipment such as teleprinters.
    7. QSerialPort::Data6 6 The number of data bits in each character is 6. It is rarely used.
    8. QSerialPort::Data7 7 The number of data bits in each character is 7. It is used for true ASCII. It generally only makes sense with older equipment such as teleprinters.
    9. QSerialPort::Data8 8 The number of data bits in each character is 8. It is used for most kinds of data, as this size matches the size of a byte. It is almost universally used in newer applications.
    10. QSerialPort::UnknownDataBits -1 Unknown number of bits. This value is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
    To copy to clipboard, switch view to plain text mode 
    I tried data5 but serial port is not opening. I'm using QSerialPort:ata8 and each character has 8 bits so its correct i think. Am i right ?
    Maybe i didn't understand what you're saying.

    Thanks.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by franbogaz View Post
    Because, i'm reading the data before clearing the serial port. Data is keep coming consistently if i don't clear port there , the other incoming bytes will not going to take a place in buffer.(I thought like that actually.) I think i'm getting all data in buffer then clearing it. If it is wrong where should i clear my serial port for not losing data ?

    Thanks for the quick reply by the way.
    Error in reasoning.
    1. During the operation of the data read by serial->readAll buffers appears next portion of the data that you delete in line 22.
    2. The data you read in packs of random length (this is the nature of the serial port) and you lose "remain" the last byte.
    3. The length of the data read by the serial->readAll () may be greater than serial-> bytesAvailable () read previously.

  7. #7
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Hi, franbogaz.

    If I understood your problem well.
    Perhaps your problem of loss of information is related to serial cable (manufacturing quality) or connection parameters.

    I'm finding it strange that your serial connection configuration.
    I've been searching the Internet and I think you should use the following:

    Qt Code:
    1. 1. serial-> setPortName ("COM7");
    2. 2. serial-> setBaudRate (19200); // Rate = 19200 * 3.32 * log (4) ... Rate = 38Kbps.
    3. 3. serial-> setDataBits (QSerialPort :: Data8);
    4. 4. serial-> setParity (QSerialPort :: NoParity);
    5. 5. serial-> setStopBits (QSerialPort :: OneStop);
    6. 6. serial-> setFlowControl (QSerialPort :: SoftwareControl); // Software flow control (XON / XOFF).
    7. 7. serial-> setReadBufferSize (400);
    To copy to clipboard, switch view to plain text mode 

    It is more common to use these settings to access equipment via the serial port

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Why are you using a QueuedConnection?

    Cheers,
    _

  9. #9
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by anda_skoa View Post
    Why are you using a QueuedConnection?

    Cheers,
    _
    Nothing changed when i delete the QueuedConnection. I didn't put it on purpose. Just trying what i see on forums .


    Added after 7 minutes:


    Quote Originally Posted by Lesiok View Post
    Error in reasoning.
    1. During the operation of the data read by serial->readAll buffers appears next portion of the data that you delete in line 22.
    2. The data you read in packs of random length (this is the nature of the serial port) and you lose "remain" the last byte.
    3. The length of the data read by the serial->readAll () may be greater than serial-> bytesAvailable () read previously.
    Hi again. I'm aware of losing byte because of "remain" but it is just 1 byte per package. (1 package loss in 500) But i tried your approach. I'm readAll to data to ArrayBuffer and i'm arranging my NumberOfBytesToRead = ArrayBuffer.size();
    Actually it became more stable. But i got a problem now like that. First 2500 number is coming without any error then it is going like this : after 2500(number) is recevied -> 3500..3700 -> 7500..7800 -> 11000..12000 -> etc

    I'm losing package in somewhere else and it became periodic.


    Quote Originally Posted by marcos.miranda View Post
    Hi, franbogaz.

    If I understood your problem well.
    Perhaps your problem of loss of information is related to serial cable (manufacturing quality) or connection parameters.

    I'm finding it strange that your serial connection configuration.
    I've been searching the Internet and I think you should use the following:

    Qt Code:
    1. 1. serial-> setPortName ("COM7");
    2. 2. serial-> setBaudRate (19200); // Rate = 19200 * 3.32 * log (4) ... Rate = 38Kbps.
    3. 3. serial-> setDataBits (QSerialPort :: Data8);
    4. 4. serial-> setParity (QSerialPort :: NoParity);
    5. 5. serial-> setStopBits (QSerialPort :: OneStop);
    6. 6. serial-> setFlowControl (QSerialPort :: SoftwareControl); // Software flow control (XON / XOFF).
    7. 7. serial-> setReadBufferSize (400);
    To copy to clipboard, switch view to plain text mode 

    It is more common to use these settings to access equipment via the serial port

    I tried what marcos.miranda said. Baudrate is still 600000 but flow control seems logical. When i tried softwareflowcontrol USB Serial Port stucks and not opening again or closing or receiving or sending data. I'm restarting pc and trying it again and it is same like this. Couldnt understand what's going on about flow control.
    Last edited by franbogaz; 20th January 2017 at 09:21.

  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    So make a simple test. Use this :
    Qt Code:
    1. void MyObject::toReadThePort()
    2. {
    3. qDebug() << serial->readAll();
    4. }
    To copy to clipboard, switch view to plain text mode 
    In this way you will find out whether the data are lost in your code or the link.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by franbogaz View Post
    Nothing changed when i delete the QueuedConnection. I didn't put it on purpose. Just trying what i see on forums .
    Definitely not a good idea.

    You want your code to react to the readyRead() signal when it happens, not delayed at some later time.

    Cheers,
    _

  12. #12
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    So make a simple test. Use this :
    Qt Code:
    1. void MyObject::toReadThePort()
    2. {
    3. qDebug() << serial->readAll();
    4. }
    To copy to clipboard, switch view to plain text mode 
    In this way you will find out whether the data are lost in your code or the link.
    Hi man.
    I have tried what you said so many times. Here the best result i can get.

    https://postimg.org/image/onlcn5mrj/

    https://postimg.org/image/mx2blo58f/

    I'm counting at qt side simultaneously for testing the COUNTER value which is coming from board. Here you can see lost packages. After that package lost it is happening periodically and always ~3000 data. I checked the sending code ( board side) everything is okay there. I debugged it really carefully. The problem is QT side but i still couldn't figure it out.

    list = QSerialPortInfo::standardBaudRates();

    I used this code for finding baudrates supported and the maximum i saw is 256000 and i'm using it now. I set the sending frequency to 2.5kHz. Means 2500*5(bytes)*8(bit) = 100000. So 256000 should work with it.

    Quote Originally Posted by anda_skoa View Post
    Definitely not a good idea.

    You want your code to react to the readyRead() signal when it happens, not delayed at some later time.

    Cheers,
    _
    Now i'm using directConnection. It's better but i still got the problem :/.

    Thanks.

  13. #13
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    You did not use methods such as I pointed out - use exactly like mine. The point is you do not do any processing of the received data.

  14. #14
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Okay but now i see this.

    https://postimg.org/image/tocst0rox/

    I cant understand from anything here. Every time package is coming in different sizes. Maybe i couldn't understand you fully sorry.

    Thanks.

  15. #15
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by franbogaz View Post
    Okay but now i see this.

    https://postimg.org/image/tocst0rox/
    Yes, and now you have to analyze whether the data are complete or not.

    Quote Originally Posted by franbogaz View Post
    I cant understand from anything here. Every time package is coming in different sizes. Maybe i couldn't understand you fully sorry.

    Thanks.
    This is normal. Serial port knows nothing about packets. Serial port is a stream of bytes. You have to divide the stream into packets and handle them. It should look something like this
    Qt Code:
    1. void MyObject::toReadThePort()
    2. {
    3.  
    4. if(serial->isReadable())
    5. {
    6.  
    7. ArrayBuffer.append(serial->readAll());
    8. while(ArrayBuffer.size() >= ExpectedPacketLength)
    9. {
    10. QByteArray one_packet = ArrayBuffer.left(ExpectedPacketLength);
    11. // Here processing of one_packet
    12. ArrayBuffer.remove(0,ExpectedPacketLength);//delete processed packet
    13. }
    14. receiveData();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    Of course I not tried to compile it - it is only a sketch.

  16. The following user says thank you to Lesiok for this useful post:

    franbogaz (23rd January 2017)

  17. #16
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Thanks for quick reply. I will try it and get back to you as soon as possible i can.

  18. #17
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    Yes, and now you have to analyze whether the data are complete or not.

    This is normal. Serial port knows nothing about packets. Serial port is a stream of bytes. You have to divide the stream into packets and handle them. It should look something like this
    Qt Code:
    1. void MyObject::toReadThePort()
    2. {
    3.  
    4. if(serial->isReadable())
    5. {
    6.  
    7. ArrayBuffer.append(serial->readAll());
    8. while(ArrayBuffer.size() >= ExpectedPacketLength)
    9. {
    10. QByteArray one_packet = ArrayBuffer.left(ExpectedPacketLength);
    11. // Here processing of one_packet
    12. ArrayBuffer.remove(0,ExpectedPacketLength);//delete processed packet
    13. }
    14. receiveData();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    Of course I not tried to compile it - it is only a sketch.
    I did what you said. And it became more stable. Actually it is working at lower frequency. But i need 2.5kHz. It's working at 500 Hz now.

    I changed my code like this :

    Qt Code:
    1. while(ArrayBuffer.size() >= ExpectedPacketLength)
    2. {
    3. indexOfType = ArrayBuffer.indexOf('s');
    4.  
    5. if(indexOfType >= 1)
    6. {
    7. ArrayBuffer.remove(0,indexOfType);
    8. }
    9.  
    10. QByteArray one_packet = ArrayBuffer.left(ExpectedPacketLength);
    11. ArrayBuffer.remove(0,ExpectedPacketLength);
    12.  
    13. if(one_packet[0] == 's') // 's' buldur kodu yaz dene!
    14. {
    15. for(dummyCounter=0;dummyCounter<ExpectedPacketLength;dummyCounter++)
    16. {
    17.  
    18. dummyArray[dummyCounter] = one_packet[dummyCounter];
    19. shortArray[dummyCounter] = one_packet[dummyCounter];
    20. }
    21.  
    22. CRCValue = crcsum(&dummyArray[0],ExpectedPacketLength,CRC_INIT); // Just Checking the CRCValue. not gonna use anywhere.
    23. ReceiveIsSuccessful = crcverify(&dummyArray[0],ExpectedPacketLength);
    24.  
    25. if(ReceiveIsSuccessful == 1) // Checking if CRC is OK or not
    26. { .. parse and logging process is here..}
    To copy to clipboard, switch view to plain text mode 

    Now here is the other problem:

    When i'm trying to get data at 2.5kHz terminal goes like this :

    Everything is okay to some point. But when any error occurs (like CRC can be wrong) QT cant keep the data instaneously at that time.
    https://postimg.org/image/ilb3tg0d5/

    So i added to my code this :

    Qt Code:
    1. if(ArrayBuffer.size() >= 20000){
    2. .. then the code is the same i wrote above..
    To copy to clipboard, switch view to plain text mode 

    Now it's getting better:

    https://postimg.org/image/iml1mv26x/

    But as we can see suddenly data are escaping from the buffer after its full. When i increment the 20000 to 100000 or much far away its getting better. However board will always send data constantly.

    How can i solve this ? I tried to clear the ArrayBuffer after a chunk of data (20000) have been processed. But it didnt fix it. Any idea about this ?

    Because i'm thinking QSerialPort cant handle the high frequency communication. Maybe internal read buffer size isn't enough ?

    Thanks for help.

  19. #18
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Can You tell some about protocol (frame construction) ? As I see a frame starts with letter s.

  20. #19
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    > Because i'm thinking QSerialPort cant handle the high frequency communication.

    It is only your wrong thinking.

    > serial->setReadBufferSize(400);

    Don't touch this at all.

    By default the internal buffer of QSP is infinite, and QSP does not lose any data.

    > serial->clear(...)

    Do not use it.

    PS: The problem is in your code.
    Last edited by kuzulis; 23rd January 2017 at 12:14.

  21. #20
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    Can You tell some about protocol (frame construction) ? As I see a frame starts with letter s.
    Yes. Starting with type -> 1byte for 's', then the short value -> which is 2 byte , and the other 2 byte -> is the CRC Value of these 3 bytes('s',short value byte 1, short value byte 2). Total of 5 bytes i'm receiving.


    Quote Originally Posted by kuzulis View Post
    > Because i'm thinking QSerialPort cant handle the high frequency communication.

    It is only your wrong thinking.

    > serial->setReadBufferSize(400);

    Don't touch this at all.

    By default the internal buffer of QSP is infinite, and QSP does not lose any data.

    > serial->clear(...)

    Do not use it.

    PS: The problem is in your code.
    Hi kuzulis. I read about internal buffer and i removed that code directly. I was just limited the internal buffer without any reason. Yes that was wrong. I forgot to say that at my last post.

    I'm basically thinking that now while parsing and logging processes are going on readyRead is not emitted so i'm losing data ? I can't think any other problem. I checked and debugged my code so many times.

    Thanks for the help.

    Edit: I also removed the serial->clear(); Not using it anywhere in code.

Similar Threads

  1. Replies: 1
    Last Post: 22nd June 2016, 00:32
  2. QSerialPort - speed and performance
    By Wer_Bn in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2015, 18:12
  3. qserialport and reading bytes
    By gab74 in forum Newbie
    Replies: 3
    Last Post: 14th February 2014, 21:11
  4. QSerialPort :: read - Serial Comms noob.
    By llaregyb in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2014, 13:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.