K8047

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;

}

I have only Borland C++Builder. I tried some of your code in it and it seems to work OK.

The function ReadData returns 8 integers (of 32 byte).
Change
int data[6];
to
int data[8];

Quote from the manual:

[quote]ReadData
Syntax
PROCEDURE ReadData(Buffer:Pointer);
Parameter
Buffer: A pointer to the data array of 8 integers where the data will be read.
Description
Reads the timer counter status and the A/D data from the K8047 to a buffer in the application program.
The timer counter is incremented every 10ms. The new data from the A/D converter channels 1…4 is
updated every time the timer counter is incremented.
Data structure:
Timer data A/D converter data Reserved
LSB MSB CH1 CH2 CH3 CH4 0 0[/quote]

This is my test code:

[code] int data[8];
String s;

    StartDevice();
    LEDon();
    SetGain(1,1);
    SetGain(2,1);
    SetGain(3,1);
    SetGain(4,1);

    for (int i = 0; i <= 100000000; i++) {}
    LEDoff();
    for (int i = 0; i <= 100000000; i++) {}
    LEDon();
    for (int i = 0; i <= 100000000; i++) {}
    LEDoff();
    for (int i = 0; i <= 100000000; i++) {}
    LEDon();

    ReadData(data);

    Memo1->Clear();
    s = "";
    for (int i = 0; i <= 5; i++)
    {
        s = s + IntToStr(data[i])+ Char(9);
    }
    Memo1->Lines->Add(s);[/code]

I have got it working now. However, when I run it, I get a window message “SimpleHIDWrite” saying “Device VID=10CF PID=8047”.
Also, I get in the Event Viewer under Security the following entry Event ID 577 - Priviledge Use.
How can both be fixed. I do not get this when running i.e. PCLAB2000SE.

I found this from Microsoft Help and Support: “Event ID 577 appears repeatedly in the security event log of your Windows XP-based computer”
There is also resolution to this problem.
support.microsoft.com/kb/831905

The VID=10CF PID=8047 are the VID and PID of the K8047 card.

No idea what the “SimpleHIDWrite” is.
Google says there is a program named “SimpleHIDWrite.EXE”.

[quote]The SimpleHIDWrite utility tests HID-class devices.[/quote] See: Tools / Software in this link: lvr.com/hidpage.htm

Maybe Administrator privileges are required?

I am administrator. Does Velleman code reference to this SimpleHIDWrite.EXE ?
This sympthom is seen on two different computers running Win XP.

What should be the correct USB driver ?
Currently my computer uses “USB Human Interface Device” from Microsoft.

[quote]Does Velleman code reference to this SimpleHIDWrite.EXE ?[/quote]Actually not but the K8047E.EXE includes a form with title bar text “SimpleHIDWrite”. It seems that you see this form. Normally this form is invisible. - Difficult to find solution how you can hide it.

To try to solve this problem I recompiled the K8047E.EXE. Now the form is forced to be invisible when created. In the old code it was hidden in a timer routine. Here is a link to download this modified K8047E.EXE: box.net/shared/rngt1ng1fu
(I’m afraid this doesn’t help anyhow.)

[quote]What should be the correct USB driver ?
Currently my computer uses “USB Human Interface Device” from Microsoft.[/quote]This is correct driver.

It was a great deal to have given us a new version of K8047E.EXE!

The previous one didn’t work neither using Recorder_Logger_Demo.exe (I couldn’t even lit a red Record LED, all the data were zeroes), nor under and from VBA.

I nearly decided to ask a question on the matter as I saw this forum topic: in a minute I became happy!

Now everything works; Demo shows all it must; I receive readings from my water meters.

But will my wife be also happy with these readings? Not integral, but attached to particular moments…