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

Graph 自动获取CPU温度并将其放入图形中,graph,cpu,autoit,temperature,Graph,Cpu,Autoit,Temperature,这是我目前掌握的代码: #RequireAdmin #include <GUIConstants.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi") $Instances = $objWMIService.Insta

这是我目前掌握的代码:

#RequireAdmin
#include <GUIConstants.au3>
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$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 & "\root\wmi")
   $Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
   For $Item in $Instances
     $temp=($Item.CurrentTemperature - 2732) / 10
   Next
   GUICtrlSetData($tmp, $temp)
WEnd
func close()
    Exit
EndFunc
#RequireAdmin
#包括
$WBEMFlagReturnInstance=0x10
$wbemFlagForwardOnly=0x20
$strComputer=“”
$objWMIService=ObjGet(“winmgmts:\\”和$strComputer&“\root\wmi”)
$Instances=$objWMIService.InstancesOf(“MSAcpi_热区温度”)
对于$Instances中的$Item
$temp=($Item.CurrentTemperature-2732)/10
下一个
选项(“GUIOnEventMode”,1)
GUICreate(“、340、330)
GUISetOnEvent($GUI\u事件\u关闭,“关闭”)
$GraphWidth=273
$GraphHeight=273
$graph=GUICtrlCreateGraphic(48,15,$GraphWidth,$GraphHeight)
GUICTRLESTBKCOLOR(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)
$yMax=100
$yMin=0
$xMax=100
$xMin=0
GUICtrlCreateLabel($yMax,15,10,20,15,$SS_右)
GUICtrlCreateLabel($yMin,15280,20,15,$SS_RIGHT)
GUICtrlCreateLabel($xMax,307295,20,15,$SS_中心)
GUICtrlCreateLabel($xMin,38295,20,15,$SS_中心)
GUICtrlCreateLabel(“临时”,10120)
$tmp=GUICtrlCreateLabel($temp,20140)
GUISetState()
而1
睡眠(10000)
$WBEMFlagReturnInstance=0x10
$wbemFlagForwardOnly=0x20
$strComputer=“”
$objWMIService=ObjGet(“winmgmts:\\”和$strComputer&“\root\wmi”)
$Instances=$objWMIService.InstancesOf(“MSAcpi_热区温度”)
对于$Instances中的$Item
$temp=($Item.CurrentTemperature-2732)/10
下一个
GUICtrlSetData($tmp,$temp)
温德
func close()
出口
EndFunc

该代码获取CPU温度并生成一个图表。我的问题是如何将温度输入到图表中,并使其每10秒更新一次。感谢您的帮助。

我使用了部分代码制作了此脚本,包括获取温度以及创建和设置温度事件

我添加了GraphGDIPlus.au3库的使用,可以下载该库并将其放入程序文件->autoit->include;链接到

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

#RequireAdmin
#包括
#包括
AdlibRegister(“findTemp”,9000)
AdlibRegister(“\u Draw\u Graph”,10000)
本地$hGUI、$hGraph、$temp、$Counter=1、$iCheck、$msg、$xVal=1
$hGUI=GUICreate(“,600350);创建GUI窗口
$iCheck=GUICtrlCreateCheckbox(“在下一个间隔重置”,462,1)
GUISetState();显示窗口
CreateGraph();创建图形
findTemp();找到临时工
_绘制图();画图表
而1
$msg=GUIGetMsg()
开关$msg
案例$GUI\u事件\u结束
退出
终端开关
温德
Func CreateGraph()
如果IsArray($hGraph)=0,则
$hGraph=_GraphGDIPlus_Create($hGUI,37,24,5453000,0xFF000000,0xFF88B3DD);创建图形
恩迪夫
如果$Counter>24,则
_GraphGDIPlus_Set_RangeX($hGraph,$xVal,$Counter,24)
$xVal+=1
其他的
_图的范围($hGraph,0,24,24);将x范围设置为0-24,将所有24个刻度都显示在屏幕上
_图集范围($hGraph,0,125,5);将y范围设置为0-125,仅在屏幕上显示5个刻度
_GraphGDIPlus_Set_GridX($hGraph,1,0xFF6993BE);设置x网格
_GraphGDIPlus_Set_GridY($hGraph,1,0xFF6993BE);设置y轴网格
恩迪夫
EndFunc;==>CreateGraph
Func _绘制_图()
本地$rCheckbox
$rCheckbox=GUICtrlRead($iCheck)
如果$rCheckbox=1,则
ControlClick($hGUI,“在下一个间隔重置,$iCheck)
_graphglus_Delete($hGUI,$hGraph);删除图形
$Counter=1;重置计数器
$xVal=1;重置x范围计数器
CreateGraph();然后再次创建图形
恩迪夫
如果$Counter>24,则;如果我们已经走到了尽头
CreateGraph();然后再次创建图形
恩迪夫
_笔画(hGraph,0xFF325D87);设置线条的颜色
_GraphGDIPlus_Set_PenSize($hGraph,2);设置行的大小
_GraphGDIPlus_Plot_Start($hGraph,$Counter,0);在曲线图上设置起点
_图形绘制线($hGraph,$Counter,$temp);设置行的结尾
_graphglus_刷新($hGraph);把它画到屏幕上
$Counter+=1;给我们的柜台加一个
EndFunc;==>_画图
Func findTemp()
$WBEMFlagReturnInstance=0x10
$wbemFlagForwardOnly=0x20
$strComputer=“”
$objWMIService=ObjGet(“winmgmts:\\”和$strComputer&“\root\wmi”)
$Instances=$objWMIService.InstancesOf(“MSAcpi_热区温度”)
对于$Instances中的$Item
$temp=($Item.CurrentTemperature-2732)/10;设定温度
下一个
EndFunc;==>findTemp
Func Quit()
_graphglus_Delete($hGUI,$hGraph);删除图形
出口把我们弄出去
EndFunc;==>退出

您看过GraphGDIPlus.au3吗?-我现在正在给你写一个脚本来做你想做的事情。如果图表已满,是否要关闭它或刷新(重画)图表?
#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 & "\root\wmi")
    $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