#include <GuiConstantsEx.au3>
#include 'CommMG.au3'

Global $sportSetError = ''

Global $CMPort = 3              ; Port
Global $CmBoBaud = 9600        ; Baud
Global $CmboDataBits =  8       ; Data Bits
Global $CmBoParity = "none"     ; Parity
Global $CmBoStop = 1            ; Stop
Global $setflow = 2             ; Flow
Global $RTSMode = 1
Global $DTRMode = 1
Global $iWait = 0

_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow, $RTSMode, $DTRMode)


; GUI erstellen
GUICreate("Foto", 1000, 400)


GUICtrlCreateLabel("Startverzögerung in Mikrosekunden", 10, 10)
$startverzoegerung = GUICtrlCreateInput("500000", 600, 10, 100, 20)
GUICtrlCreateUpdown($startverzoegerung)

GUICtrlCreateLabel("Verzögerung zwischen Magnet Abschaltung und Kameraauslösung in Mikrosekunden", 10, 50)
$verzoegerung = GUICtrlCreateInput("500000", 600, 50, 100, 20)
GUICtrlCreateUpdown($verzoegerung)

$fotomachen =  GUICtrlCreateButton("Starten", 10,80, 100, 30)

GUICtrlCreateLabel("Magnet Schalten", 10, 150)
$magnetein = GUICtrlCreateButton("Magnet Ein", 10,200, 100, 30)
$magnetaus = GUICtrlCreateButton("Magnet Aus", 150,200, 100, 30)


GUISetState()
While True
   Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
		 Case $fotomachen
			 $schalt = "3/" & GUICtrlRead($startverzoegerung)  & "/" & GUICtrlRead($verzoegerung) & "/"
            _CommSendString($schalt, $iWait) 
		Case $magnetein
            _CommSendString("1/", $iWait)
        Case $magnetaus
            _CommSendString("2/", $iWait)
    EndSwitch
WEnd



; GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd