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
Forum Updated to NodeBB v4.3 + New Features

QCanbus - Peak driver - Unable to read data from CANbus

Scheduled Pinned Locked Moved Unsolved General and Desktop
canbus
6 Posts 3 Posters 985 Views 1 Watching
  • 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 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

    jsulmJ 1 Reply Last reply
    0
    • T TMJJ001

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      0
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on 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
        0
        • jsulmJ jsulm

          @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 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
          • SPlattenS SPlatten

            @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 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?

            SPlattenS 1 Reply Last reply
            0
            • T TMJJ001

              @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?

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on 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

              • Login

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