tim1986 Posted January 20, 2007 Share Posted January 20, 2007 Hello. My script closes immediately on execution. What do I do?? expandcollapse popup#include <GUIConstants.au3> #include <Mixer_Include.au3> #Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. ;$showhideitem = TrayCreateItem("Show/Hide Settings") $testitem = TrayCreateItem("Test Serial Receive") $restartitem = TrayCreateItem("Restart Program") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() ;default mixer is always 0 (so far) which is last audio device installed or prefered deviced selected by user $MsComm = ObjCreate("MSCOMMLib.MsComm.1") $MsComm.CommPort = 4 $MsComm.Settings = "9600,N,8,1" $MsComm.Handshaking = 0 $MsComm.InBufferSize = 1024 $MsComm.InputLen = 1 $MsComm.PortOpen = 1 $UpdateInterval = 500 Func Main() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop ;Case $msg = $showhideitem ;WindowHideShow($Form1,$Form1State) Case $msg = $testitem _MsgTest() Case $msg = $restartitem _restart() Case $msg = $exititem ExitLoop EndSelect Sleep($UpdateInterval) VolumeSet(SerialGetVolume()) WEnd EndFunc ;;;;;;;;;;;;;;; ;Serial Section ;;;;;;;;;;;;;;; ;_MsgOut("RT" & @CR) ;MsgBox(0,"Testing",_MsgIn()) Func _MsgTest() MsgBox(0,"Testing",SerialGetVolume()) EndFunc Func _MsgOut($str) $MsComm.OutBufferCount = 0 $MsComm.InBufferCount = 0 If $MsComm.PortOpen = True Then $MsComm.Output = $str EndIf $MsComm.InputLen = 0 EndFunc Func _MsgIn() $TIMEOUT = 1000 $nTimeCtr = 0 $sBuffer = "" Do $nTimeCtr += 1 If $MsComm.InBufferCount > 0 Then $sBuffer = $sBuffer & $MsComm.Input EndIf Sleep(500) Until StringInStr($sBuffer,@CR) OR $nTimeCtr > $TIMEOUT If $nTimeCtr < $TIMEOUT Then $nI = StringInStr($sBuffer,@CR) Return StringLeft($sBuffer,$nI) Else Return "Error" EndIf EndFunc Func SerialGetVolume() _MsgOut("P" & @CR) Sleep(200); $Volume = _MsgIn() ConsoleWrite("'" & $Volume & "'") Return $Volume EndFunc Func VolumeSet($volume) _SetMixerVolume($MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, $volume) EndFunc Func WindowHideShow($winhandle,ByRef $state) if $state = 0 Then GUISetState(@SW_SHOW, $winhandle) $state = 1 Else GUISetState(@SW_HIDE, $winhandle) $state = 0 EndIf EndFunc ; Restart the program Func _restart() If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc Link to comment Share on other sites More sharing options...
BigDod Posted January 20, 2007 Share Posted January 20, 2007 Remove the line Func Main() and the corresponding EndFunc Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2007 Moderators Share Posted January 20, 2007 Remove the line Func Main() and the corresponding EndFuncOr $UpdateInterval = 500 Main()Actually call the function. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
tim1986 Posted January 20, 2007 Author Share Posted January 20, 2007 Thank you both! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now