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
socketcancan busqt 5.7linux
2 Posts 2 Posters 1.6k 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.
  • lakotammL Offline
    lakotammL Offline
    lakotamm
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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