ich versuche nun schon seit einiger zeit ein problem zu lösen komm aber nicht und nicht weiter. folgendes will ich machen.
es geht um eine hardware (ant). diese möchte ich in labview nutzen. eine der funktionen (die die mir die daten liefert) benötigt eine callbackfunktion als argument. soweit so gut. die hardware benutzt diese callbackfunktion und die angegebenen buffer jedes mal, wenn eine übertragung statt findet.
ich wollte also nichts anderes tun, eine wrapper schreiben, die benötigte funktion von der hersteller dll laden, an diese funktion eine LVUsereventref übergeben und so die kommunikation zwischen labview und meiner dll herstellen.
wie ihr euch denken könnt funktioiert das nicht
folgenden code habe ich geschreiben:
Код: Выделить всё
// antwrapper.cpp : Definiert die exportierten Funktionen für die DLL-Anwendung.
//
#include "stdafx.h"
#include "stdio.h"
#include "extcode.h" //labview inlcude
//Typendifinitionen für die ANT Funktionen
typedef BOOL (*ptreventfunction)(LVUserEventRef*);
typedef BOOL (*ptrresponsefunction)(LVUserEventRef*);
typedef void (*ANT_RESPONSE_POINTER)(ptrresponsefunction, UCHAR*);
typedef void (*ANT_EVENT_POINTER)(UCHAR, ptreventfunction, UCHAR*);
//Zeiger auf die ANT_Funktionen definieren
static ANT_RESPONSE_POINTER ANT_AssignResponseFunction = NULL;
static ANT_EVENT_POINTER ANT_AssignChannelEventFunction = NULL;
//ANT Buffer
UCHAR aucResponseBuffer[10];
UCHAR aucChannelEventBuffer[10];
char eventbuffer[10];
void PopulateStringHandle(LStrHandle lvStringHandle,char* stringData);
BOOL ANT_ChannelEventFunction(UCHAR ucChannel, UCHAR ucEvent);
BOOL ANT_ResponseFunction(UCHAR ucChannel, UCHAR ucMsgId);
static LVUserEventRef *eventref;
static LVUserEventRef *responseref;
extern "C" __declspec(dllexport) BOOL sendevent(LVUserEventRef *eventref)
{
strcpy((char*)&eventbuffer,(const char*)&aucChannelEventBuffer);
LStrHandle eventstringhandle;
//Allocate memory for a LabVIEW string handle using LabVIEW's
//memory manager functions.
eventstringhandle=(LStrHandle)DSNewHandle(sizeof(int32)+256*sizeof(uChar));
PopulateStringHandle(eventstringhandle,(char*)&eventbuffer);
PostLVUserEvent(*eventref, (void *)&eventstringhandle);
return TRUE;
}
extern "C" __declspec(dllexport) BOOL sendresponse(LVUserEventRef *responseref)
{
LStrHandle responsestringhandle;
//Allocate memory for a LabVIEW string handle using LabVIEW's
//memory manager functions.
responsestringhandle=(LStrHandle)DSNewHandle(sizeof(int32)+256*sizeof(uChar));
PopulateStringHandle(responsestringhandle,"Hallo");
PostLVUserEvent(*responseref, (void *)&responsestringhandle);
return TRUE;
}
extern "C" __declspec(dllexport) int ANT_DLL_Load(void)
{
HINSTANCE hANTdll = LoadLibraryA("ANT_DLL.dll");
if (hANTdll == NULL)
ANT_AssignResponseFunction = (ANT_RESPONSE_POINTER) GetProcAddress(hANTdll, "ANT_AssignResponseFunction");
ANT_AssignChannelEventFunction = (ANT_EVENT_POINTER) GetProcAddress(hANTdll, "ANT_AssignChannelEventFunction");
if (ANT_AssignResponseFunction == NULL)
return 0;
if (ANT_AssignChannelEventFunction == NULL)
return 0;
else
return 1;
}
/*//ChannelEventFunction
BOOL ANT_ChannelEventFunction(UCHAR ucChannel, UCHAR ucEvent)
{
LStrHandle eventstringhandle;
//Allocate memory for a LabVIEW string handle using LabVIEW's
//memory manager functions.
eventstringhandle=(LStrHandle)DSNewHandle(sizeof(int32)+256*sizeof(uChar));
PopulateStringHandle(eventstringhandle,"Hallo");
PostLVUserEvent(*eventref, (void *)&eventstringhandle);
return TRUE;
}
//ResponseFunction - hier wollte ich nur schauen ob die callbackfunktion auslöst
BOOL ANT_ResponseFunction(UCHAR ucChannel, UCHAR ucMsgId)
{
LStrHandle responsestringhandle;
//Allocate memory for a LabVIEW string handle using LabVIEW's
//memory manager functions.
responsestringhandle=(LStrHandle)DSNewHandle(sizeof(int32)+256*sizeof(uChar));
PopulateStringHandle(responsestringhandle,"Test");
PostLVUserEvent(*responseref, (void *)&responsestringhandle);
return TRUE;
}
*/
extern "C" __declspec(dllexport) int functioncaller(UCHAR antChannel)
{
if(ANT_AssignResponseFunction != NULL && ANT_AssignChannelEventFunction != NULL)
{
ANT_AssignResponseFunction(&sendresponse, aucResponseBuffer);
ANT_AssignChannelEventFunction(antChannel, &sendevent, aucChannelEventBuffer);
return 1;
}
return 0;
}
void PopulateStringHandle(LStrHandle lvStringHandle,char* stringData)
{
//Empties the buffer
memset(LStrBuf(*lvStringHandle),'\0',256);
//Fills the string buffer with stringData
sprintf((char*)LStrBuf(*lvStringHandle),"%s",stringData);
//Informs the LabVIEW string handle about the size of the size
LStrLen(*lvStringHandle)=strlen(stringData);
return;
}
lg
xhulkx
ps.: anleitung vom hersteller: http://www.thisisant.com/images/Resourc ... 202.12.pdf