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 - readAll stops after CR
Forum Updated to NodeBB v4.3 + New Features

QSerialPort - readAll stops after CR

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 496 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.
  • H Offline
    H Offline
    hkottmann
    wrote on last edited by
    #1

    Dear all

    If I read from serial port using readAll it stops after receiving a CR (\r). Device Monitoring Studio reads the following string:

    24 30 37 37 0D 24 30 37 37 0D $077.$077.

    requestData.append(cormet->readLine());
    cormet->clear();
    qDebug() << "All " << requestData;
    

    The qDebug() output is as follows:

    All "$077\r"
    All "$077\r"

    What can I do that the whole buffer is read without taking notice CR or LF since also data in binary (Modbus) format are transferred here (I have afterwards to determine the data format).

    Thanks in advance.

    Hans

    O 1 Reply Last reply
    0
    • H hkottmann

      Dear all

      If I read from serial port using readAll it stops after receiving a CR (\r). Device Monitoring Studio reads the following string:

      24 30 37 37 0D 24 30 37 37 0D $077.$077.

      requestData.append(cormet->readLine());
      cormet->clear();
      qDebug() << "All " << requestData;
      

      The qDebug() output is as follows:

      All "$077\r"
      All "$077\r"

      What can I do that the whole buffer is read without taking notice CR or LF since also data in binary (Modbus) format are transferred here (I have afterwards to determine the data format).

      Thanks in advance.

      Hans

      O Online
      O Online
      ollarch
      wrote on last edited by
      #2

      @hkottmann You are calling "readLine()" that just stops reading when find a CR.

      1 Reply Last reply
      1
      • H Offline
        H Offline
        hkottmann
        wrote on last edited by
        #3

        I've just tried this too. But this here does the same:

        requestData.append(cormet->readAll());
        cormet->clear();
        qDebug() << "All " << requestData;
        

        All "$077\r"
        All "$077\r"

        Kind regards,

        Hans

        JonBJ O 2 Replies Last reply
        0
        • H hkottmann

          I've just tried this too. But this here does the same:

          requestData.append(cormet->readAll());
          cormet->clear();
          qDebug() << "All " << requestData;
          

          All "$077\r"
          All "$077\r"

          Kind regards,

          Hans

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @hkottmann
          readAll() does not "stop" after reading a \r or anything else. Review where you are calling this from (i.e. needs to be readyRead() signal/slot). You must allow for received data arriving in multiple "chunks", regardless of how they might have been sent.

          1 Reply Last reply
          0
          • H hkottmann

            I've just tried this too. But this here does the same:

            requestData.append(cormet->readAll());
            cormet->clear();
            qDebug() << "All " << requestData;
            

            All "$077\r"
            All "$077\r"

            Kind regards,

            Hans

            O Online
            O Online
            ollarch
            wrote on last edited by
            #5

            @hkottmann as @JonB points, you have to add the recived data to a buffer and parse it. As you are receiving Modbus responses, the protocol tells you how to calculate how long the response will be, so you know how many bytes are you expecting.

            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