Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCanBus on Qt5.8



  • Hi!

    When visiting the main page of Qt5.8, we can read "Fast & easy integration and communication with devices and peripherals using Qt Serial Bus API".

    My problem is quite simple: my CAN connection works well with Qt5.7, but fails with Qt5.8.
    I'm using a PEAK device, and I follow this example. It's a little bit different from the Qt5.7 version. e.g QCanBus::instance()->plugins() returns a QStringList in Qt5.8 while it returned a QByteArray in Qt5.7 but anyway, I modified my code to match with these new prototypes.

    Here is a sample of my code:

     if(QCanBus::instance()->plugins().contains(QStringLiteral("peakcan")))
        {
            foreach (QString bus, listBus) //listBus contains usbbus0, usbbus1, usbbus2,...
            {
                device = QCanBus::instance()->createDevice("peakcan", bus);
    
                if(device!=nullptr)
                {
                    // apply filters
                    device->setConfigurationParameter(QCanBusDevice::BitRateKey, 500000);//500kbits/s
                    device->setConfigurationParameter(QCanBusDevice::ReceiveOwnKey, false); //readonly
                    device->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(filterList));
    
                    if(device->connectDevice()) /******returns false******/
                    {
                        //blablabla
                    }
                }
    

    connectDevice() always returns false, and I really don't get why.
    Any help would be appreciated, thank you in advance!

    Arnaud



  • Ok, I finally used the peak lib instead of QCanBus, where it is possible to use the filters and much more options.

    Thank you all!


  • Lifetime Qt Champion

    Hi,

    I haven't used that module yet but did you try to print the value returned by QCanBusDevice::errorString ?



  • said in QCanBus on Qt5.8:

    connectDevice() always returns false, and I really don't get why.

    Did you read documentation? The PeakCAN still supports only one property as QCanBusDevice::BitRateKey!



  • Ok, I finally used the peak lib instead of QCanBus, where it is possible to use the filters and much more options.

    Thank you all!


Log in to reply