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;
}
}
}
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;
}
}
}
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
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;
}
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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks