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?
Code:
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
Code:
foreach
(QString payload_id, payload_send_final
) {
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;
}
Re: Sending multiple Canframes and processing it at the same time
Quote:
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
Re: Sending multiple Canframes and processing it at the same time
Problem solved. Had a blocking function from another class.