QCanBus together with a PCAN-USB interface from PEAK-System
-
I’m actually trying to use class QCanBus together with a PCAN-USB interface from PEAK-System, but it doesn‘t work, although I follow the Qt guideline on http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html.
According to debug output the peakcan interface will be available, i get a handle
from createDevice(…), but m_canDevice->connectDevice()) always returns false.if (QCanBus::instance()->plugins().contains(QByteArray("peakcan"))) { qDebug() << "plugin \"peakcan\" available "; } qDebug() << "Trying to connect......."; m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0"); if (!m_canDevice) { qDebug() << "createDevice failed"; return; } //m_canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey, 1000000); if (!m_canDevice->connectDevice()) { delete m_canDevice; m_canDevice = nullptr; qDebug() << "connectDevice failed"; return; }
Using log feature of PCANBasic-DLL, I see, wrong parameters will be used to initialize the PCAN-USB:
«____________________________________» « PCAN-Basic Log » <<<<< 32-Bit API V. 4.3.0.150 >>>>> «____________________________________»
Thu Mar 22 11:05:31.533 - [2684] EINGANG 'CAN_Initialize'
Thu Mar 22 11:05:31.533 - [2684] PARAMETER von CAN_Initialize - Channel: 0x00, Baudrate: 0x001C, HwType: 0x00, IOPort: 0x0, Interrupt: 0
Thu Mar 22 11:05:31.561 - [2684] AUSGANG 'CAN_Initialize' - ERGEBNIS: 0x1C00
Thu Mar 22 11:05:31.561 - [2684] EINGANG 'CAN_GetErrorText'
Thu Mar 22 11:05:31.561 - [2684] PARAMETER von CAN_GetErrorText - Error: 0x00001C00, Language: 0, Buffer: 0x20CAAD90
Thu Mar 22 11:05:31.563 - [2684] AUSGANG 'CAN_GetErrorText' - ERGEBNIS: 0x00"Channel: 0x00" is wrong here, should be 0x51!
How can I guide Qt to use correct parameters?
-
Sorry for the missing informations:
Window10 Version 1709 (Build 16299,248)
Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
=>
C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 providedHi @apexul,
thanks for the information.
Please update your Qt version to 5.9.4 or 5.10.1.
CAN bus was technology preview in 5.6 and 5.7 and I changed quite a lot since then, e.g. the
errorMessage
parameter tocreateDevice
.If you run the CAN example from 5.9 upwards, it will even show you which CAN channels are available :)
Best regards.
PS: if you insist not to update Qt, then replace "usb0" with "usbbus1" in your code. But I can guarantee you won't get happy with this old release.
-
Hi @apexul,
- Which Qt version are you using?
- Which PCAN-Basic version?
- Which Operating System?
m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0");
if (!m_canDevice) {
qDebug() << "createDevice failed";
return;
}Please change that code to:
QString erroMessage; m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage); if (!m_canDevice) { qDebug() << "createDevice failed:" << errorMessage; return; }
and come back with the output. Thanks.
PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.
-
Sorry for the missing informations:
Window10 Version 1709 (Build 16299,248)
Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
=>
C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 provided -
Also
if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
// plugin available
}taken from http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html doesn't compile,
I have usedif (QCanBus::instance()->plugins().contains(QByteArray))) {
// plugin available
}instead.
-
Sorry for the missing informations:
Window10 Version 1709 (Build 16299,248)
Qt5.7.1 (MSVC 2015, 32bit) / Qt Creator 4.2.0m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage);
=>
C:\Users\RC459_UL\imager2D\accessories-utils\cblhostswutility\mainwindow.cpp:128: Fehler: no matching function for call to 'QCanBus::createDevice(QByteArray, const QString&, QString*)'
C:\Qt\5.7\mingw53_32\include\QtSerialBus\qcanbus.h:56: note: candidate expects 2 arguments, 3 providedHi @apexul,
thanks for the information.
Please update your Qt version to 5.9.4 or 5.10.1.
CAN bus was technology preview in 5.6 and 5.7 and I changed quite a lot since then, e.g. the
errorMessage
parameter tocreateDevice
.If you run the CAN example from 5.9 upwards, it will even show you which CAN channels are available :)
Best regards.
PS: if you insist not to update Qt, then replace "usb0" with "usbbus1" in your code. But I can guarantee you won't get happy with this old release.
-
Also
if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
// plugin available
}taken from http://doc.qt.io/qt-5/qtserialbus-peakcan-overview.html doesn't compile,
I have usedif (QCanBus::instance()->plugins().contains(QByteArray))) {
// plugin available
}instead.
@apexul said in QCanBus together with a PCAN-USB interface from PEAK-System:
if (QCanBus::instance()->plugins().contains(QStringLiteral("peakcan"))) {
// plugin available
}This is another change from the tech preview to the final version:
// Qt 5.7 version if (QCanBus::instance()->plugins().contains("peakcan")) { // plugin available }
-
Hi @apexul,
- Which Qt version are you using?
- Which PCAN-Basic version?
- Which Operating System?
m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0");
if (!m_canDevice) {
qDebug() << "createDevice failed";
return;
}Please change that code to:
QString erroMessage; m_canDevice = QCanBus::instance()->createDevice("peakcan", "usb0", &errorMessage); if (!m_canDevice) { qDebug() << "createDevice failed:" << errorMessage; return; }
and come back with the output. Thanks.
PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.
@aha_1980 said in QCanBus together with a PCAN-USB interface from PEAK-System:
PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.
The Code I got from another team member is almost identical with the example from Qt 5.7.1
I've now updated Qt to 5.10.1 and compiled the example provided by it - it works fine!
Thx
-
@aha_1980 said in QCanBus together with a PCAN-USB interface from PEAK-System:
PS: Have you already tried the CAN example? I use it regularly in conjunction with Peak adapters.
The Code I got from another team member is almost identical with the example from Qt 5.7.1
I've now updated Qt to 5.10.1 and compiled the example provided by it - it works fine!
Thx
-
Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!
-
Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!
@apexul said in QCanBus together with a PCAN-USB interface from PEAK-System:
Stupid - I can't mark post https://forum.qt.io/topic/89087/qcanbus-together-with-a-pcan-usb-interface-from-peak-system/5 as the correct answer!
Maybe a bug :)