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. How to synchronize QTcpSocket data and timer data in the GUI
Qt 6.11 is out! See what's new in the release blog

How to synchronize QTcpSocket data and timer data in the GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.3k 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.
  • T Offline
    T Offline
    thippu
    wrote on last edited by aha_1980
    #1

    Hi,

    1. I used QwtPlot's x axis asQwtSystemClock object (seconds) it will keep running on the GUI.
    2. I will get 256 QPointF points through QTCPSocket per second in Socket.cpp by socket.
    3. How to synchronize received 256 QPointF's SetX() values according to QwtSystemClock's per second .
    4. Each point's x should have a difference (1/256=0.00390625)
    K 1 Reply Last reply
    0
    • T thippu

      Hi,

      1. I used QwtPlot's x axis asQwtSystemClock object (seconds) it will keep running on the GUI.
      2. I will get 256 QPointF points through QTCPSocket per second in Socket.cpp by socket.
      3. How to synchronize received 256 QPointF's SetX() values according to QwtSystemClock's per second .
      4. Each point's x should have a difference (1/256=0.00390625)
      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @thippu

      IMHO you will need time tags from device sending through tcp/ip. That is the most accurate possibility.

      QTcpSocket has a buffer and all in-coming data will be accumulated there. Typically sometime at the beginning you will receive a readyRead signal. At which time your application will react on the signal is dependend on a couple of factors (e.g. cpu load, time retrieve each data record, time to plot, ...).

      If you have a fast machine with a couple of cores, there might be possibility to run a thread checking the contents of the buffer very quickly. This would allow for assigning a time-tag for each value, but probably not too close to actual measuring time.

      Vote the answer(s) that helped you to solve your issue(s)

      T 1 Reply Last reply
      3
      • K koahnig

        @thippu

        IMHO you will need time tags from device sending through tcp/ip. That is the most accurate possibility.

        QTcpSocket has a buffer and all in-coming data will be accumulated there. Typically sometime at the beginning you will receive a readyRead signal. At which time your application will react on the signal is dependend on a couple of factors (e.g. cpu load, time retrieve each data record, time to plot, ...).

        If you have a fast machine with a couple of cores, there might be possibility to run a thread checking the contents of the buffer very quickly. This would allow for assigning a time-tag for each value, but probably not too close to actual measuring time.

        T Offline
        T Offline
        thippu
        wrote on last edited by
        #3

        @koahnig said in How to synchronize QTCPSOCKET data and timer data in the GUI:

        there might be possibility to run a thread checking the contents of the buffer very quickly.

        I can go with a thread.
        if I connect readyRead() to collectData() and store the data in buffer.
        after that by using QwtSystemClock clock in socket.cpp and calling sendToGui() every second and passing the data, Can I go with it?.

        K 1 Reply Last reply
        0
        • T thippu

          @koahnig said in How to synchronize QTCPSOCKET data and timer data in the GUI:

          there might be possibility to run a thread checking the contents of the buffer very quickly.

          I can go with a thread.
          if I connect readyRead() to collectData() and store the data in buffer.
          after that by using QwtSystemClock clock in socket.cpp and calling sendToGui() every second and passing the data, Can I go with it?.

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @thippu

          If this is your only option, you can try. Note, gut feeling on my side is that you will have varying time intervals between your "measured values". If this is acceptable, you need to decide.

          Vote the answer(s) that helped you to solve your issue(s)

          T 2 Replies Last reply
          1
          • K koahnig

            @thippu

            If this is your only option, you can try. Note, gut feeling on my side is that you will have varying time intervals between your "measured values". If this is acceptable, you need to decide.

            T Offline
            T Offline
            thippu
            wrote on last edited by thippu
            #5

            @koahnig
            My server does send only y values of the points.
            I have to calculate x values while they arrive and display only 256 samples.
            please help me.

            1 Reply Last reply
            0
            • K koahnig

              @thippu

              If this is your only option, you can try. Note, gut feeling on my side is that you will have varying time intervals between your "measured values". If this is acceptable, you need to decide.

              T Offline
              T Offline
              thippu
              wrote on last edited by thippu
              #6

              @koahnig
              Will this help me?

              double elapsed=clock.elapsed();
              int no_of_interval=256;
              double msecs=no_of_interval-(clock.elapsed()-elapsed);
              if(msecs>0.0)
              QThread::usleep(qRound(msecs*1000));
              
              K 1 Reply Last reply
              0
              • T thippu

                @koahnig
                Will this help me?

                double elapsed=clock.elapsed();
                int no_of_interval=256;
                double msecs=no_of_interval-(clock.elapsed()-elapsed);
                if(msecs>0.0)
                QThread::usleep(qRound(msecs*1000));
                
                K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                @thippu

                Best you try it with a small example. Within the thread you need to read the system clock and output.
                At the day's end all depends on the actual thread scheduling of your computer and device. The weakest link in the chain determines the accuracy.
                You will probably need to do a lot of testing. Also you need to consider what you actually want to have. One thing could be the even scaling for plotting or is it the precise and accurate knowledge of when the values are taken.

                Vote the answer(s) that helped you to solve your issue(s)

                T 1 Reply Last reply
                1
                • K koahnig

                  @thippu

                  Best you try it with a small example. Within the thread you need to read the system clock and output.
                  At the day's end all depends on the actual thread scheduling of your computer and device. The weakest link in the chain determines the accuracy.
                  You will probably need to do a lot of testing. Also you need to consider what you actually want to have. One thing could be the even scaling for plotting or is it the precise and accurate knowledge of when the values are taken.

                  T Offline
                  T Offline
                  thippu
                  wrote on last edited by
                  #8

                  @koahnig Thank you,

                  @koahnig said in How to synchronize QTcpSocket data and timer data in the GUI:

                  Best you try it with a small example. Within the thread, you need to read the system clock and output.

                  Doing this .

                  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