6

我用 OpenHardwareMonitor.dll 引用了我的项目,然后用这段代码创建了新类:

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;
        }

在线上:

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

如果我使用温度,它工作正常并显示温度。但是一旦我将其更改为风扇传感器类型永远不会 == 风扇

如果我正在运行原始的 openhardwaremonitor 程序,它会显示所有内容,甚至是 cpu 风扇速度。

那么为什么在我的代码中它不起作用?

编辑**

忘了在顶部的Form1中提到我有:

private CpuTemperature cpu;

然后在构造函数中:

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=" },
            });

也许cpu的FAN应该有这样的东西,但我找不到。所以我想知道他们如何在原始的 openhwardwaremonitor 中使用它。

试图在源代码中搜索:http: //open-hardware-monitor.googlecode.com/svn/trunk/GUI/

但我没有找到如何让 cpu/gpu 风扇加速。

4

3 回答 3

3

对于仍在为此苦苦挣扎的人,您首先必须在您的 OpenHardwareMonitor.Hardware.Computer 对象中启用主板:

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

然后,您必须深入搜索2 个硬件层。
我的意思是:

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");
                }
            }
        }
    }
}

拥有 subhardware.update(); 非常重要。在那里打电话,否则你只会看到控制型传感器(我从痛苦的经历中知道)。

我希望这有帮助。

参考:
SuperIO
主板

于 2014-12-06T04:21:07.280 回答
1

看起来您需要以下内容才能打开风扇阅读器:

computer.FanControllerEnabled = true;
于 2013-09-26T20:01:19.083 回答
1

您只是在寻找嵌套在 CPU 对象内的传感器。

CPU内部实际上有温度传感器,但风扇既不在CPU内部,也没有连接到它。您的“CPU 风扇”之所以这么称呼,是因为它物理上放置在 CPU 顶部以冷却它。

在树的其他地方寻找风扇传感器。在我的系统上,它们显示在主板对象中。您还可以从放置在 CPU 模块外部的传感器那里找到 CPU 温度的其他测量值。CPU 电压也可以在 CPU 外部检测到,至少在我的系统上是这样,因此嵌套在主板内,而不是硬件监控树中的 CPU。

正如平淡无奇的那样,这myComputer.CPUEnabled = true;可能不足以启用传感器树的其余部分。

于 2013-09-26T20:10:23.257 回答