Home > Software engineering >  CAN Communication in QT
CAN Communication in QT

Time:09-24

I have a specific problem with the CAN communication in QT. It is not a problem to send/write CAN messages, but the readFrame() function in QT doesn't load my received frames. If you are implementing a CAN communication in C you can use the read() and write() functions. But in QT it is not supported. In general the read function interrupts the programm until a message is received, how can I do the same in QT?

QCanBusFrame frame = device->readFrame();

Thanks for your help, I really appreciate it!

CodePudding user response:

From the QT docs:

Returns the next QCanBusFrame from the queue; otherwise returns an empty QCanBusFrame. The returned frame is removed from the queue.

The queue operates according to the FIFO principle.

https://doc.qt.io/qt-5.12/qcanbusdevice.html#readFrame

Try first calling

bool QCanBusDevice::waitForFramesReceived(int msecs)

https://doc.qt.io/qt-5.12/qcanbusdevice.html#waitForFramesReceived

and then read frames

  • Related