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. Send multiple Can signals at the same time
Forum Updated to NodeBB v4.3 + New Features

Send multiple Can signals at the same time

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.5k 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.
  • P PriyankaM96
    30 Apr 2021, 10:35

    @nagesh Thank you for the sudden reply.

    I have not used threads till now, since I am confused with its implementation.

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 30 Apr 2021, 10:36 last edited by
    #4

    @PriyankaM96 Why don't you use QTimer (you even created an instance of it) instead of blocking event loop?

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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PriyankaM96
      wrote on 30 Apr 2021, 10:45 last edited by
      #5

      @jsulm said in Send multiple Can signals at the same time:

      QTimer

      The delay function is as follows. It uses Qtimer.

      void MainWindow::delay( int millisecondsToWait )
      {
          QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait );
          while( QTime::currentTime() < dieTime )
          {
              QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
          }
      }
      
      
      J 1 Reply Last reply 30 Apr 2021, 10:47
      0
      • P PriyankaM96
        30 Apr 2021, 10:45

        @jsulm said in Send multiple Can signals at the same time:

        QTimer

        The delay function is as follows. It uses Qtimer.

        void MainWindow::delay( int millisecondsToWait )
        {
            QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait );
            while( QTime::currentTime() < dieTime )
            {
                QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
            }
        }
        
        
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 30 Apr 2021, 10:47 last edited by
        #6

        @PriyankaM96 said in Send multiple Can signals at the same time:

        It uses Qtimer

        Then why do you use local event loop? Simply use timout from QTimer to send the data after given time...

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PriyankaM96
          wrote on 30 Apr 2021, 11:22 last edited by
          #7

          Okay. Thank you

          But still, I have a problem with sending two signals simultaneously.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nagesh
            wrote on 30 Apr 2021, 11:38 last edited by
            #8

            @PriyankaM96 Problem statement not understood correctly.
            At current implementation m_canDevice->writeFrame(frame); is delayed for 5.5sec
            significance of 5500msec delay?
            These 5.5sec delay will be there for each framewrite...

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PriyankaM96
              wrote on 30 Apr 2021, 11:44 last edited by PriyankaM96
              #9

              Yes, but each frame write takes that much time to avoid overwrite. As far as I tested.

              This is to send signals for a cycle number of times (cycle length is extracted for each signal from DBC file).

              I want to send two similar signals and keep it running simulataneously

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nagesh
                wrote on 1 May 2021, 00:19 last edited by
                #10

                @PriyankaM96 One approach would be as follows

                the signal is repeatedly transmitted till its cycle length
                

                signals which are having cycle length to be handled separately using QTimer
                In QTimer keep track of number of times to send it & for each timeout emit as if it needs to send 1 frame.
                emit sendFrame(frame,"1");

                P 1 Reply Last reply 3 May 2021, 06:07
                1
                • C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 1 May 2021, 08:23 last edited by
                  #11

                  Looks like your answers are not good enough, but so has the same answers so the next forum is on the road with the same outcoming I would guess :)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  P 1 Reply Last reply 3 May 2021, 06:46
                  0
                  • N nagesh
                    1 May 2021, 00:19

                    @PriyankaM96 One approach would be as follows

                    the signal is repeatedly transmitted till its cycle length
                    

                    signals which are having cycle length to be handled separately using QTimer
                    In QTimer keep track of number of times to send it & for each timeout emit as if it needs to send 1 frame.
                    emit sendFrame(frame,"1");

                    P Offline
                    P Offline
                    PriyankaM96
                    wrote on 3 May 2021, 06:07 last edited by
                    #12

                    @nagesh Yes, This can be one approach. Thanks

                    Is multithreading good for this problem?

                    1 Reply Last reply
                    0
                    • C Christian Ehrlicher
                      1 May 2021, 08:23

                      Looks like your answers are not good enough, but so has the same answers so the next forum is on the road with the same outcoming I would guess :)

                      P Offline
                      P Offline
                      PriyankaM96
                      wrote on 3 May 2021, 06:46 last edited by
                      #13

                      @Christian-Ehrlicher Yes, I have been looking for answers in different mediums, and posting in a forum was my last option. But hoping more answers :)

                      1 Reply Last reply
                      0
                      • C Online
                        C Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 3 May 2021, 06:51 last edited by
                        #14

                        We told you what to do - the first and important message is: don't block the event loop and use a QTimer.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          PriyankaM96
                          wrote on 4 May 2021, 11:23 last edited by
                          #15

                          I am sorry, being a beginner. I have tried doing it for last 2 days and I am not able to find solution. When I put Qtimer, like

                              connect(timer, &QTimer::timeout,[=]() {
                                  m_canDevice->writeFrame(frame);
                              });
                          
                              timer->setInterval(2000);
                              timer->start(5000);
                          

                          the UI doesnt respond or not able to write the frame.

                          J 1 Reply Last reply 4 May 2021, 11:29
                          0
                          • P PriyankaM96
                            4 May 2021, 11:23

                            I am sorry, being a beginner. I have tried doing it for last 2 days and I am not able to find solution. When I put Qtimer, like

                                connect(timer, &QTimer::timeout,[=]() {
                                    m_canDevice->writeFrame(frame);
                                });
                            
                                timer->setInterval(2000);
                                timer->start(5000);
                            

                            the UI doesnt respond or not able to write the frame.

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 4 May 2021, 11:29 last edited by
                            #16

                            @PriyankaM96 said in Send multiple Can signals at the same time:

                            the UI doesnt respond

                            Then you still block the event loop somewhere. Please show all relevant code.

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

                            P 1 Reply Last reply 17 May 2021, 07:12
                            0
                            • J jsulm
                              4 May 2021, 11:29

                              @PriyankaM96 said in Send multiple Can signals at the same time:

                              the UI doesnt respond

                              Then you still block the event loop somewhere. Please show all relevant code.

                              P Offline
                              P Offline
                              PriyankaM96
                              wrote on 17 May 2021, 07:12 last edited by
                              #17

                              @jsulm Sorry for the delay in reply. Had a blocking function from another class. Problem solved.

                              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