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. QCanBus together with a PCAN-USB interface from PEAK-System
Forum Update on Monday, May 27th 2025

QCanBus together with a PCAN-USB interface from PEAK-System

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 3.6k 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.
  • A Offline
    A Offline
    apexul
    wrote on last edited by apexul
    #1

    I’m actually trying to use class QCanBus together with a PCAN-USB interface from PEAK-System, but it doesn‘t work, although I follow the Qt guideline on http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html.

    According to debug output the peakcan interface will be available, i get a handle
    from createDevice(…), but m_canDevice->connectDevice()) always returns false.

    if (QCanBus::instance()->plugins().contains(QByteArray("peakcan")))
    {
        qDebug() << "plugin \"peakcan\" available ";
    }
    qDebug() << "Trying to connect.......";
    m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0");
    if (!m_canDevice) {
        qDebug() <<  "createDevice failed";
        return;
    }
    
    //m_canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey, 1000000);
    if (!m_canDevice->connectDevice()) {
        delete m_canDevice;
        m_canDevice = nullptr;
        qDebug() <<  "connectDevice failed";
        return;
    }
    

    Using log feature of PCANBasic-DLL, I see, wrong parameters will be used to initialize the PCAN-USB:

                          «____________________________________»
                          «           PCAN-Basic Log           » <<<<< 32-Bit API V. 4.3.0.150 >>>>>
                          «____________________________________»
    

    Thu Mar 22 11:05:31.533 - [2684] EINGANG 'CAN_Initialize'
    Thu Mar 22 11:05:31.533 - [2684] PARAMETER von CAN_Initialize - Channel: 0x00, Baudrate: 0x001C, HwType: 0x00, IOPort: 0x0, Interrupt: 0
    Thu Mar 22 11:05:31.561 - [2684] AUSGANG 'CAN_Initialize' - ERGEBNIS: 0x1C00
    Thu Mar 22 11:05:31.561 - [2684] EINGANG 'CAN_GetErrorText'
    Thu Mar 22 11:05:31.561 - [2684] PARAMETER von CAN_GetErrorText - Error: 0x00001C00, Language: 0, Buffer: 0x20CAAD90
    Thu Mar 22 11:05:31.563 - [2684] AUSGANG 'CAN_GetErrorText' - ERGEBNIS: 0x00

    "Channel: 0x00" is wrong here, should be 0x51!

    How can I guide Qt to use correct parameters?

    1 Reply Last reply
    0
    • A apexul

      Sorry for the missing informations:
      Window10 Version 1709 (Build 16299,248)
      Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0

      m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
      =>
      C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
      C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 provided

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #5

      Hi @apexul,

      thanks for the information.

      Please update your Qt version to 5.9.4 or 5.10.1.

      CAN bus was technology preview in 5.6 and 5.7 and I changed quite a lot since then, e.g. the errorMessage parameter to createDevice.

      If you run the CAN example from 5.9 upwards, it will even show you which CAN channels are available :)

      Best regards.

      PS: if you insist not to update Qt, then replace "usb0" with "usbbus1" in your code. But I can guarantee you won't get happy with this old release.

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi @apexul,

        • Which Qt version are you using?
        • Which PCAN-Basic version?
        • Which Operating System?

        m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0");
        if (!m_canDevice) {
        qDebug() << "createDevice failed";
        return;
        }

        Please change that code to:

        QString erroMessage;
         m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
         if (!m_canDevice) {
             qDebug() <<  "createDevice failed:" << errorMessage;
             return;
         }
        

        and come back with the output. Thanks.

        PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.

        Qt has to stay free or it will die.

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          apexul
          wrote on last edited by
          #3

          Sorry for the missing informations:
          Window10 Version 1709 (Build 16299,248)
          Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0

          m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
          =>
          C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
          C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 provided

          aha_1980A 1 Reply Last reply
          0
          • A Offline
            A Offline
            apexul
            wrote on last edited by apexul
            #4

            Also

            if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
            // plugin available
            }

            taken from http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html doesn't compile,
            I have used

            if (QCanBus::instance()->plugins().contains(QByteArray))) {
            // plugin available
            }

            instead.

            aha_1980A 1 Reply Last reply
            0
            • A apexul

              Sorry for the missing informations:
              Window10 Version 1709 (Build 16299,248)
              Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0

              m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
              =>
              C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
              C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 provided

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #5

              Hi @apexul,

              thanks for the information.

              Please update your Qt version to 5.9.4 or 5.10.1.

              CAN bus was technology preview in 5.6 and 5.7 and I changed quite a lot since then, e.g. the errorMessage parameter to createDevice.

              If you run the CAN example from 5.9 upwards, it will even show you which CAN channels are available :)

              Best regards.

              PS: if you insist not to update Qt, then replace "usb0" with "usbbus1" in your code. But I can guarantee you won't get happy with this old release.

              Qt has to stay free or it will die.

              1 Reply Last reply
              2
              • A apexul

                Also

                if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
                // plugin available
                }

                taken from http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html doesn't compile,
                I have used

                if (QCanBus::instance()->plugins().contains(QByteArray))) {
                // plugin available
                }

                instead.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @apexul said in QCanBus together with a PCAN-USB interface from PEAK-System:

                if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
                // plugin available
                }

                This is another change from the tech preview to the final version:

                // Qt 5.7 version
                if (QCanBus::instance()->plugins().contains("peakcan")) {
                  // plugin available
                }
                

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • aha_1980A aha_1980

                  Hi @apexul,

                  • Which Qt version are you using?
                  • Which PCAN-Basic version?
                  • Which Operating System?

                  m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0");
                  if (!m_canDevice) {
                  qDebug() << "createDevice failed";
                  return;
                  }

                  Please change that code to:

                  QString erroMessage;
                   m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
                   if (!m_canDevice) {
                       qDebug() <<  "createDevice failed:" << errorMessage;
                       return;
                   }
                  

                  and come back with the output. Thanks.

                  PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.

                  A Offline
                  A Offline
                  apexul
                  wrote on last edited by
                  #7

                  @aha_1980 said in QCanBus together with a PCAN-USB interface from PEAK-System:

                  PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.

                  The Code I got from another team member is almost identical with the example from Qt 5.7.1

                  I've now updated Qt to 5.10.1 and compiled the example provided by it - it works fine!

                  Thx

                  aha_1980A 1 Reply Last reply
                  0
                  • A apexul

                    @aha_1980 said in QCanBus together with a PCAN-USB interface from PEAK-System:

                    PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.

                    The Code I got from another team member is almost identical with the example from Qt 5.7.1

                    I've now updated Qt to 5.10.1 and compiled the example provided by it - it works fine!

                    Thx

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Hi @apexul, glad you got it working!

                    So please mark this thread as SOLVED now. Thanks.

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      apexul
                      wrote on last edited by apexul
                      #9

                      Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!

                      aha_1980A 1 Reply Last reply
                      0
                      • A apexul

                        Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @apexul said in QCanBus together with a PCAN-USB interface from PEAK-System:

                        Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!

                        Maybe a bug :)

                        Qt has to stay free or it will die.

                        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