CAN BUS, SocketCAN cannot read CAN frames
Unsolved
General and Desktop
-
Hi,
I have troubles reading CAN frames using readFrame() method.
My code for initialization:
#include <QCanBusFrame> #include <QCanBus> #include <QCanBusDevice> CANSend::CANSend(QString interface){ CANdevice = QCanBus::instance()->createDevice("socketcan", interface); if (!CANdevice->connectDevice()) {} }
code for sending data - everything works correctly
void CANSend::send_pos(uint16_t pos) { QCanBusFrame frame; frame.setFrameId(1024); QByteArray payload; payload[0]=0; payload[1]=pos>>8; payload[2]=pos; frame.setPayload(payload); CANdevice->writeFrame(frame); }
code for reading data
int CANSend::check_messages(){ const QCanBusFrame frame = CANdevice->readFrame(); const qint8 dataLength = frame.payload().size(); const qint32 id = frame.frameId(); return id; }
during debugging I always get
frame = @0x7fffffffdf10,
dataLength = 0,
id = 0,So, even though I can clearly see incomming packets via candump command and also in QT CANBUS example, I never receive anything.
Can you help me? Thanks.
-
Hi and welcome to devnet,
The module being pretty new (maybe even technical preview), I'd recommend posting this question on the interest mailing list. You'll find there QtCanBus developers/maintainers. This forum is more user oriented.