Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QExtSerialPort && waitForReadyRead
Forum Updated to NodeBB v4.3 + New Features

QExtSerialPort && waitForReadyRead

Scheduled Pinned Locked Moved 3rd Party Software
15 Posts 4 Posters 13.8k Views 1 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #6

    Would spinning an eventloop while waiting for the signal be a solution for you? Or just use QxtSignalWaiter?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by
      #7

      [quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]

      I didn't know this, I'll try.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #8

        [quote author="Andre" date="1304426868"]Would spinning an eventloop while waiting for the signal be a solution for you? Or just use QxtSignalWaiter?[/quote]

        I have the function to read from serial port in a second thread so form me there isn't the problem of blocking event loop. I'd like to do this:
        @
        serialPort->write("123456\r\n");
        serialPort->waitForReadyRead(10000);
        int num_byte =serialPort->bytesAvailable();
        if(num_byte>=10)
        {
        qDebug() << "Num BYTE: " << num_byte;
        qDebug() << serialPort->read(num_byte);
        }
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #9

          It was mend as a work-around for the problem that waitForReadyRead doesn't work for you. I understand that it is not ideal, but it may just do the trick.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca
            wrote on last edited by
            #10

            [quote author="Andre" date="1304429607"]It was mend as a work-around for the problem that waitForReadyRead doesn't work for you. I understand that it is not ideal, but it may just do the trick. [/quote]

            So sorry, I didn't understand you question.

            As work-around I'll use this:
            @
            serialPort->write("123456\r\n");
            while(1)
            {
            int num_byte =serialPort->bytesAvailable();
            if(num_byte>=10)
            {
            qDebug() << "Num BYTE: " << num_byte;
            qDebug() << serialPort->read(num_byte);
            break;
            }
            }
            @

            or something similar.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca
              wrote on last edited by
              #11

              [quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]

              Thanks, It seems to works. I must do some tests but it goes in the right way.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #12

                [quote]As work-around I’ll use this:
                @
                serialPort->write("123456\r\n");
                while(1)
                {
                int num_byte =serialPort->bytesAvailable();
                if(num_byte>=10)
                {
                qDebug() << "Num BYTE: " << num_byte;
                qDebug() << serialPort->read(num_byte);
                break;
                }
                }
                @

                or something similar.[/quote]

                I would not do that. That will keep the eventloop occupied, and that in turn may interfere with the working of the serial port you're interested in. Not a good plan.

                How about something like this:
                @
                QxtSignalWaiter waiter(serialPort, SIGNAL(readyRead());
                serialPort->write("123456\r\n");
                if (waiter.wait(10000)) {
                int num_byte =serialPort->bytesAvailable();
                if(num_byte>=10)
                {
                qDebug() << "Num BYTE: " << num_byte;
                qDebug() << serialPort->read(num_byte);
                }
                } else {
                //timeout waiting...
                }
                @

                Edit: if another serial port implementation works better, then that is obviously a much better solution than messing around with hacks like QxtSignalWaiter.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luca
                  wrote on last edited by
                  #13

                  Thanks Andre, I never used QxtSignalWaiter but it seems very useful .

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #14

                    It is, but it does have its limitations. This is important to realize:

                    [quote]
                    Note: QxtSignalWaiter is not reentrant. In particular, only one QxtSignalWaiter object per thread can be safely waiting at a time. If a second QxtSignalWaiter is used while the first is waiting, the first will not return until the second has timed out or successfully caught its signal.[/quote]

                    Please be aware of those before using it. Also, often the use can be worked around, and if you can, that is often the better approach.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      stukdev
                      wrote on last edited by
                      #15

                      This project is not very popular but for me is better than Qextserialport.

                      [quote author="Luca" date="1304430744"]
                      [quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]

                      Thanks, It seems to works. I must do some tests but it goes in the right way.[/quote]

                      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