QCanbus - Peak driver - Unable to read data from CANbus
Unsolved
General and Desktop
-
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 -
@TMJJ001 said in QCanbus - Peak driver - Unable to read data from CANbus:
device->connectDevice();
What does it return?