How do i get the cpu fan speed using the OpenHardwareMonitor lib?

open hardware monitor
cpu temperature monitor
gpu temp monitor
cpu temperature monitor windows 10
best cpu temp monitor
core temp
cpu temperature gadget
speedfan

I referenced my project with OpenHardwareMonitor.dll And then created new class with this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenHardwareMonitor.Hardware;
using System.Diagnostics;
using DannyGeneral;
using System.Windows.Forms;
using System.Threading;

namespace HardwareMonitoring
{
    class Core
    {
        public static Form1 form1;

        private static List<float?> cpuSensorValues = new List<float?>();
        private static List<float?> gpuSensorValues = new List<float?>();
        Computer myComputer;
        Computer computer;

        public Core(Form1 f)
        {
            form1 = f;
            myComputer = new Computer();
            myComputer.CPUEnabled = true;
            myComputer.Open();
            computer = new Computer();
            computer.Open();
            computer.GPUEnabled = true;
        }

        public float? cpuView(bool pause , CpuTemperature cpuTemp , Form1 f1 , List<string> myData , float? myCpuTemp , Button b1)
        {
            try
            {
                if (pause == true)
                {
                }
                else
                {
                    Trace.WriteLine("");
                    foreach (var hardwareItem in myComputer.Hardware)
                    {
                        if (hardwareItem.HardwareType == HardwareType.CPU)
                        {
                            hardwareItem.Update();
                            foreach (IHardware subHardware in hardwareItem.SubHardware)
                                subHardware.Update();

                            foreach (var sensor in hardwareItem.Sensors)
                            {
                                cpuTemp.SetValue("sensor", sensor.Value.ToString());
                                if (sensor.SensorType == SensorType.Fan)//Temperature)
                                {
                                    sensor.Hardware.Update();
                                    cpuTemp.GetValue("sensor", sensor.Value.ToString());
                                    if (!f1.IsDisposed)
                                    {
                                        Thread.Sleep(1000);
                                        f1.Invoke(new Action(() => myData.Add("Cpu Temeprature --- " + sensor.Value.ToString())));
                                    }
                                    myCpuTemp = sensor.Value;
                                    //if (sensor.Value > 60)
                                    //{
                                        cpuSensorValues.Add(sensor.Value);
                                        if (cpuSensorValues.Count == 300)
                                        {
                                            float a = ComputeStats(cpuSensorValues).Item1;
                                            float b = ComputeStats(cpuSensorValues).Item2;
                                            float c = ComputeStats(cpuSensorValues).Item3;
                                            Logger.Write("********************************");
                                            Logger.Write("CPU Minimum Temperature Is ===> " + a);
                                            Logger.Write("CPU Maximum Temperature Is ===> " + b);
                                            Logger.Write("CPU Average Temperature Is ===> " + c);
                                            Logger.Write("********************************" + Environment.NewLine);                                            
                                            cpuSensorValues = new List<float?>();
                                        }
                                        b1.Enabled = true;
                                    //}
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception err)
            {
                Logger.Write("There was an exception: " + err.ToString());
            }
            return myCpuTemp;
        }

On the line:

if (sensor.SensorType == SensorType.Fan)//Temperature)

If i'm using the Temperature it's working fine and showing the temperature. But once i change it to Fan the SensorType never == to the Fan

And if i'm running the original openhardwaremonitor program it's showing all the stuff even the cpu fan speed.

So why in my code it's not working ?

EDIT**

Forgot to mention that in Form1 at the top i have:

private CpuTemperature cpu;

Then in the constructor:

cpu = new CpuTemperature(new Dictionary<string, string>
            {
                { "/intelcpu/0/temperature/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9/+NX6N3/TJm9/5f/01fw1+fosnv+A/+OlfS37/jZ/s/Lpv9fff6Ml/NTef/yZPnozc5679b+i193//TQZ+/w2Dd+P9/sZeX/67v/GTf/b3iP3u4/ObBL//73+i+f039+D8Zk/+xz/e/P6beu2TQZju8yH8f6OgzcvPv/U3/Rb8+z/0f/9b/+yfaOn8079X6fr6Cws7ln/iHzNwflPv99/wyS/+xY4+v/evcJ+733+jJ5//Cw7/4ndy9Im3+U2e/Fbnrk31C93vrt/fyPvdb+N//hsF7/4/AQAA//9NLZZ8WAIAAA==" },
                { "/intelcpu/0/load/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9++mpwcv/md/9df89egZ/xX/ym/5y/4D37618Lv7ya//u+58+u+5d9/z7/5t/w9/6u5fP5bH/6av+eTkXyefXxp26ONaf/v/dG/sf39D/rvnv4e5vc/0IP56/waK/vuHzf5I38P8/tv+mv8Rbb9f0pwTF9/zr/1X9vP/8I//+/6Pf7Z30N+/zdf/HX29zd/859q4aCNP5b//U+U3/+7f+zXOjZwfqvDX/V7/o9/vPz+a1G/pv0f+fGlhfk7eZ//N3/0v28//5X0u/n8Cxq7+f1X/tHft20A5x8a/W5/02+BP36Nf+j/nv8XfzrT+c2//Ob4p3+vktvUhNs/+xcWikP6e/4T/5jS5M8/sL8vP/5ff49f/Ivl9//sHzv6PX/vXyG//9R/94/9HuZ34P/5vyC//3W/5e/1exa/k+Bw4bUBnU2bP4Xg/1bn0uafeTH6PatfKL//N3/0t2y/gG9+/8+IzqYNxmU+/+jwX7afY67/nwAAAP//GYSA31gCAAA=" },
            });

Maybe there should be something like this for the FAN of the cpu but i couldn't find any. So i wonder how they use it in the original openhwardwaremonitor.

Tried to search in the source code : http://open-hardware-monitor.googlecode.com/svn/trunk/GUI/

But i didn't find how to get the cpu/gpu fans speed.

For anybody still struggling with this, you first have to enable the mainboard in your OpenHardwareMonitor.Hardware.Computer object:

Computer computerHardware = new Computer();
computerHardware.MainboardEnabled = true;

You then have to search 2 hardware layers deep. By this I mean:

foreach (var hardware in computerHardware.Hardware)
{
    // This will be in the mainboard
    foreach (var subhardware in hardware.SubHardware)
    {
        // This will be in the SuperIO
        subhardware.Update();
        if (subhardware.Sensors.Length > 0) // Index out of bounds check
        {
            foreach (var sensor in subhardware.Sensors)
            {
                // Look for the main fan sensor
                if (sensor.SensorType == SensorType.Fan && sensor.Name.Equals("Fan #1", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("CPU Fan Speed:" + Convert.ToString((int)(float)sensor.Value) + " RPM");
                }
            }
        }
    }
}

It is very important that you have the subhardware.update(); call in there, otherwise you will only see control type sensors (I know from painful experience).

I hope this helps.

References: SuperIO Mainboard

Using the Code. The code is implemented as a Visual Studio 2015 self-contained project. It includes OpenHardwareMonitorLib.dll version 0.8.0  The Open Hardware Monitor is a free open source software that monitors temperature sensors, fan speeds, voltages, load and clock speeds of a computer. The Open Hardware Monitor supports most hardware monitoring chips found on todays mainboards. The CPU temperature can be monitored by reading the core temperature sensors of Intel and AMD processors.

Looks like you need the following to turn on the fan reader:

computer.FanControllerEnabled = true;

Using the Code. The code is implemented as a Visual Studio 2015 self-contained project. It includes OpenHardwareMonitorLib.dll version 0.8.0  The Open Hardware Monitor is a free open source software that monitors temperature sensors, fan speeds, voltages, load and clock speeds of a computer. Step 1: Download Open hardware monitor. Download the lastest Open hard waremonitor software here. You can open the .exe file first to see your hardware information, CPU useage , etc.

You're only looking for sensors nested inside the CPU object.

There actually are temperature sensors inside the CPU, but the fans are neither inside the CPU nor connected to it. Your "CPU fan" is called that because it's physically placed atop the CPU to cool it.

Look for Fan sensors elsewhere in the tree. On my system they're displayed within the motherboard object. You'll find additional measurements of CPU temperature there as well, from sensors placed on the outside of the CPU module. The CPU voltage as well is sensed outside the CPU, at least on my system, and therefore nested within the motherboard and not the CPU in the hardware monitoring tree.

As bland noted, the myComputer.CPUEnabled = true; may not be sufficient to enable the rest of the sensor tree.

I'm using OpenHardwareMonitorLib.dll in my project. I have this function in a class: public static void cpuView(bool pause , CpuTemperature  The Open Hardware Monitor is a free open source software that monitors temperature sensors, fan speeds, voltages, load and clock speeds of a computer. Step 1: Download Openhardwaremonitor. Download the lastest Openhardwaremonitor software here. You can open the .exe file first to see your hardware information, CPU usage, etc.

The OpenHardwareMonitorLib.dll is in the OpenHardwareMonitor folder. DEMO 3: Cooling Fan Control System Based on CPU Temperature I have an issue to get information from internal fan on Fujitsu computers using latest version of OHM tool. Also I have tested latest OHM source code v.8.0.5.0 Alpha. The information from internal fan does not present under UI.

However, open hardware monitor does not display the fan speeds could you upload a report from ohm? you should use the latest Version! display a lot of information like CPU temp on my i7-7700 but this one works! Tell Open Hardware Monitor to show the gadget. By pulling down the view menu and checking it. Then, still in view right click on the items you want showing and choose to show in Gadget. Then put the gadget somewhere out of the way. I choose to just show the speed of 1 core and the temperature of the cpu package instead of more stuff.

The OpenHardwareMonitorLib.dll is in the OpenHardwareMonitor folder. DEMO 3: Cooling fan Control system based on CPU temperature. I'm trying to use OpenHardwareMonitor to get a reading on the diagnostics of my hardware. If you've ever tried using OHM you know that there is very little documentation on it yet to my knowledge there is no other open source library that is as accurate and robust. I've been able to get load and clock speed from the CPU but not the temperature.

Comments
  • The fan number doesn't necessarily mean it's the CPU fan. A good practice would be to have a configuration file that tells what number is what on the motherboard.
  • Is that not for actually controlling (changing) fan speeds?
  • @BenVoigt It is not solely for it. See OP's .GPUEnabled = true; and CPUEnabled = true; which are same naming convention. Appears that it is reading sensors and controlling - no distinction made between the two. Note my non-definitive opening words though.
  • Uggh. Well, that's half his problem. The other half is related.