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 - Peak driver - Unable to read data from CANbus

QCanbus - Peak driver - Unable to read data from CANbus

Scheduled Pinned Locked Moved Unsolved General and Desktop
canbus
6 Posts 3 Posters 957 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.
  • T Offline
    T Offline
    TMJJ001
    wrote on 18 Jul 2022, 13:32 last edited by
    #1

    Dear,

    I have some very basic code where I just want to see a qDebug message when I receive a message on the Canbus.
    I'm using the Peak CAN-USB adapter and QCanbus.

    For some reason the "&QCanBusDevice::framesReceived" is not triggered. First I thought it would be a .dll issue or driver issue.
    When I use the SAVVYCAN source code (https://github.com/collin80/SavvyCAN) I do receive the data. So it seems like I'm just doing something wrong in the code.

    
    void Canbus::setupDevice()
    {
        qDebug() << "connectCanDevice";
        //Check if Peakcan plugin is available
        if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
            qDebug() << "Peakcan plugin is existing";
        }
    
        QString errorString;
        device = QCanBus::instance()->createDevice(
            QStringLiteral("peakcan"), QStringLiteral("usb0"), &errorString);
        if (!device) {
            // Error handling goes here
            qDebug() << errorString;
        } else {
            qDebug() << "Device is Ready";
            setBitrate();
        }
    }
    
    void Canbus::setBitrate()
    {
        qDebug() << "Set bitrate";
        device->setConfigurationParameter(QCanBusDevice::BitRateKey,250000);
        connectCanDevice();
    }
    
    void Canbus::connectCanDevice()
    {
    
        connect(device,&QCanBusDevice::framesReceived,this,&Canbus::dataReceived);
        connect(device,&QCanBusDevice::errorOccurred, this,&Canbus::processErrors);
        qDebug() << "connect the device";
        device->connectDevice();
    
    
    }
    
    void Canbus::dataReceived()
    {
        qDebug()<< "data received";
    }
    
    void Canbus::processErrors(QCanBusDevice::CanBusError error)
    {
        switch (error) {
        case QCanBusDevice::ReadError:
        case QCanBusDevice::WriteError:
        case QCanBusDevice::ConnectionError:
        case QCanBusDevice::ConfigurationError:
        case QCanBusDevice::UnknownError:
            qDebug() << "ERROR:" + device->errorString();
            break;
        default:
            break;
        }
    }
    
    

    Anybody an idea what the reason could be?
    I'm using Qt5.15.2.

    Thanks in advance,
    Kind regards,
    Toon

    J 1 Reply Last reply 19 Jul 2022, 05:52
    0
    • T TMJJ001
      18 Jul 2022, 13:32

      Dear,

      I have some very basic code where I just want to see a qDebug message when I receive a message on the Canbus.
      I'm using the Peak CAN-USB adapter and QCanbus.

      For some reason the "&QCanBusDevice::framesReceived" is not triggered. First I thought it would be a .dll issue or driver issue.
      When I use the SAVVYCAN source code (https://github.com/collin80/SavvyCAN) I do receive the data. So it seems like I'm just doing something wrong in the code.

      
      void Canbus::setupDevice()
      {
          qDebug() << "connectCanDevice";
          //Check if Peakcan plugin is available
          if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
              qDebug() << "Peakcan plugin is existing";
          }
      
          QString errorString;
          device = QCanBus::instance()->createDevice(
              QStringLiteral("peakcan"), QStringLiteral("usb0"), &errorString);
          if (!device) {
              // Error handling goes here
              qDebug() << errorString;
          } else {
              qDebug() << "Device is Ready";
              setBitrate();
          }
      }
      
      void Canbus::setBitrate()
      {
          qDebug() << "Set bitrate";
          device->setConfigurationParameter(QCanBusDevice::BitRateKey,250000);
          connectCanDevice();
      }
      
      void Canbus::connectCanDevice()
      {
      
          connect(device,&QCanBusDevice::framesReceived,this,&Canbus::dataReceived);
          connect(device,&QCanBusDevice::errorOccurred, this,&Canbus::processErrors);
          qDebug() << "connect the device";
          device->connectDevice();
      
      
      }
      
      void Canbus::dataReceived()
      {
          qDebug()<< "data received";
      }
      
      void Canbus::processErrors(QCanBusDevice::CanBusError error)
      {
          switch (error) {
          case QCanBusDevice::ReadError:
          case QCanBusDevice::WriteError:
          case QCanBusDevice::ConnectionError:
          case QCanBusDevice::ConfigurationError:
          case QCanBusDevice::UnknownError:
              qDebug() << "ERROR:" + device->errorString();
              break;
          default:
              break;
          }
      }
      
      

      Anybody an idea what the reason could be?
      I'm using Qt5.15.2.

      Thanks in advance,
      Kind regards,
      Toon

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Jul 2022, 05:52 last edited by
      #2

      @TMJJ001 said in QCanbus - Peak driver - Unable to read data from CANbus:

      device->connectDevice();

      What does it return?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 19 Jul 2022, 07:12
      0
      • S Offline
        S Offline
        SPlatten
        wrote on 19 Jul 2022, 06:02 last edited by
        #3

        @TMJJ001 , are you sure the baud rate is correct? There are several settings you need to ensure are correct, like data bits, stop bits, baud and parity.

        Kind Regards,
        Sy

        T 1 Reply Last reply 19 Jul 2022, 07:14
        0
        • J jsulm
          19 Jul 2022, 05:52

          @TMJJ001 said in QCanbus - Peak driver - Unable to read data from CANbus:

          device->connectDevice();

          What does it return?

          T Offline
          T Offline
          TMJJ001
          wrote on 19 Jul 2022, 07:12 last edited by
          #4

          @jsulm

          Yes, it returns true. So the device is connected. The SIGNAL "&QCanBusDevice::framesReceived" is not transmitted.

          Thanks!

          1 Reply Last reply
          0
          • S SPlatten
            19 Jul 2022, 06:02

            @TMJJ001 , are you sure the baud rate is correct? There are several settings you need to ensure are correct, like data bits, stop bits, baud and parity.

            T Offline
            T Offline
            TMJJ001
            wrote on 19 Jul 2022, 07:14 last edited by
            #5

            @SPlatten

            Yes baudrate is correct, I'm sending with another computer and PCanview data on the bus.
            The parameters databits, stop bits and parity, isn't this only for serial communication?

            S 1 Reply Last reply 21 Jul 2022, 13:50
            0
            • T TMJJ001
              19 Jul 2022, 07:14

              @SPlatten

              Yes baudrate is correct, I'm sending with another computer and PCanview data on the bus.
              The parameters databits, stop bits and parity, isn't this only for serial communication?

              S Offline
              S Offline
              SPlatten
              wrote on 21 Jul 2022, 13:50 last edited by
              #6

              @TMJJ001 , depends on the network medium, like other protocols, CANbus is a protocol that can be used on multi-drop serial connections like RS422 and RS485, in both these cases then the serial parameters are relevant.

              Kind Regards,
              Sy

              1 Reply Last reply
              0

              2/6

              19 Jul 2022, 05:52

              4 unread
              • Login

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