PDA

View Full Version : Sending multiple Canframes and processing it at the same time



PriyankaM96
30th April 2021, 09:37
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?



void MainWindow::sendFrame(const QCanBusFrame &frame,QString cycle)
{
if (!m_canDevice)
return;

m_frame_list.enqueue(frame);
send_frame_str = frame.toString();

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;
}
}
}

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



foreach(QString payload_id, payload_send_final) {

const QByteArray payload = QByteArray::fromHex(payload_id.remove(QLatin1Char( ' ')).toLatin1());
qDebug() << payload;
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;
}

ChrisW67
5th May 2021, 02:47
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

PriyankaM96
17th May 2021, 08:11
Problem solved. Had a blocking function from another class.