(转)aardio 利用开源库OpenHardwareMonitor获取CPU或显卡温度
By
admin
at 2018-08-03 • 1人收藏 • 3320人看过
以下文章整理自aar官方培训群以备日后查看:
aardio官方论坛上有人问怎么调用c#代码利用开源的dll获取cpu温度,一鹤jacen在培训群里给出了如下的代码:
import win.ui; /*DSG{{*/ var mainForm = win.form(text="aardio 利用开源库OpenHardwareMonitor获取CPU或显卡温度";right=791;bottom=699) mainForm.add( edit={cls="edit";left=8;top=4;right=787;bottom=696;db=1;dl=1;dr=1;dt=1;edge=1;multiline=1;z=1} ) /*}}*/ import dotNet; var clr = dotNet.clr(); var app = clr.createAppDomain(); //官网 http://openhardwaremonitor.org var dll = app.loadFile("\dll\OpenHardwareMonitorLib.dll"); var computer = dll.createInstance("OpenHardwareMonitor.Hardware.Computer"); computer.MainboardEnabled = true; computer.CPUEnabled = true; computer.HDDEnabled = true; computer.RAMEnabled = true; computer.GPUEnabled = true; computer.FanControllerEnabled = true; computer.Open(); var HardwareType = { [0] = "Mainboard"; [1] = "SuperIO"; [2] = "CPU"; [3] = "GpuNvidia"; [4] = "GpuAti"; [5] = "TBalancer"; [6] = "Heatmaster"; [7] = "HDD"; } for(i,hardware in computer.Hardware){ mainForm.edit.print( hardware.Name,HardwareType[hardware.HardwareType] ); hardware.Update() //下面这行是多余的 //for(k,v in hardware.SubHardware) v.Update() for(k,sensor in hardware.Sensors){ mainForm.edit.print("温度",sensor.Name,sensor.Value ) } } mainForm.show() win.loopMessage();
从没调用过C#的dll,刚好学习下。
2 个回复 | 最后更新于 2022-11-25
登录后方可回帖
从官方下载的openhardwaremonitor-v0.9.6,调用例子,提示 hardware.Update() 这里出错,null