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. QT6 QCanBus not decoding Frames correctly.
Forum Updated to NodeBB v4.3 + New Features

QT6 QCanBus not decoding Frames correctly.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6qcanbusqcanbusdevicemacqt6.4.3
2 Posts 1 Posters 400 Views
  • 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.
  • G Offline
    G Offline
    Guy Radford
    wrote on 9 May 2023, 12:52 last edited by
    #1

    I am using a Mac and have followed the https://doc.qt.io/qt-6/macos.html & https://doc.qt.io/qt-6/qtserialbus-peakcan-overview.html documentation.

    I am using QT6.4.1 for MacOS.

    When QT receives a Can Frame it is decoding the data incorrectly.

    On my Mac, the CAN data is being correctly displayed when receiving the CAN Data via Python or the MacCAN Monitor tool. The IDs are correct, the payload length is correct and the data is correct. (The actual payload will vary slightly over time and therefore the actual data within the payload varies slightly, but the shape of the data is consistent.)

    Example Python Output:

    ID=00A LEN=8 DATA=[00 00 47 0A 6E 02 00 00]
    ID=00B LEN=8 DATA=[E9 2F 4D 42 0E 67 AC BE]
    ID=00A LEN=8 DATA=[00 00 47 0A 6D 02 00 00]
    ID=00B LEN=8 DATA=[E9 2F 4D 42 28 66 AC BE]
    ID=002 LEN=2 DATA=[06 3A 00 00 00 00 00 00]
    ID=00A LEN=8 DATA=[00 00 47 0A 6A 02 00 00]
    ID=00B LEN=8 DATA=[EA 2F 4D 42 CA 65 AC BE]
    ID=00A LEN=8 DATA=[00 00 47 0A 6E 02 00 00]
    

    With QT I am getting the following with qDebug() << canFrame.toString() << " Payload: " << canFrame.payload(); (Full code below)

    "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
    "     00B  [66]  Remote Request"  Payload:  "\x06^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
    "     00B  [66]  Remote Request"  Payload:  "\x06^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "     002   [0]"  Payload:  ""
    "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
    "     00B  [66]  Remote Request"  Payload:  "\x07^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
    "     00B  [66]  Remote Request"  Payload:  "\x07^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
    "     00B  [66]  Remote Request"  Payload:  "\t^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "0000000A   [6]  E4 00 00 00 00 00"  Payload:  "\xE4\x00\x00\x00\x00\x00"
    

    I am expecting the following:
    Frame ID 0x02 to have a length of 2, not 0 bytes.
    Frame ID 0x0A to have a length of 8, not 6 bytes.
    Frame ID 0x0B to have a length of 8, not 66 bytes.

    None of the Frame IDs are extended, yet QCanBus is reporting 0x0A as extended.

    Here is the code used to generate the above QT output:

    CanBusTest.pro

    QT += quick serialbus
    
    SOURCES += \
            main.cpp
    
    resources.files = main.qml 
    resources.prefix = /$${TARGET}
    RESOURCES += resources
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
    

    main.cpp

    #include <QCanBus>
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    class FrameReceiver : public QObject {
      public:
        FrameReceiver(QObject *parent = nullptr, QCanBusDevice *device = nullptr) {
            this->device = device;
            connect(device, &QCanBusDevice::framesReceived, this, &FrameReceiver::onNewFrame);
        }
      public slots:
        void onNewFrame(void) {
            while (this->device->framesAvailable()) {
                QCanBusFrame canFrame = this->device->readFrame();
                qDebug() << canFrame.toString() << " Payload: " << canFrame.payload();
    
            }
        }
    
      private:
        QCanBusDevice *device;
    };
    
    int main(int argc, char *argv[]) {
        QGuiApplication app(argc, argv);
    
        QString errorString;
        QCanBusDevice *device =
            QCanBus::instance()->createDevice(QStringLiteral("peakcan"), QStringLiteral("usb0"), &errorString);
    
        device->setConfigurationParameter(QCanBusDevice::BitRateKey, QVariant::fromValue(250000));
        qDebug() << "Can Device: " << device;
        device->connectDevice();
    

    Thank you for your help.

    G 1 Reply Last reply 11 May 2023, 10:24
    0
    • G Guy Radford
      9 May 2023, 12:52

      I am using a Mac and have followed the https://doc.qt.io/qt-6/macos.html & https://doc.qt.io/qt-6/qtserialbus-peakcan-overview.html documentation.

      I am using QT6.4.1 for MacOS.

      When QT receives a Can Frame it is decoding the data incorrectly.

      On my Mac, the CAN data is being correctly displayed when receiving the CAN Data via Python or the MacCAN Monitor tool. The IDs are correct, the payload length is correct and the data is correct. (The actual payload will vary slightly over time and therefore the actual data within the payload varies slightly, but the shape of the data is consistent.)

      Example Python Output:

      ID=00A LEN=8 DATA=[00 00 47 0A 6E 02 00 00]
      ID=00B LEN=8 DATA=[E9 2F 4D 42 0E 67 AC BE]
      ID=00A LEN=8 DATA=[00 00 47 0A 6D 02 00 00]
      ID=00B LEN=8 DATA=[E9 2F 4D 42 28 66 AC BE]
      ID=002 LEN=2 DATA=[06 3A 00 00 00 00 00 00]
      ID=00A LEN=8 DATA=[00 00 47 0A 6A 02 00 00]
      ID=00B LEN=8 DATA=[EA 2F 4D 42 CA 65 AC BE]
      ID=00A LEN=8 DATA=[00 00 47 0A 6E 02 00 00]
      

      With QT I am getting the following with qDebug() << canFrame.toString() << " Payload: " << canFrame.payload(); (Full code below)

      "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
      "     00B  [66]  Remote Request"  Payload:  "\x06^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
      "     00B  [66]  Remote Request"  Payload:  "\x06^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "     002   [0]"  Payload:  ""
      "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
      "     00B  [66]  Remote Request"  Payload:  "\x07^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
      "     00B  [66]  Remote Request"  Payload:  "\x07^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "0000000A   [6]  E3 00 00 00 00 00"  Payload:  "\xE3\x00\x00\x00\x00\x00"
      "     00B  [66]  Remote Request"  Payload:  "\t^\xAC\xBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xC4\x00\x00`\x00\x00\x10/!\x00\x00`\x00\x00)\x00@\xFF""e>'\xB8\n\x00\x00 E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "0000000A   [6]  E4 00 00 00 00 00"  Payload:  "\xE4\x00\x00\x00\x00\x00"
      

      I am expecting the following:
      Frame ID 0x02 to have a length of 2, not 0 bytes.
      Frame ID 0x0A to have a length of 8, not 6 bytes.
      Frame ID 0x0B to have a length of 8, not 66 bytes.

      None of the Frame IDs are extended, yet QCanBus is reporting 0x0A as extended.

      Here is the code used to generate the above QT output:

      CanBusTest.pro

      QT += quick serialbus
      
      SOURCES += \
              main.cpp
      
      resources.files = main.qml 
      resources.prefix = /$${TARGET}
      RESOURCES += resources
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
      

      main.cpp

      #include <QCanBus>
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      class FrameReceiver : public QObject {
        public:
          FrameReceiver(QObject *parent = nullptr, QCanBusDevice *device = nullptr) {
              this->device = device;
              connect(device, &QCanBusDevice::framesReceived, this, &FrameReceiver::onNewFrame);
          }
        public slots:
          void onNewFrame(void) {
              while (this->device->framesAvailable()) {
                  QCanBusFrame canFrame = this->device->readFrame();
                  qDebug() << canFrame.toString() << " Payload: " << canFrame.payload();
      
              }
          }
      
        private:
          QCanBusDevice *device;
      };
      
      int main(int argc, char *argv[]) {
          QGuiApplication app(argc, argv);
      
          QString errorString;
          QCanBusDevice *device =
              QCanBus::instance()->createDevice(QStringLiteral("peakcan"), QStringLiteral("usb0"), &errorString);
      
          device->setConfigurationParameter(QCanBusDevice::BitRateKey, QVariant::fromValue(250000));
          qDebug() << "Can Device: " << device;
          device->connectDevice();
      

      Thank you for your help.

      G Offline
      G Offline
      Guy Radford
      wrote on 11 May 2023, 10:24 last edited by Guy Radford 5 Nov 2023, 10:24
      #2

      @Guy-Radford

      This appears to be a bug as the CAN Frames are decoded correctly on a windows machine, I have raised a Bug report with QT:

      https://bugreports.qt.io/browse/QTBUG-113538

      1 Reply Last reply
      0

      1/2

      9 May 2023, 12:52

      • Login

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