VM140 and/or K8061_C.h not working

I have a serious problem using the VM140. I intend to write two programms. One is intended to control a heavy ceramic oven. The other to control a complicated solar system. I do not succeed in including K8061.h or K8061_C.h in a C++ programm. As soon as I do so the C++ compiler generates about 20 errors concerning the K8061.h or K8061_C.h. The first error is: expected constructor, destructor or type conversion before “CloseDevices”. The second error is: expected ","or “;” before “CloseDevices”. The following errors are identical but concern “CloseDevices” etc. It does not make any difference I connect the VM140 to the PC or not.
I tried to locate the problem by writing a very simple C++ programm which only generates a small file on disc and gives a message on screen. It works fine. But as soon as I only add #include <K8061.h> or #include <K8061_C.h> to this simple programm the above mentioned errors appear.
I use XP and installed the USB-driver from the Velleman-CD. Also I put the mpusbapi.dll in the Windows\system32 directory. The K8061.h and K8061_C.h are in as well as the \include as the \lib directory of the compiler. The VM140 hardware works fine according to the tests with the demo and diagnose programms on the Vellemans CD; i.e. I can connect and switch the Leds on and off. Who can help me to solve this nasty problem?

Is there any difference if you are using this K8061_C.h

[code]#ifdef __cplusplus
extern “C” {
#endif

#define FUNCTION __declspec(dllexport)

FUNCTION long __stdcall OpenDevice();
VOID __stdcall CloseDevices();
VOID __stdcall ReadAnalogChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION unsigned char __stdcall PowerGood(unsigned char CardAddress);
FUNCTION unsigned char __stdcall Connected(unsigned char CardAddress);
VOID __stdcall ReadVersion(unsigned char CardAddress, long *Buffer);
VOID __stdcall ReadAllAnalog(unsigned char CardAddress, long *Buffer);
VOID __stdcall OutputAnalogChannel(unsigned char CardAddress, unsigned char Channel, unsigned char Data);
VOID __stdcall OutputAllAnalog(unsigned char CardAddress, long *Buffer);
VOID __stdcall ClearAnalogChannel(unsigned char CardAddress, unsigned char Channel);
VOID __stdcall SetAllAnalog(unsigned char CardAddress);
VOID __stdcall ClearAllAnalog(unsigned char CardAddress);
VOID __stdcall SetAnalogChannel(unsigned char CardAddress, unsigned char Channel);
VOID __stdcall OutputAllDigital(unsigned char CardAddress, unsigned char Data);
VOID __stdcall ClearDigitalChannel(unsigned char CardAddress, unsigned char Channel);
VOID __stdcall ClearAllDigital(unsigned char CardAddress);
VOID __stdcall SetDigitalChannel(unsigned char CardAddress, unsigned char Channel);
VOID __stdcall SetAllDigital(unsigned char CardAddress);
FUNCTION bool __stdcall ReadDigitalChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION unsigned char __stdcall ReadAllDigital(unsigned char CardAddress);
VOID __stdcall OutputPWM(unsigned char CardAddress, long Data);
VOID __stdcall Version();
FUNCTION unsigned char __stdcall ReadBackDigitalOut(unsigned char CardAddress);
VOID __stdcall ReadBackAnalogOut(unsigned char CardAddress, long *Buffer);
FUNCTION long __stdcall ReadBackPWMOut(unsigned char CardAddress);

#ifdef __cplusplus
}
#endif[/code]
or this one:

