Phidgets project update
The implementation of my
Closet Venting Project was so easy in all the languages I tried. I had to make it slightly more challenging. So, I took the .NET
Assemblies (DLLs) and used
Reflector to disassemble them in to C#
code. Once I had the ".cs" files, I recompiled it on the Linux box, using the latest version of
Mono.
Since all the C function names and parameters were the same in Windows and Linux, I just added one
configuration entry to tell it to use "libphidgets21.so" when the
DllImport calls refer to "Phidgets21.dll". This forwarded all the
wrapped C functions in that DLL to the Linux "so" (shared library).
Then, I took my original C# code and compiled that on the Linux box with Mono too. It worked! :)
Here's the configuration line:
<dllmap dll="phidget21.dll" target="libphidget21.so" />
I had a couple new requirements for myself. I needed it to run as a "service" so that I could restart it and replace it with new versions at will. After a few tries, I realized that I could just use the /etc/inittab. The entry looks like:
FC:2345:respawn:/opt/mono-1.2.5.1/bin/mono /home/tom/FanController/FanController.exe
This sets the ID to "FC" and runs it at runlevels 2,3,4,5. What it also does is automatically respawn the process if it exits. So, I needed a way to make it exit itself. So, I added a very simple .NET Remoting interface into the app to kill it. So, if you call FanController with a "/X", it connects to the currently running version of itself and calls a function. This function sets the ManualResetEvent that the app normally waits on before it exits.
So, an upgrade consists of:
- compile a new version
- run "mono FanController.exe /X"
That's it! I, for one, think that's pretty cool :)