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

Send multiple Can signals at the same time

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.4k 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.
  • P Offline
    P Offline
    PriyankaM96
    wrote on last edited by
    #1

    Hello,

    I have been trying to send multiple CAN signals at the same time. When selecting each signal for sending, the signal is repeatedly transmitted till its cycle length and if I have to send more signals along with it, it stays in the queue. I need to run multiple signals at the same time and see their output in GUI.

    Is it possible to the above function?

    my code for emitting multiple signals is :

            foreach(QString payload_id, payload_send_final) {
                const QByteArray payload = QByteArray::fromHex(payload_id.remove(QLatin1Char(' ')).toLatin1());
                frame = QCanBusFrame(frameId, payload);
                if(m_ui->cycle_check->isChecked())
                    emit sendFrame(frame,cycle_len.at(i));
                else
                    emit sendFrame(frame,"1");
    
                i = i + 1;
            }
    

    and writing Can signal is as follows :

        m_frame_list.enqueue(frame);
        send_frame_str = frame.toString();
        QTimer timer;
        int i = 1;
    
        while (!m_frame_list.isEmpty()) {
            QCanBusFrame m_frame = m_frame_list.dequeue();
            while ( i <= cycle.toInt()) {
                m_canDevice->writeFrame(frame);
                delay(5500);
                i = i+1;
            }
        }
    

    Thank you in advance

    1 Reply Last reply
    0
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by
      #2

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

      delay(5500);

      Do you have threads in the code?
      looks like you are blocking the event loop by using the delay(5500)

      P 1 Reply Last reply
      1
      • nageshN nagesh

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

        delay(5500);

        Do you have threads in the code?
        looks like you are blocking the event loop by using the delay(5500)

        P Offline
        P Offline
        PriyankaM96
        wrote on last edited by PriyankaM96
        #3

        @nagesh Thank you for the sudden reply.

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

        jsulmJ 1 Reply Last reply
        0
        • P PriyankaM96

          @nagesh Thank you for the sudden reply.

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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 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 );
                }
            }
            
            
            jsulmJ 1 Reply Last reply
            0
            • P PriyankaM96

              @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 );
                  }
              }
              
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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 last edited by
                #7

                Okay. Thank you

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

                1 Reply Last reply
                0
                • nageshN Offline
                  nageshN Offline
                  nagesh
                  wrote on 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 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
                    • nageshN Offline
                      nageshN Offline
                      nagesh
                      wrote on 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
                      1
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 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
                        0
                        • nageshN nagesh

                          @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 last edited by
                          #12

                          @nagesh Yes, This can be one approach. Thanks

                          Is multithreading good for this problem?

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            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 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
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 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 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.

                                jsulmJ 1 Reply Last reply
                                0
                                • P PriyankaM96

                                  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.

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 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
                                  0
                                  • jsulmJ jsulm

                                    @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 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