[code]#ifdef __cplusplus
extern “C” {
#endif

#define FUNCTION __declspec(dllexport)

FUNCTION long __stdcall OpenDevice();
FUNCTION __stdcall CloseDevices();
FUNCTION __stdcall ReadAnalogChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION unsigned char __stdcall PowerGood(unsigned char CardAddress);
FUNCTION unsigned char __stdcall Connected(unsigned char CardAddress);
FUNCTION __stdcall ReadVersion(unsigned char CardAddress, long *Buffer);
FUNCTION __stdcall ReadAllAnalog(unsigned char CardAddress, long *Buffer);
FUNCTION __stdcall OutputAnalogChannel(unsigned char CardAddress, unsigned char Channel, unsigned char Data);
FUNCTION __stdcall OutputAllAnalog(unsigned char CardAddress, long *Buffer);
FUNCTION __stdcall ClearAnalogChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION __stdcall SetAllAnalog(unsigned char CardAddress);
FUNCTION __stdcall ClearAllAnalog(unsigned char CardAddress);
FUNCTION __stdcall SetAnalogChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION __stdcall OutputAllDigital(unsigned char CardAddress, unsigned char Data);
FUNCTION __stdcall ClearDigitalChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION __stdcall ClearAllDigital(unsigned char CardAddress);
FUNCTION __stdcall SetDigitalChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION __stdcall SetAllDigital(unsigned char CardAddress);
FUNCTION bool __stdcall ReadDigitalChannel(unsigned char CardAddress, unsigned char Channel);
FUNCTION unsigned char __stdcall ReadAllDigital(unsigned char CardAddress);
FUNCTION __stdcall OutputPWM(unsigned char CardAddress, long Data);
FUNCTION __stdcall Version();
FUNCTION unsigned char __stdcall ReadBackDigitalOut(unsigned char CardAddress);
FUNCTION __stdcall ReadBackAnalogOut(unsigned char CardAddress, long *Buffer);
FUNCTION long __stdcall ReadBackPWMOut(unsigned char CardAddress);

#ifdef __cplusplus
}
#endif [/code]

Thanks for the amazing fast answer!
When I compile my simple programm with the first K8061_C.h (the one with the VOID’s) you suggested I get the same compile-errors as before:
line 8 (in K8061_C.h) gives: expected constructor, destructor or type conversion before “CloseDevices”.
line 8 gives also: expected “,” or “;” before “CloseDevices”.
line 9, 12,13,14,15,16,17,18,19,20,21,22,23,24, 27,28, 30 give the same error but with their corresponding names like “ReadAnalogChannel” and so on.

When I compile with your second proposal for K8061_C.h (the one with only FUNCTION’s) the compile-error is: expected constructor, destructor, or type conversion before “;” token.
These errors are generated for lines 8,9, 12,13,14,15,16,17,18,19,20,21,22,23,24, 27,28, 30 and are all identical. I hope this helps to solve the problem. Thanks!

The second .h is more promising - less errors.
What might happen if you change in the second .h file

FUNCTION __stdcall CloseDevices();

to

FUNCTION void __stdcall CloseDevices();

Thanks!. It helped, at least a little. The error list is almost as long as before except that the error in line 8 is not longer there. It looks like you are solving the problem. I hope you give me further instructions.

OK.
You have now to change all the

FUNCTION __stdcall

to

FUNCTION void __stdcall

I did and it worked! No errors after compiling anymore. I can now start writing my programm.
Thanks! I’m impressed about your skill.

I wish you success in your K8061 project :slight_smile:

Thanks for your good wishes. Now, after a couple of days, I made a start with my project. First of all I wrote a tiny programm to test the communication with the VM140. It did not work. Obviously I’m doiing something very stupid but can’t find out. My testprogramm is as follows:
#include
#include <k8061_C.h>
using namespace std;
int main () {
long CardAddress;
OpenDevice (CardAddress);
cout << CardAddress;
system(“pause”);
return 0;
}

The C++ compiler says: too many arguments to function long int OpenDevice(), corresponding to the line FUNCTION long __stdcall OpenDevice() out of the k8061_C.h. I use the latest k8061_C.h as discussed above.
When I omit the line OpenDevice(CardAddress) and add CardAddress=123; instead, the programm outputs this 123.
Please give me a hand.

[quote]The C++ compiler says: too many arguments to function long int OpenDevice(), corresponding to the line FUNCTION long __stdcall OpenDevice() out of the k8061_C.h. I use the latest k8061_C.h as discussed above.[/quote]The prototype of OpenDevice is: long OpenDevice();
There are no parameters. The return value is the card address, 32 bit integer.
I think your code will work if you change:

OpenDevice (CardAddress);[/code]to[code]CardAddress = OpenDevice ();

I added there some functions to test the card operation. I run this in Microsoft Visual C++ 2008 Express Edition.

[code]#include
#include “K8061_C.h”

using namespace std;

int main(void)
{
int CardAddress;
CardAddress = OpenDevice ();
cout << CardAddress << endl;
SetAllDigital(CardAddress);
system(“pause”);
ClearAllDigital(CardAddress);
system(“pause”);
CloseDevices();
return 0;
}[/code]

