Preview of the new C#, Python and VB .NET libraries

Preview of the new C#, Python and VB .NET libraries

After having announced two weeks ago the preview of version 2.0 of the C++ library, here are version 2.0 of the C#, Python, and Visual Basic .NET libraries. They are also available as previews.






As with the C++ library, the new feature of the 2.0 version is the addition of SSL/TLS support. Thanks to this feature, you can now completely encrypt communications between the application using the library and the VirtualHub or the GatewayHub.

To use a secure connection, you only need to add the "WSS://" prefix to the hub address when you call YAPI::RegisterHub. The WSS prefix stands for "WebSocket Secure" and configures the library to communicate with the WebSocket protocol on a connection encrypted with SSL/TLS.

Here is for example the code to initialize an encrypted connection with a VirtualHub v2.0 in C#:

string errsmg = "";
if (YAPI.RegisterHub("wss://vhub.example.com", ref errmsg) != YAPI.SUCCESS) {
    Console.WriteLine("RegisterHub error: " + errmsg);
    Environment.Exit(0);
}



The same code in Python:

errmsg = YRefParam()
if YAPI.RegisterHub("wss://vhub.example.com", errmsg) != YAPI.SUCCESS:
    sys.exit("RegisterHub error: " + errmsg.value)



And finally the Visual Basic .NET version:

Dim errmsg As String = ""
If (YAPI.RegisterHub("wss://vhub.example.com", errmsg) <> YAPI_SUCCESS) Then
    Console.WriteLine("RegisterHub error: " + errmsg)
    Application.Exit()
End If



Note that you can force the use of the old HTTP protocol, but still using an encrypted connection, with the "https://" prefix.

Backward compatibility

As is our custom, we made sure to maintain backward compatibility, in order to facilitate the transition to this new version. Internally, many things were modified to support end-to-end encryption, however, classes, methods, and functions already documented in version 1.0 are still present and working.

If you already have an application running with version 1.10 of the Yoctopuce library, transition to version 2.0 is extremely simple. You must simply replace the Yoctopuce library source files with those of version 2.0 and recompile the application. The application will work in the same way.

Obviously, if you want to use communication encryption, you'll have to add the "wss://" or "https://" prefix when calling the RegisterHub method.

Download

For now, these three libraries are only available as a .zip archive on our Libraries page in the new Preview section.

When these libraries become stable enough, we'll publish then on GitHub, PiPY, and NuGet.

YAPI 2.0

If you compare the source files of version 1.10 and 2.0 of these libraries, you can see only a few changes. The reason is that most of the modifications and most of the new features are located in the low level "YAPI" layer.

This low level layer is written in C and only a compiled version in the form of a dynamic library or DLL is included in the archive. The source code of this library is not included in the archive for clarity reasons, but it is in fact the same code used in the C++ v2.0 library. If you need to inspect the code or to recompile these libraries, you can simply download the C++ library and recompile it.

Limitations

Currently, SSL support for the Python library is not available on the mips and mipsel platforms.

For the library to establish an encrypted connection, both parts must support SSL/TLS. At the present time, only the VirtualHub v2.0 and the GatewayHub support this feature. It is therefore not yet possible to use this feature to communicate with a YoctoHub.

Finally, if we release this new version of the library with the "Preview" mention, it's that we want to keep the possibility to make changes breaking backward compatibility within version 2.0, but only on new features.

Feedback

Don't hesitate to contact support if you have trouble using this new version of the library or if you have suggestions.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.