Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Unable to read the response from the hardware.
Forum Updated to NodeBB v4.3 + New Features

Unable to read the response from the hardware.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 4 Posters 1.8k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    Mohit Tripathi
    wrote on last edited by
    #1
    This post is deleted!
    sierdzioS 1 Reply Last reply
    0
    • M Mohit Tripathi

      This post is deleted!

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Mohit-Tripathi said in Unable to read the response from the hardware.:

      Can I know what is wrong here?

      You don't start the event loop. So waitForReadyRead() won't work.

      Start the event loop (app.exec()) and then kickoff your algorithm (via QTimer for example).

      (Z(:^

      JKSHJ 1 Reply Last reply
      3
      • sierdzioS sierdzio

        @Mohit-Tripathi said in Unable to read the response from the hardware.:

        Can I know what is wrong here?

        You don't start the event loop. So waitForReadyRead() won't work.

        Start the event loop (app.exec()) and then kickoff your algorithm (via QTimer for example).

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by JKSH
        #3

        @sierdzio said in Unable to read the response from the hardware.:

        @Mohit-Tripathi said in Unable to read the response from the hardware.:

        Can I know what is wrong here?

        You don't start the event loop. So waitForReadyRead() won't work.

        Start the event loop (app.exec()) and then kickoff your algorithm (via QTimer for example).

        Furthermore, don't use an infinite loop (while (true) {...}). The infinite loop blocks the event loop.

        See the QSerialPort examples for help.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        M 1 Reply Last reply
        3
        • JKSHJ JKSH

          @sierdzio said in Unable to read the response from the hardware.:

          @Mohit-Tripathi said in Unable to read the response from the hardware.:

          Can I know what is wrong here?

          You don't start the event loop. So waitForReadyRead() won't work.

          Start the event loop (app.exec()) and then kickoff your algorithm (via QTimer for example).

          Furthermore, don't use an infinite loop (while (true) {...}). The infinite loop blocks the event loop.

          See the QSerialPort examples for help.

          M Offline
          M Offline
          Mohit Tripathi
          wrote on last edited by Mohit Tripathi
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mohit Tripathi
            wrote on last edited by Mohit Tripathi
            #5
            This post is deleted!
            sierdzioS 1 Reply Last reply
            0
            • M Mohit Tripathi

              This post is deleted!

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @Mohit-Tripathi said in Unable to read the response from the hardware.:

              return app.exec();

              Calling app.exec() in a loop is utterly wrong. Don't ever do it!

              If your previous solution did work, stick to that. Or rewrite your code as I suggested initially (move serial code into a class, call it using QTimer::singleShot(1, &YourClass::start);).

              I am getting the value in split form and not getting the excepted result.

              Then simply glue the response back together in your code.

              (Z(:^

              M 1 Reply Last reply
              2
              • sierdzioS sierdzio

                @Mohit-Tripathi said in Unable to read the response from the hardware.:

                return app.exec();

                Calling app.exec() in a loop is utterly wrong. Don't ever do it!

                If your previous solution did work, stick to that. Or rewrite your code as I suggested initially (move serial code into a class, call it using QTimer::singleShot(1, &YourClass::start);).

                I am getting the value in split form and not getting the excepted result.

                Then simply glue the response back together in your code.

                M Offline
                M Offline
                Mohit Tripathi
                wrote on last edited by Mohit Tripathi
                #7

                @sierdzio @JKSH
                Is this the right format of read value in Qt "303030303030313000632c"?
                The write value is 01020001000a.
                How can I check the read value is correct?

                sierdzioS 1 Reply Last reply
                0
                • M Mohit Tripathi

                  @sierdzio @JKSH
                  Is this the right format of read value in Qt "303030303030313000632c"?
                  The write value is 01020001000a.
                  How can I check the read value is correct?

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @Mohit-Tripathi said in Unable to read the response from the hardware.:

                  @sierdzio @JKSH
                  Is this the right format of read value in Qt "303030303030313000632c"?
                  The write value is 01020001000a.
                  How can I check the read value is correct?

                  We have no way of knowing that. You are communicating with your serial port device. Inspect the device API to know what kind of responses you should expect. We don't know what device it is and what software it runs...

                  (Z(:^

                  M 1 Reply Last reply
                  3
                  • sierdzioS sierdzio

                    @Mohit-Tripathi said in Unable to read the response from the hardware.:

                    @sierdzio @JKSH
                    Is this the right format of read value in Qt "303030303030313000632c"?
                    The write value is 01020001000a.
                    How can I check the read value is correct?

                    We have no way of knowing that. You are communicating with your serial port device. Inspect the device API to know what kind of responses you should expect. We don't know what device it is and what software it runs...

                    M Offline
                    M Offline
                    Mohit Tripathi
                    wrote on last edited by Mohit Tripathi
                    #9

                    @JKSH @sierdzio
                    I am using the Hercules software to get the response from the hardware.
                    But, I am not getting the same response in the Qt. I am using the PIC micro-controller.
                    The query is 01020001000a.
                    I am getting the response from the hardware into the Hercules is 00000010{00}c but into Qt "03030303030313000632c".
                    How can I get the same response?
                    I think that I am getting the correct response in Hercules but I am not getting the correct response in Qt.
                    I want to be sure about the response in Qt. This is correct or not.
                    Is there any way to find?

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      What happens if you convert to hex before sending?

                      void transmit(QSerialPort & port, const QByteArray & data) {
                         port.write(data.toHex());
                         qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData();
                         chkError(port);
                      }
                      

                      (Z(:^

                      M 1 Reply Last reply
                      0
                      • sierdzioS sierdzio

                        What happens if you convert to hex before sending?

                        void transmit(QSerialPort & port, const QByteArray & data) {
                           port.write(data.toHex());
                           qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData();
                           chkError(port);
                        }
                        
                        M Offline
                        M Offline
                        Mohit Tripathi
                        wrote on last edited by
                        #11

                        @sierdzio
                        Nothing is reading here. If I am using the port.write(data.toHex()).

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          kuzulis
                          Qt Champions 2020
                          wrote on last edited by kuzulis
                          #12

                          @Mohit Tripathi

                          just use waitForBytesWritten() after the write call, and wairForReadyRed() before the read call, in your synhronous approach.

                          1 Reply Last reply
                          1

                          • Login

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