Thank you! But I’m sorry to say that I tried CardAddress = OpenDevice (); before. In that case the compile- error was: [Linker error] undefined refrence to “OpenDevice@0”. In the directory .lib of the compiler are k8061_c.lib and k8061.lib present. I do not understand this problem. I hope you do.

Have you added the K8061_C.LIB to the project?

I got about similar error if the K8061_C.LIB is not added to the project:

1>main.obj : error LNK2019: unresolved external symbol _OpenDevice@0 referenced in function _main

It seems that the Microsoft VC++ .lib file is not compatible with the Dev-C++.
daniweb.com/forums/thread108936.html#

You have to use explicit DLL linking.
http://msdn.microsoft.com/en-us/library/9yd93633(VS.71).aspx

The explicit DLL linking seems to work fine in Dev-C++.
I used K8061.DLL in this example. You’ll find this DLL from the subfolder BCB or VB of the Vistapack.
Here is the screenshot of my simple demo software:

To get some input I connected all the digital outputs to the digital inputs and all the analog outputs to the analog inputs (pin-to-pin) .

Here’s a link to download a demo project using the Vistapack driver:
box.net/shared/7k5s8bp392

What a nice surprise to find your complete testprogramm for Dev-C++! Because my internetprovider was down I only found it this morning. Thanks!
To my surprise the compiler accepted k8061.h with no problem. When I run this testprogramm a message is issued by Windows saying: “No Win USB Support On This Computer!!”. Your testprogramm then opens a screen and displays: “DLL not found” and “Card not found”. Nevertheless my VM140 is installed and connected. The USB Led on the board is off. The test during installation of the VM140 allowed me to toggle the digital outputs on and off; as long as this installation testprogram is running the usb-Led on the board is on.
When I look in the Windows hardwarelist there is a “K8061 USB Interfaceboard” present. It is not listed in the list of USB devices but seperately, with a “?” attached to it. I removed this "K8061 USB Interfaceboard" from the list and re-installed it from the Velleman CD. It makes no difference.
In the Windows /system32 directory there is no winusb.dll. In /system32/drivers there is mchpusb.sys which is loaded through installation of the VM140 from the Velleman CD.
On the Velleman CD I found WinUSBCoInstaller.dll. I put this in the /system32 directory and renamed it, only during this test, to winusb.dll and tried the testprogramm again. Then there is no message “No WIN USB Support On This Computer”. The testprogramm now says: “DLL found” but also “Card not found”. This ends my knowledge! I hesitate to ask you again: can you please help me?

[quote]Windows saying: “No Win USB Support On This Computer!!”.[/quote]This indicates that you are using the Vistapack DLL with the original driver installed from CD.
After installing the Vistapack driver the WinUSB support should be OK.

[quote]I removed this “K8061 USB Interfaceboard” from the list and re-installed it from the Velleman CD. It makes no difference.[/quote]You have to install the driver included to the Vistapack:
velleman.eu/downloads/files/ … 2007v1.zip

As I stated before I get the error-message “No Win USB Support On This Computer!!” when I try to run the testprogramm you gave me (see above). This error-message looks to be generated by PowerBasic. Obviously the programm uses PowerBasic.

In short my problem is: when I run the test from Velleman during installation my VM140 is recognised and works oke. But when I compile and run the program you gave me (see above) I get the error message No USB support on my pc.

On 3 july 2009 someone called “Duncan” posted a simular problem. May be he found a solution. Duncan, please post a message. Thanks!

Duncan” posted a question on july, 3rd, 2009. His problem looks like my problem. Did you solve the problem Duncan? I hope you read this. Maybe you can answer me.Thanks anyway.

I think you still see this error message:

This message is sent by the Vistapack DLL.

It seems the original driver version 2.0.0.0 from CD is still in use.
To get the system working, you have to remove this driver and install the driver included to the Vistapack.
The driver version is 6.0.1.0 and in the Device Manager the K8061 should be in the list of USB devices.
After doing this you may download this Dev-C++demo package written for the Vistapack driver and Vistapack DLL: box.net/shared/7k5s8bp392

The package includes the source code for Dev-C++ and the Vistapack K8061.DLL needed to run the application.

No need for the mchpusb.sys and mchpusb.DLL any more.

I now have a working VM140. Wow! This result is achived by means of the support of Velleman. What I did was removing all of the VM140 dll’s of my PC and then reinstalled only one: k8061.DLL. This solved all the problems.
Now I have a question: Is there a programmable PIC Velleman kit available which can be used to directly controll the VM140?