#include #include #include #include #include #include #include #include 'TCP_Funcs.au3' Opt('MustDeclarevars',1) Global $iMainSocket = 0 Global $sData = "" Global $iConnectedSocket = -1 Global $Cmd = "" Global $ra,$dec,$pix_x,$pix_y,$pixels MainGUI() Func MainGUI() Local $Form1,$Button1,$Label1,$Input1,$Label2,$nMsg,$Flag = 0 Local $Data,$Array,$iPID,$TCParray,$iPID2,$iPID3,$iPID4,$iPID6 Local $String,$Image,$sOutput,$sOutput2,$cmdstring,$errrtn Local $ETime = 0.0 $Form1 = GUICreate("TCP_Camera5", 383, 313, 192, 124) $Button1 = GUICtrlCreateButton("Exit", 16, 208, 185, 73) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("TCP/IP Camera Control v5", 8, 8, 342, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") $Input1 = GUICtrlCreateInput("Information Window", 16, 120, 329, 21) $Label2 = GUICtrlCreateLabel("Communications", 16, 96, 122, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $Image = "eastport.fits" TCPStartup() $iMainSocket = TCPListen("192.168.2.25",1000) $String = "Exposure Finished" While 1 $sData = "" $nMsg = GUIGetMsg() If $iConnectedSocket >= 0 Then If $Flag == 0 Then GUICtrlSetData($Input1,"Connection Established") $Flag = 1 EndIf $sData = TCPRecv($iConnectedSocket,1024) If $sData <> "" Then If $sData == "Listen" Then TCPShutdown() $iConnectedSocket = -1 $Flag = 0 TCPStartup() $iMainSocket = TCPListen("192.168.2.25",1000) Else ;normally $sData is of the form X,Y. If X=1, take a camera exposure where Y is the exposure ;if X=2, turn tracking on if Y=0, off if Y=1 GUICtrlSetData($Input1,$sData) $TCParray = StringSplit($sData,",") If $TCParray[1] == 1 Then $ETime = Number($TCParray[2]) Expose($ETime) $iPID = Run("findbright " & $Image, "c:\wtmp\SpectroAuto",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StdOutRead($iPID) if @error Then MsgBox(0,"Error","Error reading result from findbright") Exit EndIf GUICtrlSetData($Input1,$sOutput) TCPSend($iConnectedSocket,$sOutput) ElseIf $TCParray[1] == 2 Then If $TCParray[2] == 0 Then ;turn tracking on with X10 commands $iPID2 = RunWait('"C:\Program Files\Common Files\X10\Common\ahcmd.exe" sendplc d3 on , ,hide',"",@SW_HIDE) ElseIf $TCParray[2] == 1 Then ;turn tracking off $iPID2 = RunWait('"C:\Program Files\Common Files\X10\Common\ahcmd.exe" sendplc d3 off, ,hide',"",@SW_HIDE) ElseIf $TCParray[2] == 2 Then ;turn lights on $iPID2 = RunWait('"C:\Program Files\Common Files\X10\Common\ahcmd.exe" sendplc d2 on, ,hide',"",@SW_HIDE) ElseIf $TCParray[2] == 3 Then ;turn lights off $iPID2 = RunWait('"C:\Program Files\Common Files\X10\Common\ahcmd.exe" sendplc d2 off, ,hide',"",@SW_HIDE) EndIf ElseIf $TCParray[1] == 3 Then $ETime = Number($TCParray[2]) $ra = $TCParray[3]*15.0 $dec = $TCParray[4] Expose($ETime) sleep(100) $iPID4 = RunWait("c:\users\observer\copyep.bat") GUICtrlSetData($Input1,"Plate Solving ...") $cmdstring = "bash --login -c 'solveit5 " & $ra & " " & $dec & "'" $iPID3 = Run($cmdstring ,"c:\wtmp\SpectroAuto",@SW_HIDE,$STDOUT_CHILD) $errrtn = ProcessWaitClose($iPID3,300) ;times out after 300 seconds if($errrtn == 0) Then $sOutput2 = "0.0,0.0" $iPID6 = Run("pkill astrometry") ;kill astrometry if it times out Else $sOutput2 = StdOutRead($iPID3) EndIf TCPSend($iConnectedSocket,$sOutput2) GUICtrlSetData($Input1,$sOutput2) ElseIf $TCParray[1] == 4 Then $ETime = Number($TCParray[2]) $ra = $TCParray[3]*15.0 $dec = $TCParray[4] Expose($ETime) sleep(100) $sOutput2 = "0.0,0.0" $iPID4 = RunWait("c:\users\observer\copyep.bat") GUICtrlSetData($Input1,"Image Cross-correlation ...") $cmdstring = "bash --login -c 'eastportcorr4.py " & $ra & " " & $dec & " 2>/dev/null" & "'" $iPID3 = Run($cmdstring ,"c:\wtmp\SpectroAuto",@SW_HIDE,$STDOUT_CHILD) $errrtn = ProcessWaitClose($iPID3,180) ;times out after 180 seconds if($errrtn == 0) Then $sOutput2 = "0.0,0.0" $iPID6 = Run("pkill python2.7") ;kill python if it times out Else $sOutput2 = StdOutRead($iPID3) EndIf If($sOutput2 == "") Then $sOutput2 = "0.0,0.0" EndIf TCPSend($iConnectedSocket,$sOutput2) GUICtrlSetData($Input1,$sOutput2) Else DoNothing() ;placeholder for some other command EndIf $sData = "" EndIf Sleep(2000) GUICtrlSetData($Input1,"Ready to Receive next Command") EndIf Else $iConnectedSocket = TCPAccept($iMainSocket) EndIF Switch $nMsg Case $GUI_EVENT_CLOSE If $iConnectedSocket <> -1 Then TCPSend($iConnectedSocket,"Disconnect") Sleep(500) EndIf TCPShutdown() Exit Case $Button1 If $iConnectedSocket <> -1 Then TCPSend($iConnectedSocket,"Disconnect") Sleep(500) EndIf TCPShutdown() Exit EndSwitch WEnd EndFunc Func Expose($Time) Local $Cam,$EImage $EImage = "c:\wtmp\SpectroAuto\eastport.fits" FileDelete($EImage) $Cam = ObjCreate("MaxIm.CCDCamera") $Cam.LinkEnabled = True $Cam.BinX = 2 $Cam.BinY = 2 If $Cam.LinkEnabled = False Then MsgBox(0,"","East Port Camera not ready") Exit EndIf $Cam.DisableAutoShutdown = True $Cam.Expose($Time,1) Do Until $Cam.ImageReady $Cam.SaveImage($EImage) EndFunc Func Get_Bias() Local $Cam,$EImage $EImage = "c:\wtmp\SpectroAuto\bias.fits" FileDelete($EImage) $Cam = ObjCreate("MaxIm.CCDCamera") $Cam.LinkEnabled = True $Cam.BinX = 2 $Cam.BinY = 2 If $Cam.LinkEnabled = False Then MsgBox(0,"","East Port Camera not ready") Exit EndIf $Cam.DisableAutoShutdown = True $Cam.Expose(0.0,0) Do Until $Cam.ImageReady $Cam.SaveImage($EImage) EndFunc Func DoNothing() Return EndFunc