How to use PCAN drivers or OpenCAN PCAN plugin (SOLVED?)
-
wrote on 29 Jul 2014, 10:49 last edited by
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/ -lPCANBasicdINCLUDEPATH += $$PWD/PCAN-Basic API/Include
DEPENDPATH += $$PWD/PCAN-Basic API/Includewin32-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!!! -
wrote on 29 Jul 2014, 11:49 last edited by
Means the compiler can't find the header-file. Please check the include-directories.
-
wrote on 29 Jul 2014, 11:50 last edited by
Is /PCAN-Basic API/Include a subdir of your project-dir C:\Users\jalonso\QtProy\AdquisicionCAN\ ? just correct the path
-
wrote on 29 Jul 2014, 12:18 last edited by
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.
-
wrote on 29 Jul 2014, 12:19 last edited by
Is maybe a problem of .dll location???
-
wrote on 29 Jul 2014, 13:02 last edited by
The path "$$PWD/PCAN-Basic API/Include" contains spaces...this could be the problem. Wrap it with "
-
wrote on 29 Jul 2014, 17:52 last edited by
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/ -lPCANBasicdINCLUDEPATH += $$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 guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = pruebacan
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += 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/ -lPCANBasicdINCLUDEPATH += $$PWD/Include
DEPENDPATH += $$PWD/IncludeIf anyone have an answer or question, please quote!
-
wrote on 30 Jul 2014, 06:35 last edited by
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.
-
wrote on 30 Jul 2014, 08:50 last edited by
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!!! -
wrote on 1 Aug 2014, 06:15 last edited by
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@
-
wrote on 1 Aug 2014, 10:46 last edited by
Solved?
-
wrote on 2 Aug 2014, 12:59 last edited by
Thanks Jensen,
This afternoon I'll try to use it in this way. You're a master.
Keep in touch -
wrote on 5 Aug 2014, 10:47 last edited by
Success?
-
wrote on 5 Aug 2014, 22:11 last edited by
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/14