I have purchase this K8047 board and wanted to create a program with the Borland bcc32 version 5.5 compiler.
Below is the program. When I compile and link (using Code::Block front-end) and run, I see no compiler errors, no compiler warnings, no execution errors.
However, the program does not communicate with the USB board. The library is called and loaded.
If I use the datalogger program delivered with the board, communication and data readout works.
What do I do wrong in mystand-alone program ?
#include <windows.h>
#include <iostream.h>
//#include “USB_DLL.h”
#include <time.h>
using namespace std;
typedef long(__stdcall *t_func1)();
typedef long(__stdcall *t_func2)(int *);
typedef long(__stdcall *t_func3)(int, int);
t_func1 t_StartDevice;
t_func1 t_StopDevice;
t_func1 t_LEDon;
t_func1 t_LEDoff;
t_func2 t_ReadData;
t_func3 t_SetGain;
int main() {
int data[6];
time_t start_time, end_time;
double elapsed_time;
printf("Edgar\n");
HMODULE dll_handle = LoadLibrary("k8047d.dll");
if (!dll_handle) {
fprintf(stderr,"LoadLibrary Failed.\n");
return -1;
}
t_StartDevice = (t_func1) GetProcAddress(dll_handle, "StartDevice");
t_StopDevice = (t_func1) GetProcAddress(dll_handle, "StopDevice");
t_LEDon = (t_func1) GetProcAddress(dll_handle, "LEDon");
t_LEDoff = (t_func1) GetProcAddress(dll_handle, "LEDoff");
t_ReadData = (t_func2) GetProcAddress(dll_handle, "ReadData");
t_SetGain = (t_func3) GetProcAddress(dll_handle, "SetGain");
t_StartDevice();
t_LEDon();
//StartDevice();
MessageBeep(-1);
t_SetGain(1,1);
t_SetGain(2,1);
t_SetGain(3,1);
t_SetGain(4,1);
//ReadData(data);
for (int i = 0; i <= 1000000000; i++) {}
t_LEDoff();
for (int i = 0; i <= 1000000000; i++) {}
t_LEDon();
for (int i = 0; i <= 1000000000; i++) {}
t_LEDoff();
for (int i = 0; i <= 1000000000; i++) {}
t_LEDon();
t_ReadData(data);
for (int i = 2; i <= 5; i++) {
printf ("Decimals: %d\n", data[i]);
}
printf ("Time: %d\n", (data[1]*256 + data[0])*10); // (MSB * 256 + LSB) * 10 = the time counter value in ms...
printf("StartDevice %d\n", t_StartDevice);
printf("StopDevice %d\n", t_StopDevice);
printf("LEDon %d\n", t_LEDon);
printf("LEDoff %d\n", t_LEDoff);
printf("ReadData %d\n", t_ReadData);
printf("SetGain %d\n", t_SetGain);
t_StopDevice();
FreeLibrary(dll_handle);
return 0;
}