windows 以编程方式访问笔记本电脑上的 CPU 风扇?(视窗)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/485448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatically access CPU fan on a laptop? (Windows)
提问by user9665
Is there a Windows standard way to do things such as "start fan", "decrease speed" or the like, from C/C++?
是否有 Windows 标准方法可以从 C/C++ 执行诸如“启动风扇”、“降低速度”等操作?
I have a suspicion it might be ACPI, but I am a frail mortal and cannot read that kind of documentation.
我怀疑它可能是 ACPI,但我是一个虚弱的凡人,无法阅读那种文档。
Edit: e.g. Windows 7 lets you select in your power plan options such as "passive cooling" (only when things get hot?) vs. "active cooling" (keep the CPU proactively cool?). It seems the OS does have a way to control the fan generically.
编辑:例如,Windows 7 允许您在电源计划选项中进行选择,例如“被动冷却”(仅当事情变热时?)与“主动冷却”(保持 CPU 主动冷却?)。似乎操作系统确实有一种方法可以一般地控制风扇。
回答by Boris
I am at the moment working on a project that, among other things, controls the computer fans. Basically, the fans are controlled by the superIO chip of your computer. We access the chip directly using port-mapped IO, and from there we can get to the logical fan device. Using port-mapped IO requires the code to run in kernel mode, but windows does not supply any drivers for generic port IO (with good reason, since it is a very powerful tool), so we wrote our own driver, and used that.
我目前正在做一个项目,其中包括控制电脑风扇。基本上,风扇由计算机的 superIO 芯片控制。我们使用端口映射 IO 直接访问芯片,从那里我们可以访问逻辑风扇设备。使用端口映射 IO 需要代码在内核模式下运行,但 windows 不为通用端口 IO 提供任何驱动程序(有充分的理由,因为它是一个非常强大的工具),所以我们编写了自己的驱动程序,并使用了它。
If you want to go down this route, you basically need knowledge in two areas: driver development and how to access and interpret superIO chip information. When we started the project, we didn't know anything in either of these areas, so it has been learning by browsing, reading and finally doing. To gain the knowledge, we have been especially helped by looking at these links:
如果你想走这条路,你基本上需要两个方面的知识:驱动程序开发以及如何访问和解释superIO芯片信息。当我们开始这个项目时,我们对这两个领域都一无所知,所以它一直在浏览、阅读和最终实践中学习。为了获得知识,我们通过查看以下链接获得了特别的帮助:
- The WDK, which is the Windows Driver Kit. You need this to compile any driver you write for windows, With it comes a whole lot of source code for example drivers, including a driver for general port-mapped IO, called portio.
- WinIOhas source code for a driver in C, a dll in C that programmatically installs and loads that driver, and some C# code for a GUI, that loads the dll and reads/writes to the ports. The driver is very similar to the one in portio.
- lm-sensorsis a linux project, that, among other things, detects your superIO chip. /prog/detect/sensors-detect is the perl program, that does the detecting, and we have spent some time going through the code to see how to interface with a superIO chip.
- When we were going through the lm-sensors code, it was very nice to have tools like RapidDriverand RW-everything, since they allowed us to simulate a run of sensors-detect. The latter is the more powerful, and is very helpful in visualising the IO space, while the former provides easier access to some operations which map better to the ones in sensors-detect (read/write byte to port)
- Finally, you need to find the datasheet of your superIO chip. From the examples, that I have seen, the environment controllers of each chip provide similar functionality (r/w fan speed, read temperature, read chip voltage), but vary in what registers you have to write to in order to get to this functionality. Thisplace has had all the datasheets, we have needed so far.
- 该WDK,它是Windows驱动程序工具包。你需要它来编译你为 Windows 编写的任何驱动程序,它带有大量的源代码,例如驱动程序,包括一个用于通用端口映射 IO 的驱动程序,称为 portio。
- WinIO有一个 C 驱动程序的源代码,一个 C 语言中的 dll 以编程方式安装和加载该驱动程序,以及一些用于 GUI 的 C# 代码,它加载 dll 并读取/写入端口。驱动程序与部分驱动程序非常相似。
- lm-sensors是一个 linux 项目,除其他外,它可以检测您的 superIO 芯片。/prog/detect/sensors-detect 是 perl 程序,它进行检测,我们花了一些时间浏览代码以了解如何与 superIO 芯片接口。
- 当我们浏览 lm-sensors 代码时,有像RapidDriver和RW-everything这样的工具非常好,因为它们允许我们模拟传感器检测的运行。后者功能更强大,对IO空间的可视化非常有帮助,而前者更容易访问一些操作,这些操作更好地映射到sensors-detect(读/写字节到端口)中的操作
- 最后,您需要找到您的 superIO 芯片的数据表。从我所看到的示例中,每个芯片的环境控制器提供相似的功能(r/w 风扇速度、读取温度、读取芯片电压),但为了获得此功能而必须写入的寄存器有所不同. 这个地方有我们迄今为止需要的所有数据表。
回答by Anonymous Coward
If you want something real quick to just lower fans to a level where you know things won't overheat, there's the speedfan program to do so. Figuring out how to configure it in the early versions to automatically lower fans to 50% on computer startup was so painful that my first approach was to simply byte-patch it to start the only superio managed fan I had at lower speed. The newer versions are still bit tough but it's doable - there's a graphical slider system that looks like audio equalizer except that the x axis is temp and y is fan speed. You drag them down one by one. After you figure out how to get manual control for the fan you want, this is next step.
如果您想要真正快速地将风扇降低到您知道不会过热的水平,那么可以使用 speedfan 程序。弄清楚如何在早期版本中将其配置为在计算机启动时自动将风扇降低到 50% 非常痛苦,以至于我的第一种方法是简单地对它进行字节修补以启动我拥有的唯一一个以较低速度运行的超级管理风扇。较新的版本仍然有点困难,但它是可行的 - 有一个图形滑块系统,看起来像音频均衡器,但 x 轴是温度,y 是风扇速度。你将它们一一拖下。在您弄清楚如何手动控制您想要的风扇后,这是下一步。
There's a project to monitor hardware (like fans) with C#: http://code.google.com/p/open-hardware-monitor/
有一个用 C# 监控硬件(如风扇)的项目:http: //code.google.com/p/open-hardware-monitor/
I haven't extensively looked at it, but the source code and use of WinRing0.sys atleast gives the impression that if you know what fan controller you have and have the datasheet, it should be modifiable to also set values instead of just getting them. I don't know what tool is suited (beside kernel debugger) to look at what Speedfan does, if you preferred to snoop around and imitate speedfan instead of looking at the datasheets and trying things out.
我没有仔细研究过它,但是 WinRing0.sys 的源代码和使用至少给人的印象是,如果您知道自己拥有什么风扇控制器并拥有数据表,那么它应该是可修改的以设置值而不是仅仅获取它们. 我不知道什么工具适合(除了内核调试器)来查看 Speedfan 的功能,如果您更喜欢四处窥探和模仿 speedfan,而不是查看数据表并尝试一下。
回答by SoapBox
Yes, It would be ACPI, and to my knowledge windows doesn't give much/any control over that from user space. So you'd have to start mucking with drivers, which is nigh impossible on windows.
是的,这将是 ACPI,据我所知,Windows 不会从用户空间对其进行太多/任何控制。因此,您必须开始使用驱动程序,这在 Windows 上几乎是不可能的。
That said, google revealsthere are a few open source windows libraries for this for specific hardware... so depending on your hardware you might be able to find something.
也就是说,谷歌透露有一些针对特定硬件的开源 Windows 库......因此,根据您的硬件,您可能会找到一些东西。
回答by Kris Kumler
ACPI may or may not allow you to adjust the fan settings. Some BIOS implementations may not allow that control though -- they may force control depending on the BIOS/CMOS settings. One might be hard-pressed for a gooduse case where the BIOS control (even customized) is insufficient. I have come across situations where the BIOS control indeed was insufficient, but not for all possible motherboard platforms.
ACPI 可能允许也可能不允许您调整风扇设置。不过,某些 BIOS 实现可能不允许进行这种控制——它们可能会根据 BIOS/CMOS 设置强制进行控制。对于BIOS 控制(甚至自定义)不足的良好用例,可能很难。我遇到过 BIOS 控制确实不足的情况,但并非适用于所有可能的主板平台。
回答by zdan
WIndows Management Instrumentation library (WMI) does provide a Win32_Fan Classand even a SetSpeed method. Alas, the docs say this is not implemented, so I guess it's not very helpful. But you may be able to control things by setting the power state.
WINdows Management Instrumentation 库 (WMI) 确实提供了一个Win32_Fan 类甚至一个 SetSpeed 方法。唉,文档说这没有实现,所以我想这不是很有帮助。但是您可以通过设置电源状态来控制事物。