Retrieve CPU temperature

Lately I had to check the CPU temperature in a critical acquisition system, and I thought it could be a good thing to share here. I know there are several applications to do this and much more, but getting it from our code allows to react conveniently to any event.

Now, IMPORTANT, the VI doesn't work on its own. First you must download the Open Hardware Monitor. Extract OpenHardwareMonitorLib.dll from the zip file and put it in the same folder the VI is located. The objects exposed in it use .NET Framework 2.0 and above, but that shouldn't be a problem in any modern machine. On the other hand, this works only for Windows, obviously. And remember, the application (either an .exe or the LabVIEW IDE) must run with administrator rights (otherwise you'll get error 1172).

Download (VI for LabVIEW 2016)

Now, if you haven't worked with .NET functions in LabVIEW, this can be a good opportunity to familiarize with them. Let's take a look at the code. First we have the constructor, in this case the Computer class. If you place a blank constructor node from the .NET palette, a dialog opens and you must browse to select the previous DLL, and then the Computer object and the first (void) constructor. From there on, the code uses the exposed properties and methods to retrieve the sensors and average the CPU temperature. As easy as that. And then close the open references to avoid memory leaks.

Obviously, Open Hardware Monitor offers a lot more functionalities to monitor your system, explore them freely.

Comentarios

Publicar un comentario

Entradas populares de este blog

SNMP library for LabVIEW

Base64 Encoding