Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort Qt5.9.1 issue
Qt 6.11 is out! See what's new in the release blog

QSerialPort Qt5.9.1 issue

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 905 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • michaelLM Offline
    michaelLM Offline
    michaelL
    wrote on last edited by
    #1

    Hi,

    i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
    The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.

    What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
    Here is my code:

    if(serial->bytesAvailable()>=160)
    {
            num=serial->read(buffer,160);
    
            if((num != -1) && num)
           {
                 QByteArray DSI_Array = QByteArray(buffer, 160);
                 ...
    

    Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?

    jsulmJ aha_1980A 2 Replies Last reply
    0
    • michaelLM michaelL

      Hi,

      i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
      The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.

      What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
      Here is my code:

      if(serial->bytesAvailable()>=160)
      {
              num=serial->read(buffer,160);
      
              if((num != -1) && num)
             {
                   QByteArray DSI_Array = QByteArray(buffer, 160);
                   ...
      

      Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @michaelL Can you show the code surrounding the code you posted?
      Also, who is not receiving what you're writing? You are talking about reading in your code.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • michaelLM michaelL

        Hi,

        i am facing an issue on QSerialPort. In Qt5.7.1 works fine but on Qt5.9.1 it is not receiving all values i am sending.
        The code is the same and i am only changing the kits/version from 5.7.1 to 5.9.1.

        What i am doing is waiting so that bytes available are equal or greater than 160 and i will only read 160 bytes.
        Here is my code:

        if(serial->bytesAvailable()>=160)
        {
                num=serial->read(buffer,160);
        
                if((num != -1) && num)
               {
                     QByteArray DSI_Array = QByteArray(buffer, 160);
                     ...
        

        Any idea? Is tehre a known issue on QSerialPort in Qt5.9.1?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by aha_1980
        #3

        @michaelL said in QSerialPort Qt5.9.1 issue:

        What i am doing is waiting so that bytes available are equal or greater than 160

        Which leads me to the question, how you are doing that.

        Also, on which platform are you experiencing this behavior?

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • michaelLM Offline
          michaelLM Offline
          michaelL
          wrote on last edited by
          #4

          So looking in the read part if i do:

          QByteArray Array=serial->readAll();
          it really does receive all bytes but the issue is when i want to read a specific amount of bytes like 160 and not all:

          So everytime i do this:
          serial->read(buffer,160);

          The QSerialPort buffer "erase" all bytes that where read from "read()" function plus the left ones inside.

          Why is the internal QSerialPort buffer been completely erased if i do "read(buffer,160);"
          I understand if i do "readAll()" it will read all values from serialport and delete them.
          But why is "read()" function doing the same in Qt5.9.1?

          1 Reply Last reply
          0
          • michaelLM Offline
            michaelLM Offline
            michaelL
            wrote on last edited by
            #5

            @aha_1980 so i am reading in a slot

            connect(serial, &QSerialPort::readyRead, this, &QelcSystemSerialport::run);
            

            Everytime QSerialPort send "readyRead" it goes to slot "run"

            A MCU is sending values to Qt Application. I debug MCu and it is sending, i measured the RX and TX with an oscilloscope and the values are send out.
            So the issue is in Qt

            1 Reply Last reply
            0
            • michaelLM Offline
              michaelLM Offline
              michaelL
              wrote on last edited by
              #6

              I dont know if this is causing the issue:

              void QIODevice::readyRead():
              " you should always emit readyRead() when new data has arrived (do not emit it only because there's data still to be read in your buffers"

              Everything was working with Qt5.7.1. Maybe i have to make a new loop to check if buffer still has values more ore equal than 160. If so, it should be read them, because the signal "readyRead()" wont be send out again.

              1 Reply Last reply
              0
              • michaelLM Offline
                michaelLM Offline
                michaelL
                wrote on last edited by
                #7

                Ok so this resolve my issue
                Instead of

                if(serial->bytesAvailable()>=160)
                

                I change it to

                while(serial->bytesAvailable()>=160)
                

                So if buffer has more values it should read them too. Once is less then 160 bytes, it will leave the slot. It iwll come back when "readyRead" signal is emitted again.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved