]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Added automatic temperature adjustment
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 23 Aug 2013 14:12:18 +0000 (16:12 +0200)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 23 Aug 2013 14:12:18 +0000 (16:12 +0200)
bot/Functions/TemperatureControl.au3 [new file with mode: 0755]

diff --git a/bot/Functions/TemperatureControl.au3 b/bot/Functions/TemperatureControl.au3
new file mode 100755 (executable)
index 0000000..7bce0ef
--- /dev/null
@@ -0,0 +1,76 @@
+#include <String.au3>
+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