Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113538

QCanBus not decoding CAN Frames correctly on Mac.

    XMLWordPrintable

Details

    • macOS
    • This is an issue with me using the wrong version Mac Peak library., fce250b42 (dev), 406591f36 (6.6), 1aa62c5b0 (6.5)

    Description

      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.3 for MacOS.

      When QT receives a Can Frame it is decoding the data incorrectly, running the same code on Windows, it works correctly.

      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();
      
          FrameReceiver *frameReceiver = new FrameReceiver(nullptr, device);
      
          QQmlApplicationEngine engine;
          const QUrl url(u"qrc:/CanBusTest/main.qml"_qs);
          QObject::connect(
              &engine, &QQmlApplicationEngine::objectCreated, &app,
              [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
              },
              Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      } 

       

      Attachments

        For Gerrit Dashboard: QTBUG-113538
        # Subject Branch Project Status CR V

        Activity

          People

            aha_1980 André Hartmann
            guyradford_sunswap Guy Radford
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes