Using the Proxy API with WinDEV

Using the Proxy API with WinDEV

Apparently, the tradition says that any WinDev relative text must be illustrated with some random girls. Don't ask us why.Our .NET Proxy library was originally designed to enable integration with LabVIEW, but you can easily use it in other development environments, such as WinDEV. And since we're not one to brag, we'll prove it to you...


This week, we are thus going write with WinDEV a short and very simple Windows application which dynamically changes the state of a relay depending on the temperature. So, you need a module with a temperature function and a module with a relay function. If you don't have any on hand, you can easily adapt the code that we present for other Yoctopuce modules. This post also assumes that if you take the time to read it, it's that you know more than we do about WinDEV, so we are not going to linger on the details on how to handle the environment.

Installing

Simply download the .NET Proxy library from our web site and unzip it wherever you want. The interesting directories are:

  • Documentation containing the library reference documentation, in HTML format
  • Binaries containing the library itself, as a DLL


Creating the project

We run WinDEV and we create a project of type "Windows application", then we use the "Project > Import > a .NET assembly" to import the DotNetProxyLibrary.dll DLL of the library. That's it, the library is now available from our project.

Initializing

The first thing to do is to initialize the library, the best location for this is the initialization section of the application. To make this section appear, select the ".Project" node in the project explorer and then click F2.

The initialization simply consists in calling the static function "RegisterHub" of the "YAPIProxy" class (do not confuse it with the "YAPI" class). We use "usb" as parameter to indicate that we want to use the modules connected by USB, but we could also have indicated the IP address of a VirtualHub or of a YoctoHub. As we are at it, we take the opportunity to also call "YAPIProxy.FreeAPI()" when the application ends.

Initializing the application
Initializing the application



The problem with yapi.dll

DotNetProxyLibrary.dll is a .NET DLL, but it uses yapi.dll, which is a traditional DLL. Unfortunately, we were unable to make WinDEV understand that it needed this later DLL as well. Therefore, we had to copy by hand the "yapi.dll" and "amd64\yapi.dll" files in the "Exe" subdirectory of our project. If you know a way so that WinDEV does it automatically, don't hesitate and tell us how to do it in a comment.

Main window

Initializing

We then add to our project a window containing two "static texts": "Sensor state" and "Relay state".

Defining the main window
Defining the main window


In the initialization code of the window, we declare two variables "r" and "t" corresponding to the relay and to the temperature sensor. We initialize them thanks to "YRelayProxy.FindRelay" and "YTemperatureProxy.FindTemperature" respectively. Here as well, make sure not to confuse them with "YTemperature.FindTemperature" and "YRelay.FindRelay". As we use an empty string as parameter, the functions Findxxx return the first available function, but we could have used a hardware name or a logical name.

Initializing the window
Initializing the window


Refreshing

The center of the application is a "refresh" procedure which

  • Reads the value of the temperature sensor
  • Displays it
  • Update the state of the relay depending on the temperature
  • Displays the state of the relay

Refreshing the window
Refreshing the window


Then we can configure this refresh procedure so that it runs again automatically four times per second.

Configuring the refresh procedure in a loop
Configuring the refresh procedure in a loop



Result

Our application is coded, we only have to run it to see the result.

And besides, it works!
And besides, it works!



Not only does it work, but on top of it the connections/disconnections are managed transparently by the Proxy API: you can connect or disconnect your modules while the application runs without this causing any specific issue.

General considerations

To conclude, here are a few general comments about using the Proxy API with WinDEV:

  • The code presented here makes maximal use of the properties of the different objects rather than their methods. For example, we used t.CurrentValue rather than t.get_currentValue(). This is because the properties are automatically managed in the background while the corresponding methods generate explicit communication with the concerned module each time they are called.
  • Constants of the Proxy API all start with an underscore.
  • It seems that WinDEV doesn't care much for namespaces in .NET assembly. So make sure to not confuse and mix the Yxxx classes and their YxxxProxy Proxy version, otherwise you are quickly going to be in trouble.
  • You have probably noticed that the Proxy API works perfectly well with the evaluation Express version of WinDEV.
  • However, if we presented you with only a Windows application, it's that there is virtually no hope for you to generate with WinDEV a Linux, Android, or iOS application which uses the .NET Proxy library. So much so that we didn't even bother trying.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.