IMX8 Reading canbus interface problem
-
Hello,
I would like to use can interface in IMX8 board.I hooked up the can0 and can1 interfaces each other. The canbus interface is working when I make loopback test. I wrote two different console apps which are for reading and writing. My reading application is not working . When I write the data from one of canbus interfaces , I couldn't read the data from another canbus interface.The loopback test commands:
ip link set can0 up type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
ifconfig can0 up
ip link set can1 up type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
ifconfig can1 upcandump can1
cansend can0 5A1#11.22.33.44.55.66.77.88
killall candumpcandump can0
cansend can1 5A1#11.22.33.44.55.66.77.88My read application is below:
#include <QCoreApplication>
#include <QDebug>
#include <QCanBusDevice>
#include <QCanBusDeviceInfo>
#include <QCanBus>
#include <QString>
#include <QThread>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString canbus_interface;QList<QCanBusDevice::Filter> list; QCanBusDevice::Filter f; if(argc != 2) { qDebug() << "The usage : ./Program_name can0/or/can1/interface"; qDebug() << "Example : ./read_canbus can0"; } if(argc == 2) { canbus_interface = argv[1]; } if (QCanBus::instance()->plugins().contains(QStringLiteral("socketcan"))) { qDebug() << "Plugin is avaliable"; } QString errorString; QCanBusDevice *device = QCanBus::instance()->createDevice( QStringLiteral("socketcan"), canbus_interface, &errorString); if (!device) { qDebug() << errorString; } else { device->connectDevice(); qDebug() << "Device connected"; } while(true){ while (device->framesAvailable()) { const QCanBusFrame frame = device->readFrame(); QString view; if (frame.frameType() == QCanBusFrame::ErrorFrame){ view = device->interpretErrorFrame(frame); qDebug() << "Frame error "; } else{ view = frame.toString(); qDebug() << "Frame available " << view; } } QThread::msleep(10); }
How can I handle that ? Thanks in advanced.
-
Did you read a documentation at all? Did you see a set of waitForXX methods?
UPD: Please, read the documentation about how the Qt and its event-loop works at all.
-
No comments...
-
@hixboz said in IMX8 Reading canbus interface problem:
I couldnt get any frame . What are the possible causes of getting not any frame? I dont think is not related with waitForXX methods?
Your application can not work as it is!
QCanBus, like all QObject based classes, needs a working event loop.
The event loop is need to made work the signals/slots feature of the QObject.Please start with reading documentation and follow the suggestions given @Pablo-J-Rogina, first try out the CAN Bus example application: https://doc.qt.io/qt-5/qtserialbus-can-example.html
Here is an example of a minimal console application: http://treyweaver.blogspot.com/2013/02/qt-console-application-template-tutorial.html
-
https://code.woboq.org/qt5/qtserialbus/src/tools/canbusutil is a command line CAN example