如何使用Open Hardware Monitor获取GPU和主板温度?

时间:2018-10-24 14:26:35

标签: c# winforms temperature openhardwaremonitor

我正在尝试使用Open Hardware Monitor代码获取CPU,GPU和主板的温度。我遇到了一个非常有用的页面,该页面很好地解释了我的情况,并为我提供了所需的结果,但仅适用于CPU温度。这里是链接: https://www.instructables.com/id/Using-Open-Hardware-Monitor-to-Get-CPU-Temperature/

这正是我需要的教程类型,但适用于GPU和主板温度。到目前为止,我尝试执行以下操作(它都返回了一个空字符串):

public string getGraphicsTemp()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();
            computer.Open();
            computer.GPUEnabled = true;
            computer.Accept(updateVisitor);
            string res = "";
            for (int i = 0; i < computer.Hardware.Length; i++)

            {
                if (computer.Hardware[i].HardwareType == HardwareType.GpuAti)

                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)

                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) res = String.Concat(res, (computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "ºC" + "\r"));
                    }

                }
            }
            computer.Close();
            return res;
        }

        public string getMotherboardTemp()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();
            computer.Open();
            computer.MainboardEnabled= true;
            computer.Accept(updateVisitor);
            string res = "";
            for (int i = 0; i < computer.Hardware.Length; i++)

            {
                if (computer.Hardware[i].HardwareType == HardwareType.Mainboard)

                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)

                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) res = String.Concat(res, (computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "ºC" + "\r"));
                    }

                }
            }
            computer.Close();
            return res;
        }

此外,这是CPU部件的代码,这是到目前为止唯一可用的代码:

 public string getCPUTemp()
        {
            UpdateVisitor updateVisitor = new UpdateVisitor();
            Computer computer = new Computer();
            computer.Open();
            computer.CPUEnabled = true;
            computer.Accept(updateVisitor);
            string res = "";
            for (int i = 0; i < computer.Hardware.Length; i++)

            {
                if (computer.Hardware[i].HardwareType == HardwareType.CPU)

                {
                    for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)

                    {
                        if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) res = String.Concat(res, (computer.Hardware[i].Sensors[j].Name + ": " + computer.Hardware[i].Sensors[j].Value.ToString() + "ºC" + "\r"));
                    }

                }
            }

            computer.Close();
            return res;
        }

在此先感谢您能解决此问题。

0 个答案:

没有答案