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. [CAN BUS](SocketCAN cannot read CAN frames)
Forum Updated to NodeBB v4.3 + New Features

[CAN BUS](SocketCAN cannot read CAN frames)

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 439 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.
  • E Offline
    E Offline
    EngElectronic
    wrote on 2 Dec 2019, 00:11 last edited by
    #1

    https://forum.qt.io/topic/101710/qt-canbus-systec-can-can-t-read-can-frames
    https://forum.qt.io/topic/69635/can-bus-socketcan-cannot-read-can-frames

    Hi, I have same problem that topics above. I can send but I can't read frames.
    I did tests with can and vcan. Bellow my code:

    #include <QCanBusFrame>
    #include <QCanBus>
    #include <QCanBusDevice>

    int main(int argc, char *argv[])
    {

    /* CAN */
    if (QCanBus::instance()->plugins().contains(QStringLiteral("socketcan"))) {
        // plugin available
    }
    
    QCanBusDevice *device = QCanBus::instance()->createDevice(
        QStringLiteral("socketcan"), QStringLiteral("vcan1"));
    device->connectDevice();
    
    QCanBusFrame frame;
    frame.setFrameId(0x1A5A5A);
    QByteArray payload("00001111");
    frame.setPayload(payload);
    device->writeFrame(frame);
    
    while(!device){}
    
    while(true)
    {
        if (device->framesAvailable())
        {
            const QCanBusFrame frameRx = device->readFrame();
            break;
        }
    }
    
    return app.exec();
    

    }

    J 1 Reply Last reply 2 Dec 2019, 04:32
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 2 Dec 2019, 04:09 last edited by kuzulis 12 Feb 2019, 04:09
      #2

      Your code is stupid and wrong. Read the documentation and take a look the examples at first, before posting something on a forum.

      1 Reply Last reply
      -4
      • E EngElectronic
        2 Dec 2019, 00:11

        https://forum.qt.io/topic/101710/qt-canbus-systec-can-can-t-read-can-frames
        https://forum.qt.io/topic/69635/can-bus-socketcan-cannot-read-can-frames

        Hi, I have same problem that topics above. I can send but I can't read frames.
        I did tests with can and vcan. Bellow my code:

        #include <QCanBusFrame>
        #include <QCanBus>
        #include <QCanBusDevice>

        int main(int argc, char *argv[])
        {

        /* CAN */
        if (QCanBus::instance()->plugins().contains(QStringLiteral("socketcan"))) {
            // plugin available
        }
        
        QCanBusDevice *device = QCanBus::instance()->createDevice(
            QStringLiteral("socketcan"), QStringLiteral("vcan1"));
        device->connectDevice();
        
        QCanBusFrame frame;
        frame.setFrameId(0x1A5A5A);
        QByteArray payload("00001111");
        frame.setPayload(payload);
        device->writeFrame(frame);
        
        while(!device){}
        
        while(true)
        {
            if (device->framesAvailable())
            {
                const QCanBusFrame frameRx = device->readFrame();
                break;
            }
        }
        
        return app.exec();
        

        }

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 2 Dec 2019, 04:32 last edited by
        #3

        @EngElectronic said in [CAN BUS](SocketCAN cannot read CAN frames):

        while(true)
        

        An infinite while while loop blocks the event processor which prevents you from sending or receiving frames.

        There are other issues in your code too. Follow the working example to learn how to use QCanBusDevice correctly: https://doc.qt.io/qt-5/qtserialbus-can-example.html

        @kuzulis, there is no need and no benefit in being nasty.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        5

        3/3

        2 Dec 2019, 04:32

        • Login

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