Results 1 to 3 of 3

Thread: Sending multiple Canframes and processing it at the same time

  1. #1
    Join Date
    Apr 2021
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Sending multiple Canframes and processing it at the same time

    Currently, I am working on sending the CAN signals of type QCanBusFrame and receiving the signals accordingly. But, I am facing difficulty to send multiple signals at the same time since once a signal is sent, it repeats until its cycle length. So if I send another signal, it stays in the loop until the other signal is completed (cycle number of times)


    I want to send the signal simultaneously and see the received signals in GUI. Can I have any suggestions? is multithreading a solution for this problem?

    Qt Code:
    1. void MainWindow::sendFrame(const QCanBusFrame &frame,QString cycle)
    2. {
    3. if (!m_canDevice)
    4. return;
    5.  
    6. m_frame_list.enqueue(frame);
    7. send_frame_str = frame.toString();
    8.  
    9. int i = 1;
    10.  
    11. while (!m_frame_list.isEmpty()) {
    12.  
    13. QCanBusFrame m_frame = m_frame_list.dequeue();
    14.  
    15. while ( i <= cycle.toInt()) {
    16.  
    17. m_canDevice->writeFrame(frame);
    18.  
    19. delay(5500);
    20.  
    21. i = i+1;
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    This is my code for writing the frame and sending is done as shown below

    Qt Code:
    1. foreach(QString payload_id, payload_send_final) {
    2.  
    3. const QByteArray payload = QByteArray::fromHex(payload_id.remove(QLatin1Char(' ')).toLatin1());
    4. qDebug() << payload;
    5. frame = QCanBusFrame(frameId, payload);
    6.  
    7. if(m_ui->cycle_check->isChecked())
    8. emit sendFrame(frame,cycle_len.at(i));
    9. else
    10. emit sendFrame(frame,"1");
    11. i = i + 1;
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sending multiple Canframes and processing it at the same time

    is multithreading a solution for this problem?
    No. Allow your code to return to the Qt event loop and use the signals and slots offered by QCanBusDevice

  3. The following user says thank you to ChrisW67 for this useful post:

    PriyankaM96 (17th May 2021)

  4. #3
    Join Date
    Apr 2021
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Sending multiple Canframes and processing it at the same time

    Problem solved. Had a blocking function from another class.

Similar Threads

  1. Real time audio processing
    By Bangalaman in forum Qt Programming
    Replies: 0
    Last Post: 17th June 2014, 12:17
  2. Real time audio processing
    By Andrea993 in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 09:20
  3. Processing multiple checkboxes
    By -Kyr0s- in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2011, 12:28
  4. Replies: 3
    Last Post: 19th February 2009, 19:01
  5. sending localsystem time through port
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2007, 07:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.