12-04-2008 11:42 AM
Hi, I am trying to interface a Keyence laser displacement sensor controller with labview. Keyence has a dll API and I wrote a wrapper in C with DEV-C++. The wrapper is compiled into another DLL so I can call in my application. (Keyence DLL cannot be called directly for some reason)
These are tested in Matlab and worked well. The problem is when I try to use the "Call Library Function Node " in Labview, it always report me errors. The C code is pasted as below. The arrays are 1-D and not been resized in the function call.
Any input is highly appreciated.
Bo
----------------------------------------------------------------------------------------------------------------
DLLIMPORT int AcqData(float *DataA, float *DataB)
{
typedef int (_stdcall *DataStorageStartPtr) (void);
typedef int (_stdcall *DataStorageStopPtr) (void);
typedef int (_stdcall *DataStorageInitPtr) (void);
typedef int (_stdcall *DataStorageGetDataPtr) (int OutNo,int NumOutBuffer, LKIF_FLOATVALUE *OutBuffer, int *NumReceived);
typedef int (_stdcall *DataStorageGetStatusPtr) (int OutNo, int *IsStorage, int *NumStorageData);
DataStorageStartPtr DataStorageStart;
DataStorageStopPtr DataStorageStop;
DataStorageInitPtr DataStorageInit;
DataStorageGetDataPtr DataStorageGetData;
DataStorageGetStatusPtr DataStorageGetStatus;
HINSTANCE hLib;
int feedback;
int OutNo;
int NumOutBuffer = MAX_NUM_DATA;
int IsStorageA, IsStorageB;
int NumStorageData;
int NumReceivedA, NumReceivedB;
LKIF_FLOATVALUE OutBufferA[NumOutBuffer];
LKIF_FLOATVALUE OutBufferB[NumOutBuffer];
//---------------- Import the DLL --------------------//
hLib = LoadLibrary("LkIF.dll");
if(!hLib)
{
return -1;
}
//---------------- Get the addresses of functions ---------------//
DataStorageStart = (DataStorageStartPtr)GetProcAddress(hLib, "LKIF_DataStorageStart");
if(DataStorageStart == NULL)
{
return -2;
}
DataStorageStop = (DataStorageStopPtr)GetProcAddress(hLib, "LKIF_DataStorageStop");
if(DataStorageStop == NULL)
{
return -3;
}
DataStorageInit = (DataStorageInitPtr)GetProcAddress(hLib, "LKIF_DataStorageInit");
if(DataStorageInit == NULL)
{
return -4;
}
DataStorageGetData = (DataStorageGetDataPtr)GetProcAddress(hLib, "LKIF_DataStorageGetData");
if(DataStorageGetData == NULL)
{
return -5;
}
DataStorageGetStatus = (DataStorageGetStatusPtr)GetProcAddress(hLib, "LKIF_DataStorageGetStatus");
if(DataStorageGetStatus == NULL)
{
return -6;
}
//---------------------------- Data Acqusition --------------------------//
feedback = (DataStorageInit)();
if(!feedback)
{
return -7;
}
feedback = (DataStorageStart)();
if(!feedback)
{
return -8;
}
sleep(10000);
sleep(500);
OutNo = 0;
feedback = (DataStorageGetStatus)(OutNo, &IsStorageA, &NumStorageData);
if(!feedback)
{
return -9;
}
OutNo = 1;
feedback = (DataStorageGetStatus)(OutNo, &IsStorageB, &NumStorageData);
if(!feedback)
{
return -10;
}
while(IsStorageA || IsStorageB)
{
sleep(500);
OutNo = 0;
feedback = (DataStorageGetStatus)(OutNo, &IsStorageA, &NumStorageData);
if(!feedback)
{
return -9;
}
OutNo = 1;
feedback = (DataStorageGetStatus)(OutNo, &IsStorageB, &NumStorageData);
if(!feedback)
{
return -10;
}
}
feedback = (DataStorageStop)();
if(!feedback)
{
return -11;
}
OutNo = 0;
feedback = (DataStorageGetData)(OutNo,NumOutBuffer,&OutBufferA[0],&NumReceivedA);
if(!feedback)
{
return -12;
}
OutNo = 1;
feedback = (DataStorageGetData)(OutNo,NumOutBuffer,&OutBufferB[0],&NumReceivedB);
if(!feedback)
{
return -13;
}
int i;
for(i = 0; i < NumReceivedA; i++)
{
DataA[i] = OutBufferA[i].Value;
}
for(i = 0; i < NumReceivedB; i++)
{
DataB[i] = OutBufferB[i].Value;
}
return 0;
}
12-04-2008 11:45 AM
12-04-2008 11:53 AM
12-04-2008 12:10 PM
12-04-2008 12:19 PM
12-04-2008 12:21 PM
12-05-2008 12:58 AM
12-05-2008 05:30 PM
Hi All,
I agree with mathan. I think seeing the VI may help us help you.
12-09-2008 02:27 PM
I am sorry for the delay. Here is the vi and dlls and the C source code. Thanks.
08-12-2010 11:59 AM
Bo2008:
I have used lkIF.dll in several applications, using a call library function node. I have never had to write any C or other "extra" code (in LV 8.0 and 8.5).
Check the version number on your LK-Navigator disk. The USB driver from disks at version 1.40 will work with lkIF.dll, but the driver from a version 1.51 disk will not. I cannot tell you where the good-to-bad transition point occurs.
My VI is attached.
Cheers,
-GN