#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Genesys.ico #AutoIt3Wrapper_Outfile=IR Load Manager.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=IR Load Manager by Asaf Ben-Yosef & Shai Alon #AutoIt3Wrapper_Res_Description=IR Load Manager #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_ProductVersion=1.0.0 #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/pe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "C:\Users\salon\My Documents\GraphGDIPlus.au3" Global $CSVData Global $XasixEnd = 300 Global $XasixStart = 0 Global $SamplingInterval = 20 ;20 sec between each read of data file Global $WorkingDir = IniRead(@ScriptDir & "\IR Load Manager.ini","common","WorkingDirectory",@ScriptDir) Global $CSVDataFileName = IniRead(@ScriptDir & "\IR Load Manager.ini","common","CSVDataFile","ERROR") Global $IRSimCommonParamFileName = IniRead(@ScriptDir & "\IR Load Manager.ini","common","IRSimCommonParamFile","CommonFilesReaderParams.ini") Global $ApplicationLaunchName = IniRead(@ScriptDir & "\IR Load Manager.ini","common","ApplicationLaunchName","notepad.exe") Global $ResFileExists = "true" Global $NumOfSamples = 0 Global $GaugeVal = 0 Local $CAPSfromINI = IniRead($WorkingDir & "\" & $IRSimCommonParamFileName, "common", "NumOfCallsPerSecond", "0") ;read pre-configured CAPS value ConsoleWrite ("CAPS from file (" & $WorkingDir & "\" & $IRSimCommonParamFileName & "): " & $CAPSfromINI & @CRLF) If FileExists($WorkingDir & "\" & $CSVDataFileName) Then $ResFileExists = "true" _FileReadToArray($WorkingDir & "\" & $CSVDataFileName,$CSVData,1,",") Else $ResFileExists = "false" EndIf ;~ _ArrayDisplay($CSVData, "DATA", Default, 8) Global $StartingSample = 2 If $ResFileExists = "true" Then $NumOfSamples = $CSVData[0][0]-1 $GaugeVal=Round($CSVData[$NumOfSamples+1][1]/60,1) Else $NumOfSamples = 0 $GaugeVal = 0 EndIf ConsoleWrite ("NumOfSamples = " & $NumOfSamples & @CRLF) Global $CAPSval=$CAPSfromINI Global $CAPS10 = $CAPSval*10 Global $iCount = 21 ;For the Slider Labels Global $SliderLabel[$iCount] ;For the Slider Labels #Region ### START Koda GUI section ### Global $GUI = GUICreate("Load Menu", 382, 420, 223, 616) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $Group1 = GUICtrlCreateGroup("", 3, 3, 377, 100) Global $Label1 = GUICtrlCreateLabel("Calls per Second:", 107, 28, 89, 17) Global $idInput = GUICtrlCreateInput($CAPSval, 197, 25, 32, 20, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) Global $idInputHidden = GUICtrlCreateInput($CAPS10, -190, 25, 49, 25) GUICtrlSetState($idInput,$GUI_DISABLE) Global $idSlider1 = GUICtrlCreateSlider(8, 51, 370, 25,$TBS_AUTOTICKS) GUICtrlSetLimit($idSlider1, 200, 0) ; change min/max value GUICtrlSetData($idSlider1, $CAPS10) ; set cursor _Draw_Slider_Labels() GUICtrlCreateGroup("", -99, -99, 1, 1) Global $UpdateCAPS = GUICtrlCreateButton("Update CAPS", 123, 107, 137, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;~ Global $Group2 = GUICtrlCreateGroup("", 3, 136, 377, 193) $Graph = _GraphGDIPlus_Create($GUI,35,136,335,150,0xFF000000,0xFFC4D9EE) Local $OriginX = 325 Local $OriginY = 357 $SpeedMeterGause = GUICtrlCreatePic("C:\Users\salon\Pictures\speedomete.gif", 280, 312, 90, 90) ;~ $SpeedMeterNiddle = GUICtrlCreatePic("C:\Users\salon\Pictures\Niddle.jpg", 291, 352, 40, 9) $LabelGauge = GUICtrlCreateLabel($GaugeVal, 313, 378, 25, 16, BitOR($SS_SIMPLE,$SS_NOPREFIX),$WS_EX_CLIENTEDGE) Global $ButtonStart = GUICtrlCreateButton("START", 16, 376, 97, 25) Global $ButtonStop = GUICtrlCreateButton("STOP", 120, 376, 105, 25) GUICtrlSetFont($ButtonStart, 8, 800, 0, "MS Sans Serif") GUICtrlSetFont($ButtonStop, 8, 800, 0, "MS Sans Serif") GUICtrlSetState($ButtonStop,$GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $t = 0 ; Get a time stamp Global $nBegin = TimerInit() Global $LastTimeStamp = TimerInit() ;----- Set X axis range from $XasixStart to $XasixEnd ----- _GraphGDIPlus_Set_RangeX($Graph,$XasixStart,$XasixEnd,5,1,0) ;~ _GraphGDIPlus_Set_GridX($Graph,1,0xFF92B0CF) ;----- Set Y axis range from 0 to 1400 ----- _GraphGDIPlus_Set_RangeY($Graph,0,1400,10,1,0) ;~ _GraphGDIPlus_Set_GridY($Graph,1,0xFF92B0CF) $GraphYasix = GUICtrlCreateLabel("Calls/min", 25, 120, 44, 16, BitOR($SS_SIMPLE,$SS_NOPREFIX)) _Draw_Graph() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $UpdateCAPS Local $t = GUICtrlRead($idInput) ConsoleWrite ("Update CAPS button was pressed, Updating to " & $t & @CRLF) IniWrite($WorkingDir & "\" & $IRSimCommonParamFileName, "common", "NumOfCallsPerSecond",$t) ;write the new CAPS value back to the file Case $idSlider1 ; Checkif a slider has been moved _Slider_Update() $CAPS10 = GUICtrlRead($idSlider1) GUICtrlSetData($idInput,$CAPS10/10) GUICtrlSetData($idInputHidden,$CAPS10) ; Show the tootip ToolTip($CAPS10/10 &" CAPS") Case $ButtonStart ConsoleWrite($WorkingDir & @CRLF) $rc = Run (@ComSpec & ' /c ' & $WorkingDir & "\" & $ApplicationLaunchName,$WorkingDir,@SW_HIDE) ;$rc = Run (@ComSpec & ' /c ' & $ApplicationLaunchName,$WorkingDir,@SW_HIDE) ;for testing!!! IniWrite($WorkingDir & "\" & $IRSimCommonParamFileName, "common", "RunningFlag","true") ;Changing the RunningFlag to true ConsoleWrite("Running '" & $WorkingDir & "\" & $ApplicationLaunchName & "'. Result = " & $rc & @CRLF) GUICtrlSetState($ButtonStart,$GUI_DISABLE) GUICtrlSetState($ButtonStop,$GUI_ENABLE) Case $ButtonStop ;$rc = _RunDOS ("taskkill /IM " & $ApplicationLaunchName) ;DON'T KILL THE APPLICATION! IniWrite($WorkingDir & "\" & $IRSimCommonParamFileName, "common", "RunningFlag","false") ;Changing the RunningFlag to false ConsoleWrite("Stopping '" & $ApplicationLaunchName & "'. Result = " & $rc & @CRLF) GUICtrlSetState($ButtonStop,$GUI_DISABLE) While ProcessExists($ApplicationLaunchName) sleep(1000) WEnd GUICtrlSetState($ButtonStart,$GUI_ENABLE) Case $GUI_EVENT_CLOSE Exit EndSwitch _Slider_Update() ; Hide the ToolTip every second If TimerDiff($nBegin) > 1000 Then _Slider_Update() ToolTip("") $nBegin = TimerInit() EndIf If TimerDiff($LastTimeStamp) > ($SamplingInterval*1000) Then ;20 sec _UpdateGraphData() $LastTimeStamp = TimerInit() ConsoleWrite("20 seconds passed - updating graph data... ") EndIf WEnd ;================================================= Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True If $NumOfSamples > 300 Then ;Need to adjust the X asix for that: $XasixEnd = $NumOfSamples + 1 $XasixStart = $XasixEnd - 300 _GraphGDIPlus_Set_RangeX($Graph,$XasixStart,$XasixEnd,5,1,0) $StartingSample = $NumOfSamples - 300 + 1 EndIf For $i = $StartingSample to $NumOfSamples+1 Step 1 $y = $CSVData[$i][1] If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Func _Slider_Update() $nValue = GUICtrlRead($idSlider1) ;~ ToolTip($nValue/10 &" CAPS") ; Show the tootip GUICtrlSetData($idInput,$nValue/10) GUICtrlSetData($idInputHidden,$nValue) ;~ _Draw_Slider_Labels() EndFunc Func _HideToolTip() ; Hide ToolTip ToolTip("") EndFunc Func _Draw_Slider_Labels() For $i = 0 to $iCount - 1 $Position = $i * 17.2; $SliderLabel[$i] = GUICtrlCreateLabel($i, 15.8+$Position, 83, 11, 18, $SS_CENTER,$WS_EX_APPWINDOW) GUICtrlSetState($SliderLabel[$i],$GUI_DISABLE) Next EndFunc Func _UpdateGraphData() _GraphGDIPlus_Clear($Graph) If FileExists($WorkingDir & "\" & $CSVDataFileName) Then _FileReadToArray($WorkingDir & "\" & $CSVDataFileName,$CSVData,1,",") $NumOfSamples = $CSVData[0][0]-1 Local $NewGaugeVal=Round($CSVData[$NumOfSamples+1][1]/60,1) Else $NumOfSamples = 0 Local $NewGaugeVal = 0 EndIf ConsoleWrite ("NumOfSamples = " & $NumOfSamples & @CRLF) _Draw_Graph() Local $LastVal = GUICtrlRead($LabelGauge) Local $diff = ($NewGaugeVal - $LastVal)*10 Local $Dir = 1 If $NewGaugeVal < $LastVal Then $Dir = -1 For $j = $LastVal to $NewGaugeVal step ($Dir * 0.1) ;~ ConsoleWrite($j & @CRLF) sleep (1) GUICtrlSetData($LabelGauge,$j) Next EndFunc