From a3b41acd6120bbfd5d38797e09264dfed5f71135 Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Fri, 23 Aug 2013 16:12:18 +0200 Subject: [PATCH] Added automatic temperature adjustment --- bot/Functions/TemperatureControl.au3 | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 bot/Functions/TemperatureControl.au3 diff --git a/bot/Functions/TemperatureControl.au3 b/bot/Functions/TemperatureControl.au3 new file mode 100755 index 0000000..7bce0ef --- /dev/null +++ b/bot/Functions/TemperatureControl.au3 @@ -0,0 +1,76 @@ +#include +AutoItSetOption("TrayIconHide", 1) +$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler + +If ($CmdLine[0] > 0) Then + SetTemperature($CmdLine[1]) +Else + GetTemperature() +EndIf + +Func GetTemperature() + ;ConsoleWrite('@@ (6) :(' & @MIN & ':' & @SEC & ') GetTemperature()' & @CR) ;### Function Trace + $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") + WITH $oHTTP + .Open("GET", "http://cerberus.x-matter.uni-frankfurt.de:8700/tools/cooling/cooling.pl?/dev/ttyUSB1") + .Send() + $HTMLSource = .Responsetext + ENDWITH + If $HTMLSource <> "" Then + $curtemperaturmatch = StringRegExp ( $HTMLSource, "Internal Sensor\: (-)?[0-9]+\.[0-9]+", 2) + If IsArray($curtemperaturmatch) Then + If $curtemperaturmatch[0] <> "" Then + $curtemperatur = StringReplace($curtemperaturmatch[0], "Internal Sensor: ", "") + ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $curtemperatur = ' & $curtemperatur & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console + ControlSetText("MABS (Mimosa Automation Bot System)", "", "Static3", $curtemperatur) + Return $curtemperatur + EndIf + EndIf + EndIf + $oHTTP = 0 +EndFunc ;==>GetTemperature + +Func SetTemperature($temperature) + If IsInt($temperature) Then + If $temperature > 0 Then + $signum = "+" + Else + $signum = "" + EndIf + $temperature = $temperature * 100 + $command = "SP@" & $signum & PadZeros($temperature,5); + + $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") + WITH $oHTTP + .Open("GET", "http://cerberus.x-matter.uni-frankfurt.de:8700/tools/cooling/cooling.pl?/dev/ttyUSB1&" & $command) + .Send() + $HTMLSource = .Responsetext + ENDWITH + If $HTMLSource <> "" Then + $sucess = StringRegExp ( $HTMLSource, "okay") + If $sucess Then + MsgBox(0, "ok", "Yes!") + Return 1 + EndIf + EndIf + $oHTTP = 0 + EndIf +EndFunc ;==>SetTemperature + + +; This is my custom error handler +Func MyErrFunc() + ConsoleWrite('@@ (27) :(' & @MIN & ':' & @SEC & ') MyErrFunc()' & @CR) ;### Function Trace + $HexNumber=hex($oMyError.number,8) + ConsoleWrite("Intercepted a COM Error !" & @CRLF & _ + "Number is: " & $HexNumber & @CRLF & _ + "Windescription is: " & $oMyError.windescription) +Endfunc + + +Func PadZeros($theNumber, $max) + While StringLen($theNumber) < $max + $theNumber = "0" & $theNumber + WEnd + return $theNumber +EndFunc \ No newline at end of file -- 2.43.0