Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use PCAN drivers or OpenCAN PCAN plugin (SOLVED?)

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

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 6.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jako87
    wrote on last edited by
    #1

    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!!!

    1 Reply Last reply
    0
    • jensen82J Offline
      jensen82J Offline
      jensen82
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jako87
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jako87
            wrote on last edited by
            #5

            Is maybe a problem of .dll location???

            1 Reply Last reply
            0
            • jensen82J Offline
              jensen82J Offline
              jensen82
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jako87
                wrote on last edited by
                #7

                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
                mainwindow.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!

                1 Reply Last reply
                0
                • jensen82J Offline
                  jensen82J Offline
                  jensen82
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jako87
                    wrote on last edited by
                    #9

                    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!
                    Thanks!!!

                    1 Reply Last reply
                    0
                    • jensen82J Offline
                      jensen82J Offline
                      jensen82
                      wrote on last edited by
                      #10

                      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@

                      1 Reply Last reply
                      0
                      • jensen82J Offline
                        jensen82J Offline
                        jensen82
                        wrote on last edited by
                        #11

                        Solved?

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Jako87
                          wrote on last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • jensen82J Offline
                            jensen82J Offline
                            jensen82
                            wrote on last edited by
                            #13

                            Success?

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              Jako87
                              wrote on last edited by
                              #14

                              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.
                              Thanks

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved