自动获取CPU温度并将其放入图形中



这是我目前为止的代码:

#RequireAdmin
#include <GUIConstants.au3>
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "rootwmi")
$Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
For $Item in $Instances
  $temp=($Item.CurrentTemperature - 2732) / 10
Next
Opt("GUIOnEventMode", 1)
GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
$GraphWidth = 273
$GraphHeight = 273
$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)
$yMax = 100
$yMin = 0
$xMax = 100
$xMin = 0
GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)
GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)
GUICtrlCreateLabel("TEMP",10,120)
$tmp=GUICtrlCreateLabel($temp,20,140)
GUISetState()
while 1
   sleep(10000)
   $wbemFlagReturnImmediately = 0x10
   $wbemFlagForwardOnly = 0x20
   $strComputer = "."
   $objWMIService = ObjGet("winmgmts:\" & $strComputer & "rootwmi")
   $Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
   For $Item in $Instances
     $temp=($Item.CurrentTemperature - 2732) / 10
   Next
   GUICtrlSetData($tmp, $temp)
WEnd
func close()
    Exit
EndFunc

代码获取CPU温度并制作图形。我的问题是我如何把温度放到图表中,使它每10秒更新一次。谢谢你的帮助。

我使用部分代码制作了这个脚本,获取温度并创建和设置事件。

我添加了GraphGDIPlus库的使用。Au3可以下载并放入您的程序文件-> autoit -> include;链接到GraphGDIPlus。

下面是脚本(注释以便理解):

#RequireAdmin
#include <GraphGDIPlus.au3>
#include <GUIConstants.au3>
AdlibRegister("findTemp", 9000)
AdlibRegister("_Draw_Graph", 10000)
Local $hGUI, $hGraph, $temp, $Counter = 1, $iCheck, $msg, $xVal = 1
$hGUI = GUICreate("", 600, 350) ; create the GUI window
$iCheck = GUICtrlCreateCheckbox("Reset on next interval", 462, 1)
GUISetState() ; show the window
CreateGraph() ; create the graph
findTemp() ; find the temp
_Draw_Graph() ; draw the graph
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Quit()
    EndSwitch
WEnd
Func CreateGraph()
    If IsArray($hGraph) = 0 Then
        $hGraph = _GraphGDIPlus_Create($hGUI, 37, 24, 545, 300, 0xFF000000, 0xFF88B3DD) ; create the graph
    EndIf
    If $Counter > 24 Then
        _GraphGDIPlus_Set_RangeX($hGraph, $xVal, $Counter, 24)
        $xVal += 1
    Else
        _GraphGDIPlus_Set_RangeX($hGraph, 0, 24, 24) ; set the x range from 0 - 24 putting all 24 ticks on screen
        _GraphGDIPlus_Set_RangeY($hGraph, 0, 125, 5) ; set the y range from 0 - 125 only putting 5 ticks on screen
        _GraphGDIPlus_Set_GridX($hGraph, 1, 0xFF6993BE) ; set the x grid
        _GraphGDIPlus_Set_GridY($hGraph, 1, 0xFF6993BE) ; set the y grid
    EndIf
EndFunc   ;==>CreateGraph
Func _Draw_Graph()
    Local $rCheckbox
    $rCheckbox = GUICtrlRead($iCheck)
    If $rCheckbox = 1 Then
        ControlClick($hGUI, "Reset on next interval", $iCheck)
        _GraphGDIPlus_Delete($hGUI, $hGraph) ; delete the graph
        $Counter = 1 ; reset the counter
        $xVal = 1 ; reset the x range counter
        CreateGraph() ; and create the graph again
    EndIf
    If $Counter > 24 Then ; if we've reached the end
        CreateGraph() ; and create the graph again
    EndIf
    _GraphGDIPlus_Set_PenColor($hGraph, 0xFF325D87) ; set the color of the line
    _GraphGDIPlus_Set_PenSize($hGraph, 2) ; set the size of the line
    _GraphGDIPlus_Plot_Start($hGraph, $Counter, 0) ; set the start on the graph plot
    _GraphGDIPlus_Plot_Line($hGraph, $Counter, $temp) ; set the line ending
    _GraphGDIPlus_Refresh($hGraph) ; draw it to the screen
    $Counter += 1 ; add one to our counter
EndFunc   ;==>_Draw_Graph

Func findTemp()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\" & $strComputer & "rootwmi")
    $Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
    For $Item In $Instances
        $temp = ($Item.CurrentTemperature - 2732) / 10 ; set the temp
    Next
EndFunc   ;==>findTemp

Func Quit()
    _GraphGDIPlus_Delete($hGUI, $hGraph) ; delete the graph
    Exit ; get us out
EndFunc   ;==>Quit

相关内容

  • 没有找到相关文章

最新更新