⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

CAN BUS, SocketCAN cannot read CAN frames

  • 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;
        QByteArray payload;

    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.

  • Lifetime Qt Champion

    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.