Qt CanBus,SYSTEC CAN can't read CAN frames
-
Hello, I'm working on a CAN API.
I write a frame to my CAN bus device and should receive data in response. I see the received packet in CAN example API when i write that frame.
The problem is i can't read that received frame when i use QCanBusDevice::readFrame()
This is my code to read the response:QCanBusDevice *device=QCanBus::instance()->createDevice("systeccan","can1.0"); device->setConfigurationParameter(QCanBusDevice::BitRateKey,125000); device->setConfigurationParameter(QCanBusDevice::CanFdKey,false); device->connectDevice(); char data[8]={0x40,0x00,0x10,0x00,0x00,0x00,0x00,0x00}; QByteArray frame(data,8); QCanBusFrame myframe; myframe.setPayload(frame); myframe.setFrameId(0x617); qDebug()<<myframe.toString(); qDebug()<<device->writeFrame(myframe); QCanBusFrame frameR=device->readFrame(); qDebug()<<frameR.toString();
-
Hi
Did you try call
https://doc.qt.io/qt-5/qcanbusdevice.html#framesAvailable
to see if there is something to read ?Also, i think it will work better if you connect a slot
to void QCanBusDevice::framesReceived()
and there call framesAvailable and readFrame.
The way you are using it now, suggests its blocking but i think its actually async. -
@mrjj i created a function processReceivedFrames and connected it to framesReceived() function.
I still get 0 as number of available frames.
This is the way i made the connection:connect(m_device, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames,Qt::UniqueConnection);
I'm sure that data should be received i tested that in CAN example like shown in picture below:![alt text]
Regards
-
-