CloseDevices command for VM140

Hi there,

I have written the following piece of C# testing code and the results are confusing. Please help.

        int cardNr = VM140API.OpenDevice();
        [color=#408040]//result is '0' i.e the connection to card 0 is opened. We're still OK![/color]
        bool connected = VM140API.Connected(cardNr);
       [color=#408000] //as expected the result is 'true'.[/color]
        [color=#408000]//Now I close the devices[/color]
        VM140API.CloseDevices();
        connected = VM140API.Connected(cardNr);
        [color=#408000]//as expected the result is 'false' because the connections were closed[/color]
        [color=#408000]//Let us open the connection again[/color]
        cardNr = VM140API.OpenDevice();
        [color=#BF0000]//NOW HERE I AM CONFUSED.  Why is the result of cardNr = -1? If the connection to all devices were closed, should this value            not be '0'?[/color]
        connected = VM140API.Connected(cardNr);
       [color=#BF0000] //the result is 'true' here. Huh? How can the card with nr '-1' be connected?[/color]

This results look strange indeed.
According to the OpenDevice documentation:
Return value -1 indicates that all K8061 cards are opened.
Return value -2 indicates that no card was found.

I did a quick test with the Delphi version and everything seems to work OK.

BTW: Are you using the K8061.DLL or the K8061_C.DLL ?

Have you downloaded the latest DLL v2.0.0 from the Velleman downloads page?
The download package is: k8061_vistapack_2007v1.zip
It includes new driver, example programs and the latest DLL version.

I have Windows XP and use K8061. Should I use K8061_C instead.

I see I have an older version of the K8061.DLL. I have downloaded the newer one and will let you know.

By the way. The Delphi demo does not have a ‘CloseDevices’ button, but executes the command when you exit the application. When you then re-start the application then everything works fine. I have the same behavior with my app. If I exit the app and re-start it also works fine, but I have Connect and Disconnect buttons in my app and then it does not work OK i.e. I am not exiting the application just disconnecting and re-connecting.

But let me try with the updated drive first. Hope this is the issue…

[quote]The Delphi demo does not have a ‘CloseDevices’ button, but executes the command when you exit the application.[/quote] Yes, normally the CloseDevices() is used only when you exit the program.
To be more specific: I actually modified the Delphi demo and added there a Close button.
Pressing the Close disconnected the card and I got return FALSE from the function Connected(CardAddress) .
Pressing the Connect button, reconnected the card and I got TRUE from this function.

[quote]I have Windows XP and use K8061. Should I use K8061_C instead.[/quote]I think you can use K8061.DLL as well.

BTW: I have not much experience in C#. It would be nice if you can post your code or code snippets to this forum. Especially the section VM140API may be interesting starting point for new C# users who like to control the K8061 from within C# application…

The new K8061 driver solved this problem. I will also gladly add my code to the forum. Just want to put in comments to make it easier to understand.

Thanks for the help!

I’m glad the problem is solved now!
Thank you in advance for putting some code to this forum!
:slight_smile: