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

PeakCAN receives unrecognized packages



  • Dear all,

    I tried to use the QtSerialBus with the peakcan plugin and a PCAN USB interface.

    Qt creator 4.9.0, based on Qt 5.12.2 (MSVC2017, 32bit)
    Compiler Mingw32
    Windows 10
    PCAN driver 4.1.4.16279
    PCANBasic.dll 4.3.3.239 (installed with the driver into Windows/System32) or 4.3.4.246 copied into the executable folder

    Using the software of Peak (PCAN-View or the sample shipped with the API) I can clearly read the packages on the CAN-Bus: 250kbit, base frame format, 8byte payload

    Using Qt with the plugin: following the instructions in the manual it connects successfully and I can read the messages with the valid CAN ID, but frame.isValid() returns false, frameType is UnknownFrame, hasExtendedFrameFormat is true, hasFlexibleDataRateFOrmat is true (which is, in fact, everything not correct) while frame.error() is No error and errorString is empty.
    Reading the payload().size() gives me some rather big number, toString() gives a segmentation fault.

    if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
        // plugin available
        QString errorString;
        QCanBusDevice *device = QCanBus::instance()->createDevice(
            QStringLiteral("peakcan"), QStringLiteral("usb0"), &errorString);
        if (!device) {
            // Error handling goes here
            qDebug << errorString;
        } else {
            device->setConfigurationParameter(QCanBusDevice::BitRateKey, 250000);
            if(device->connectDevice()) {
                QCanBusFrame frame;
                if (device->waitForFramesReceived(1000) {
                    frame = device->readFrame();
                    /** operating on frame or showing in debugger */
                }
            }
        }
    }
    

    Made I any mistakes using the plugin or is this any incompatibility with the driver and the plugin as older threads in the forum suggest?


  • Lifetime Qt Champion

    Hi @ChristophFroe,

    you should try the CAN example first. You can also find it in QtCreator in the examples section.

    device->waitForFramesReceived(1000)

    This function is not thought to be called from the GUI thread and might give unexpected results there.

    Use the framesReceived signal instead, as shown in the example I mentioned above.

    Regards



  • Thank you for giving me the hint to the example, this one worked immediately.

    After some investigation I found the culprit in my project (an existing project for a test rig): the compiler flag

    -mno-ms-bitfields
    

    influences the can plugin (what makes sense actually).
    I reconfigured the other communication module to avoid the necessity of the compiler option, and both work fine now.



  • @ChristophFroe said in PeakCAN receives unrecognized packages:

    work fine now

    so please don't forget to mark your post as solved! thanks.


Log in to reply