Send multiple Can signals at the same time
-
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
-
@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) -
@PriyankaM96 Why don't you use QTimer (you even created an instance of it) instead of blocking event loop?
-
@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 ); } }
-
@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...
-
Okay. Thank you
But still, I have a problem with sending two signals simultaneously.
-
@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... -
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
-
@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"); -
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 :)
-
@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 :)
-
We told you what to do - the first and important message is: don't block the event loop and use a QTimer.
-
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.
-
@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.