Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. IMX8 Reading canbus interface problem
Forum Updated to NodeBB v4.3 + New Features

IMX8 Reading canbus interface problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hixboz
    wrote on 17 Jun 2019, 09:52 last edited by
    #1

    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 up

    candump can1
    cansend can0 5A1#11.22.33.44.55.66.77.88
    killall candump

    candump can0
    cansend can1 5A1#11.22.33.44.55.66.77.88

    My 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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 17 Jun 2019, 10:11 last edited by kuzulis
      #2

      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.

      P 1 Reply Last reply 19 Jun 2019, 14:12
      2
      • H Offline
        H Offline
        hixboz
        wrote on 19 Jun 2019, 08:53 last edited by
        #3

        I couldnt get any frame . What are the possible causes of getting not any frame? I dont think is not related with waitForXX methods?

        K 1 Reply Last reply 19 Jun 2019, 14:23
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on 19 Jun 2019, 09:28 last edited by kuzulis
          #4

          No comments...

          1 Reply Last reply
          0
          • K kuzulis
            17 Jun 2019, 10:11

            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.

            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 19 Jun 2019, 14:12 last edited by Pablo J. Rogina
            #5

            @hixboz have you already tried the CAN Bus example?

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1
            • H hixboz
              19 Jun 2019, 08:53

              I couldnt get any frame . What are the possible causes of getting not any frame? I dont think is not related with waitForXX methods?

              K Offline
              K Offline
              KroMignon
              wrote on 19 Jun 2019, 14:23 last edited by
              #6

              @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

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              2
              • aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 19 Jun 2019, 17:37 last edited by
                #7

                https://code.woboq.org/qt5/qtserialbus/src/tools/canbusutil is a command line CAN example

                Qt has to stay free or it will die.

                1 Reply Last reply
                0

                1/7

                17 Jun 2019, 09:52

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved