How to use PCAN drivers or OpenCAN PCAN plugin (SOLVED?)
-
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!
-
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!
Thanks!!! -
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@