How to use PCAN drivers or OpenCAN PCAN plugin (SOLVED?)

  • I'm trying to use the PCAN driver including it into the .pro file as follows:
    _*win32:CONFIG(release, debug|release): LIBS += -L$$PWD/PCAN-Basic API/x64/VC_LIB/ -lPCANBasic
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/PCAN-Basic API/x64/VC_LIB/ -lPCANBasicd

    INCLUDEPATH += $$PWD/PCAN-Basic API/Include
    DEPENDPATH += $$PWD/PCAN-Basic API/Include

    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/PCAN-Basic API/x64/VC_LIB/libPCANBasic.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/PCAN-Basic API/x64/VC_LIB/libPCANBasicd.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/PCAN-Basic API/x64/VC_LIB/PCANBasic.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/PCAN-Basic API/x64/VC_LIB/PCANBasicd.lib*_

    This lines are included automatically when you click in Add Library and select PCAN drivers .h and include path.
    But when I click compiler button it says me that C:\Users\jalonso\QtProy\AdquisicionCAN\adqcan.h:5: error: C1083: No se puede abrir el archivo incluir: 'PCANBasic.h': No such file or directory
    There is any solution for this problem?? What I'm doing wrong?? Maybe is easier including the PCAN plugin contained in OpenCAN pack??
    Thanks you all!!!

  • Means the compiler can't find the header-file. Please check the include-directories.

  • Is /PCAN-Basic API/Include a subdir of your project-dir C:\Users\jalonso\QtProy\AdquisicionCAN\ ? just correct the path

  • Yes, the include directory is a subdirectory of my project. And the .h file is inside it.I don't know what's the problem really.

  • Is maybe a problem of .dll location???

  • The path "$$PWD/PCAN-Basic API/Include" contains spaces...this could be the problem. Wrap it with "

  • Thanks for your help! Moving the include directory to the project directory, including in the .h file #include "windows.h" (DWORD definition) and next clearing the line in bold:
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/x64/VC_LIB/ -lPCANBasic
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/x64/VC_LIB/ -lPCANBasicd

    INCLUDEPATH += $$PWD/Include
    DEPENDPATH += $$PWD/Include
    I don't know what this line mean. But if you don't erase this line the compiler says that -lPCANBasicd can't be found.
    So the final .pro is:
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = pruebacan
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/x64/VC_LIB/ -lPCANBasic
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/x64/VC_LIB/ -lPCANBasicd

    INCLUDEPATH += $$PWD/Include
    DEPENDPATH += $$PWD/Include

    If anyone have an answer or question, please quote!

  • At first...what do you want to use? OpenCAN or just PCANBasic-API. OpenCAN needs the PCAN-Light-API and the PCAN_USB.dll while PCANBasic-API needs the PCANBasic.dll.

    I just use the PCANBASIC.dll with the include-files and no .lib-file. I'm calling the dll-functions directly. See the MFC-Sample in the PCANBASIC-Api. The sample uses the dll und and the lib only so you don't have to link the lib-file. Pretty simple.

  • But when you add the libraries you must add the .lib, no?? How Can I use the .dll?? Sorry, but I'm a noob with this, you can take me an example of this use in Qt??
    I thought than the .dll is called by the .lib, but I see I mistaked. Must I include the .dll in the include path?? or in the .exe path??
    At the moment the compiler don't give me any error, but if you say me that is better use .dll .Maybe it sounds easy for you!! But I'm only a noob!

  • Don't use the !!! so often. Take a look in at the PCAN-API. The example for Visual C++ (MFC) is the right for you. Just use the PCANBasicClass. In the class you'll find the funtion pointers to the dll. The function pointers are pointing to the corresponding function in the dll. That's all. Just remove the MFC-Calls and replace with Qt.

    Here are the function pointers for the dll:

    @// Function pointers
    typedef TPCANStatus (__stdcall *fpInitialize)(TPCANHandle, TPCANBaudrate, TPCANType, DWORD, WORD);
    typedef TPCANStatus (__stdcall fpOneParam)(TPCANHandle);
    typedef TPCANStatus (__stdcall fpRead)(TPCANHandle, TPCANMsg, TPCANTimestamp
    typedef TPCANStatus (__stdcall fpWrite)(TPCANHandle, TPCANMsg);
    typedef TPCANStatus (__stdcall *fpFilterMessages)(TPCANHandle, DWORD, DWORD, TPCANMode);
    typedef TPCANStatus (__stdcall fpGetSetValue)(TPCANHandle, TPCANParameter, void, DWORD);
    typedef TPCANStatus (__stdcall *fpGetErrorText)(TPCANStatus, WORD, LPSTR);

    // Re-define of name for better code-read
    #define fpUninitialize fpOneParam
    #define fpReset fpOneParam
    #define fpGetStatus fpOneParam
    #define fpGetValue fpGetSetValue
    #define fpSetValue fpGetSetValue

    // PCANbasic dynamic-load class@

  • Solved?

  • Thanks Jensen,
    This afternoon I'll try to use it in this way. You're a master.
    Keep in touch

  • Success?

  • Sorry Jensen,
    My PC's RAMs Crashes Sunday at night, and today I've just bought new ones. As soon as I finish to colocate it I'll tray. Thanks for all. I hope it works. I look forward to try it.

Log in to reply