CPU温度监控

发布于 2024-09-03 13:31:18 字数 191 浏览 6 评论 0原文

对于一个编程项目,我想访问 CPU 和 GPU 的温度读数。我将使用 C#。从各种论坛中,我得到的印象是,您需要特定的信息和开发人员资源才能访问各种主板的信息。我有一块 MSI NF750-G55 板。 MSI 的网站上没有我要查找的任何信息。我尝试了他们的技术支持,与我交谈的代表表示他们没有任何此类信息。必须有一种方法来获取该信息。

有什么想法吗?

For a programming project I would like to access the temperature readings from my CPU and GPUs. I will be using C#. From various forums I get the impression that there is specific information and developer resources you need in order to access that information for various boards. I have a MSI NF750-G55 board. MSI's website does not have any of the information I am looking for. I tried their tech support and the rep I spoke with stated they do not have any such information. There must be a way to obtain that info.

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

℡Ms空城旧梦 2024-09-10 13:31:18

至少对于 CPU 方面的事情,您可以使用 WMI。

命名空间\对象是 root\WMI, MSAcpi_ThermalZoneTemperature

示例代码:

ManagementObjectSearcher searcher = 
    new ManagementObjectSearcher("root\\WMI",
                                 "SELECT * FROM MSAcpi_ThermalZoneTemperature");

ManagementObjectCollection collection = 
    searcher.Get();

foreach(ManagementBaseObject tempObject in collection)
{
    Console.WriteLine(tempObject["CurrentTemperature"].ToString());
}

这将为您提供原始格式的温度。你必须从那里进行转换:

kelvin = raw / 10;

celsius = (raw / 10) - 273.15;

fahrenheit = ((raw / 10) - 273.15) * 9 / 5 + 32;

For at least the CPU side of things, you could use WMI.

The namespace\object is root\WMI, MSAcpi_ThermalZoneTemperature

Sample Code:

ManagementObjectSearcher searcher = 
    new ManagementObjectSearcher("root\\WMI",
                                 "SELECT * FROM MSAcpi_ThermalZoneTemperature");

ManagementObjectCollection collection = 
    searcher.Get();

foreach(ManagementBaseObject tempObject in collection)
{
    Console.WriteLine(tempObject["CurrentTemperature"].ToString());
}

That will give you the temperature in a raw format. You have to convert from there:

kelvin = raw / 10;

celsius = (raw / 10) - 273.15;

fahrenheit = ((raw / 10) - 273.15) * 9 / 5 + 32;
残龙傲雪 2024-09-10 13:31:18

在 Windows 上进行硬件相关编码的最佳方法是使用 WMI 是 Microsoft 的一个Code Creator 工具,该工具将根据您在硬件相关数据中查找的内容以及您想要使用的 .Net 语言为您创建代码。

目前支持的语言有:C#、Visual Basic、VB Script。

The best way to go for hardware related coding on windows is by using WMI which is a Code Creator tool from Microsoft, the tool will create the code for you based on what you are looking for in hardware related data and what .Net language you want to use.

The supported langauges currently are: C#, Visual Basic, VB Script.

沫尐诺 2024-09-10 13:31:18

请注意,MSAcpi_ThermalZoneTemperature 并不提供 CPU 的温度,而是提供主板的温度。另请注意,大多数主板不通过 WMI 实现此功能。

您可以尝试一下开放硬件监视器,尽管它缺乏对最新处理器的支持。

internal sealed class CpuTemperatureReader : IDisposable
{
    private readonly Computer _computer;

    public CpuTemperatureReader()
    {
        _computer = new Computer { CPUEnabled = true };
        _computer.Open();
    }

    public IReadOnlyDictionary<string, float> GetTemperaturesInCelsius()
    {
        var coreAndTemperature = new Dictionary<string, float>();

        foreach (var hardware in _computer.Hardware)
        {
            hardware.Update(); //use hardware.Name to get CPU model
            foreach (var sensor in hardware.Sensors)
            {
                if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
                    coreAndTemperature.Add(sensor.Name, sensor.Value.Value);
            }
        }

        return coreAndTemperature;
    }

    public void Dispose()
    {
        try
        {
            _computer.Close();
        }
        catch (Exception)
        {
            //ignore closing errors
        }
    }
}

官方源下载 zip 文件,解压并添加对项目中 OpenHardwareMonitorLib.dll 的引用。

Note that MSAcpi_ThermalZoneTemperature does not give you the temperature of the CPU but rather the temperature of the motherboard. Also, note that most motherboards do not implement this via WMI.

You can give the Open Hardware Monitor a go, although it lacks support for the latest processors.

internal sealed class CpuTemperatureReader : IDisposable
{
    private readonly Computer _computer;

    public CpuTemperatureReader()
    {
        _computer = new Computer { CPUEnabled = true };
        _computer.Open();
    }

    public IReadOnlyDictionary<string, float> GetTemperaturesInCelsius()
    {
        var coreAndTemperature = new Dictionary<string, float>();

        foreach (var hardware in _computer.Hardware)
        {
            hardware.Update(); //use hardware.Name to get CPU model
            foreach (var sensor in hardware.Sensors)
            {
                if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
                    coreAndTemperature.Add(sensor.Name, sensor.Value.Value);
            }
        }

        return coreAndTemperature;
    }

    public void Dispose()
    {
        try
        {
            _computer.Close();
        }
        catch (Exception)
        {
            //ignore closing errors
        }
    }
}

Download the zip from the official source, extract and add a reference to OpenHardwareMonitorLib.dll in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文