We are developing code for the K8061 in C++ to read digital and analog input. We have setup the K8061.dev from your example that came with the cd. The demo functions and the card is recognized. Now we’re trying to begin reading digital and analog ins. We have tried a variety of inputs from 0-5V to the board and used ReadDigitalChannel, ReadAllDigital, ReadAnalogChannel, and ReadAllAnalog with a constant result of 0 (but no errors). For example:
ReadAllAnalog(CardAddress, dataIn);
for (int i = 0; i < 8; i++)
{
cout << “dataIn[” << i << "] = " << dataIn[i] << endl;
}
results in an array of 0s even though several of the inputs have a variety of voltages. Do you have example code for C++ on how these functions are actually used so that we may locate our problem?
Are there problems only when using the input functions?
When running the Dev-C++ demo, are the output functions SetAllDigital() and OutputAllDigital() working?
cout << "Press Enter to \"SetAllDigital\"" << endl;
cin.get();
SetAllDigital(CardAddress);
cout << "Press Enter to \"OutputAllDigital 0x55\"" << endl;
cin.get();
OutputAllDigital(CardAddress, 0x55);
Do you get the correct analog and digital input values displayed on the screen when running the K8061_Demo.exe in the CD folder d:\VM140(K8061) USB interface card\Demo?
The problems are with input and output. SetAllDigital and OutputAllDigital do not work. Both analog and digital do work using the demo program, so the error is in our code somewhere.
What happens if you run the K8061.exe in the CD folder …\Examples\K8061DemoDevC ?
Can you post your code ?
These are the results given digital inputs I1-I4 grounded and I5-I8 at 3V.
For this scenario, our digital-in LEDs lit up for I5-I8 and remained off for I1-I4. No changes occurred in the LEDs when the code was run.
We got the same exact result given no specific input. The digital-in LEDs are all turned on. No changes occurred in the LEDs throughout running the code.
The code we used was the unchanged code provided on the CD:
#include <cstdlib>
#include <windows.h>
#include <iostream>
using namespace std;
typedef void(WINAPI *t_func0)();
typedef void(WINAPI *t_func1)(int);
typedef void(WINAPI *t_func2)(int, int);
typedef void(WINAPI *t_func3)(int, int, int);
typedef void(WINAPI * t_func4)(int, int *);
typedef int(WINAPI *t_func5)();
typedef int(WINAPI *t_func6)(int);
typedef int(WINAPI *t_func7)(int, int);
typedef bool(WINAPI *t_func8)(int, int );
t_func5 OpenDevice;
t_func0 CloseDevices;
t_func0 Version;
t_func7 ReadAnalogChannel;
t_func4 ReadAllAnalog;
t_func3 OutputAnalogChannel;
t_func4 OutputAllAnalog;
t_func2 ClearAnalogChannel;
t_func1 ClearAllAnalog;
t_func2 SetAnalogChannel;
t_func1 SetAllAnalog;
t_func2 OutputAllDigital;
t_func2 ClearDigitalChannel;
t_func1 ClearAllDigital;
t_func2 SetDigitalChannel;
t_func1 SetAllDigital;
t_func8 ReadDigitalChannel;
t_func6 ReadAllDigital;
int init();
HINSTANCE hDLL;
int foundDLL = 0;
int main(void)
{
int CardAddress;
int dataOut[8] = {20, 50, 70, 100, 120, 150, 180, 220};
int dataIn[8];
int h = init();
if (!h)
{
cout << "DLL found" << endl;
foundDLL = 1;
}
else
{
cout << "DLL not found" << endl;
cout << "Error code: " << h << endl;
cout << "Press a key to exit." << endl;
cin.get();
}
if (foundDLL)
{
CardAddress = OpenDevice();
if (CardAddress >= 0)
{
cout << "Card #"<< CardAddress << " opened." << endl;
}
else
{
cout << "Card not found" << endl;
}
}
if (foundDLL)
{
cout << "Press Enter to \"SetAllDigital\"" << endl;
cin.get();
SetAllDigital(CardAddress);
cout << "Press Enter to \"OutputAllDigital 0x55\"" << endl;
cin.get();
OutputAllDigital(CardAddress, 0x55);
cout << "Press Enter to \"ReadAllDigital\"" << endl;
cin.get();
int i = ReadAllDigital(CardAddress);
cout << i << endl;
cout << "Press Enter to \"ClearAllDigital\"" << endl;
cin.get();
ClearAllDigital(CardAddress);
cout << "Press Enter to \"OutputAllAnalog dataOut\"" << endl;
cin.get();
OutputAllAnalog(CardAddress, dataOut);
cout << "Press Enter to \"ReadAllAnalog dataIn\"" << endl;
cin.get();
ReadAllAnalog(CardAddress, dataIn);
for (int i = 0; i < 8; i++)
{
cout << "dataIn[" << i << "] = " << dataIn[i] << endl;
}
cout << "Press Enter to \"CloseDevices\" and to \"FreeLibrary\"" << endl;
cin.get();
CloseDevices();
FreeLibrary(hDLL);
}
return EXIT_SUCCESS;
}
int init()
{
hDLL = LoadLibrary("K8061.DLL");
if (hDLL != NULL)
{
OpenDevice = (t_func5) GetProcAddress(hDLL, "OpenDevice");
if (!OpenDevice)
{ // handle the error
FreeLibrary(hDLL);
return -2;
}
CloseDevices = (t_func0) GetProcAddress(hDLL, "CloseDevices");
if (!CloseDevices)
{ // handle the error
FreeLibrary(hDLL);
return -3;
}
ReadAnalogChannel = (t_func7) GetProcAddress(hDLL, "ReadAnalogChannel");
if (!ReadAnalogChannel)
{ // handle the error
FreeLibrary(hDLL);
return -4;
}
ReadAllAnalog = (t_func4) GetProcAddress(hDLL, "ReadAllAnalog");
if (!ReadAllAnalog)
{ // handle the error
FreeLibrary(hDLL);
return -5;
}
OutputAnalogChannel = (t_func3) GetProcAddress(hDLL, "OutputAnalogChannel");
if (!OutputAnalogChannel)
{ // handle the error
FreeLibrary(hDLL);
return -6;
}
OutputAllAnalog = (t_func4) GetProcAddress(hDLL, "OutputAllAnalog");
if (!OutputAllAnalog)
{ // handle the error
FreeLibrary(hDLL);
return -7;
}
ClearAnalogChannel = (t_func2) GetProcAddress(hDLL, "ClearAnalogChannel");
if (!ClearAnalogChannel)
{ // handle the error
FreeLibrary(hDLL);
return -8;
}
ClearAllAnalog = (t_func1) GetProcAddress(hDLL, "ClearAllAnalog");
if (!ClearAllAnalog)
{ // handle the error
FreeLibrary(hDLL);
return -9;
}
SetAnalogChannel = (t_func2) GetProcAddress(hDLL, "SetAnalogChannel");
if (!SetAnalogChannel)
{ // handle the error
FreeLibrary(hDLL);
return -10;
}
SetAllAnalog = (t_func1) GetProcAddress(hDLL, "SetAllAnalog");
if (!SetAllAnalog)
{ // handle the error
FreeLibrary(hDLL);
return -11;
}
OutputAllDigital = (t_func2) GetProcAddress(hDLL, "OutputAllDigital");
if (!OutputAllDigital)
{ // handle the error
FreeLibrary(hDLL);
return -12;
}
ClearDigitalChannel = (t_func2) GetProcAddress(hDLL, "ClearDigitalChannel");
if (!ClearDigitalChannel)
{ // handle the error
FreeLibrary(hDLL);
return -13;
}
ClearAllDigital = (t_func1) GetProcAddress(hDLL, "ClearAllDigital");
if (!ClearAllDigital)
{ // handle the error
FreeLibrary(hDLL);
return -14;
}
SetDigitalChannel = (t_func2) GetProcAddress(hDLL, "SetDigitalChannel");
if (!SetDigitalChannel)
{ // handle the error
FreeLibrary(hDLL);
return -15;
}
SetAllDigital = (t_func1) GetProcAddress(hDLL, "SetAllDigital");
if (!SetAllDigital)
{ // handle the error
FreeLibrary(hDLL);
return -16;
}
ReadDigitalChannel = (t_func8) GetProcAddress(hDLL, "ReadDigitalChannel");
if (!ReadDigitalChannel)
{ // handle the error
FreeLibrary(hDLL);
return -17;
}
ReadAllDigital = (t_func6) GetProcAddress(hDLL, "ReadAllDigital");
if (!ReadAllDigital)
{ // handle the error
FreeLibrary(hDLL);
return -18;
}
/* Version = (t_func0) GetProcAddress(hDLL, "Version");
if (!Version)
{ // handle the error
FreeLibrary(hDLL);
return -19;
}
*/
return 0; // OK
}
return -1; // error load DLL
}
Thanks so much for your help!
The difference between the working K8061_Demo.exe in the folder …\Demo and the Dev-C++ example in the folder …\K8061DemoDevC is the location of the two .DLL files: K8061.dll and mpusbapi.dll.
(Maybe the .DLL files copied from the folder …\DLL_v3.0.0.1 to the system32 folder are corrupted.)
As a test please copy these two .DLL files from the …\Demo folder to the Dev-C++ example folder and run the K8061.exe there again.
- Any help?
We re-copied the .DLL files into the example folder and ran again. It worked 1 time: ReadAllDigital resulted in 255 and OutputAllDigital x55 turned every other digital-out LED on. I closed the application then ran it again and returned to the same problem - no response of the board. I copied and pasted the .DLLs again, and still no response. Any reason why it might work once then stop working?
Does it start working again if you disconnect and reconnect the power and the USB cable to the card?
Then run the K8061.exe again.
Does the card work if you run the K8061_Demo.exe in the \Demo folder?
Can you test the card in other PC?
If we disconnect, restart computer, and turn everything back on again, it works once, then never again (until full shut-down/restart).
Previously, the demo worked consistently, but now the “CPU Fails” just about every other time we try to run the demo in the \Demo folder.
We will try another PC later today.
[quote]Previously, the demo worked consistently, but now the “CPU Fails” just about every other time we try to run the demo in the \Demo folder.[/quote]This may indicate a hardware problem with the K8061 board.
Is there any chance it could be an error in working with Windows7?
The K8061 should work with Windows 7, 64-bit version too.