Some time ago, someone asked us if we had planned a Yoctopuce library for the Mono framework. We didn't have such plans, however we promised to have a look at it. Let's do that together, shall we ?
Mono is an open-source implementation of C# and it is compatible with C# .NET. "What's the point?" you may ask, since Microsoft gives C# .NET for free. Well, there is a point: applications compiled with Mono can run on Windows, as well as Linux and Mac OS X. So, can we make the C# Yoctopuce library work on Linux or Mac OS X ?
The Yoctopuce API is made of two layers: the high-level API, which handles device "abstract" features such as Temperature, Voltage, Relay etc. and the low-level API which handles the communications with the hardware.
The high-level API is always written using only the target language, which is C# in our case. No fancy system calls are made in the high-level API, so the odds are it will work on any platform. The low-level API is written in C, and is available in multiple formats: source files, pre-compiled libraries, static or dynamic.
The Yoctopuce low level API is available as a dynamic library
The Yoctopuce library for C# is distributed with the yapi.dll library only, which makes sense since (until now) the C# API was targeted for Windows only.
It's quite easy to check if the Yoctopuce API works with Mono on Windows. For instance, if we want to test the Yocto-Temperature demo program, we only need to copy main.cs, yocto_api.cs,yocto_temperature.cs et yapi.dll in a folder, type gmcs *.cs and that's it. We get a working executable file. So Mono does seem to be compatible with C# .NET :-)
Obviously, the difficulty is to do the same with other operating systems. To make it simple, we need to tell Mono to load the library matching the operating system instead of yapi.dll. Luckily, it looks like this has been taken care of :-) Mono can use a little configuration file describing how to match a DLL with an equivalent dynamic library for the others operating systems.
<configuration> <dllmap dll="yapi.dll" os="linux" target="libyapi.so.1.0.1"/> <dllmap dll="yapi.dll" os="osx" target="libyapi.dylib"/> </configuration>
So, to make the C# Yoctopuce API work with the OS of your choice, you need to retrieve the dynamic library for your OS (you can find it in the C++ API), copy the contents of the configuration file above in a file named executable_name.config and that's it.
Yocto-Temperature example program compiled with Mono on Linux
To be completely honest, we had to make some minor modifications on the high-level API to make it work with Mono. One last word: if you planned to use Mono on a Raspberry Pi, you might be a bit disappointed. Mono does not support the HardFloat architecture (HF) yet, so floating point calculus doesn't work very well. You will be able to control a Yoctopuce relay, but until Mono fixes this issue, reading temperature from a Yoctopuce sensor is off the mark.