Timer in- IF THEN ELSEIF- Abfrage

  • Guten Abend zusammen,
    ich möchte gern einen Timer in einer IF THEN ELSEIF Abfrage einbauen.
    Zur Funktion:
    Der ElseIf -Zweig also die Funktion _fertig() soll nur ausgeführt werden wenn der ($status = "NOTREADY") für eine gewisse Zeit besteht.
    Diese Zeit soll per Timer einstellbar sein.

    Also Z.B der ($status = "NOTREADY") muß 10 s bestehen And Not WinExists("Backup","disc and press OK.") Then
    _fertig()

    Hier nun der code
    siehe Zeile 53!

    Danke für Eure Hilfe

    Spoiler anzeigen
    [autoit]

    $file=FileOpen(@ScriptDir & "\config.txt",0)
    $drive=FileReadLine(@ScriptDir & "\config.txt",4)
    $Comport=FileReadLine(@ScriptDir & "\config.txt",6)
    $Version=('V:X:30:2:E');Robotic Version Info Command
    $Calibration=('C:X:30:2:E');Calibration Command
    $Load=('I:X:30:2:E');Get Input (load) Command
    $Unload=('A:X:30:2:E');Unload the Drive Command

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","_exit")
    Global $iCount = 1

    [/autoit] [autoit][/autoit] [autoit]

    if $file=-1 Then
    MsgBox(0,"Error","Unable to open the config.txt")
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $vardrive=DriveStatus($drive)
    If ($vardrive = "INVALID") Then
    MsgBox(16,"Error","Invalid Optical Drive!"&@CRLF& $drive)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If ($vardrive = "READY") Then
    MsgBox(48,"Info", "Please unload the Drive" &@CRLF& $drive)
    CDTray($drive,"open")
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --command='&$Version&'')
    sleep(1000)
    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --command='&$Calibration&'')
    sleep(1000)
    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --open --command='&$Load&' --ifcommandfailortimeoutskip=failedload --set=loaderrors:0:robot --skip=trayanddiscin --label=failedload --skip=loadmorediscs --label=loadmorediscs --notify="You can cancel the batch with Abort. Hit Retry only after you load more discs on the spindle and CLEAR REJECTS. Hit Ignore if the disc loaded correctly.":"Load may have failed for drive {drive} on port {comport}.":2 --set=rc:{notifyreturncode} --ifsetskip=rc:3:shutdown --ifsetskip=rc:4:resetloaderrors --ifsetskip=rc:5:trayanddiscin --skip=failedload --label=resetloaderrors --set=loaderrors:0:robot --rejectsreset --skip=doreset --label=trayanddiscin --closeblind --sleep=2 --unbindtodrive --comportrelease --label=successexit --exit=0 ')
    Sleep(2000)

    If WinExists("Backup","disc and press OK.") Then
    ControlClick("Backup","OK","Button1")
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ToolTip("Disc" &$iCount)
    While True
    $status=DriveStatus($drive)
    sleep(500)


    If WinExists("Backup","disc and press OK.") Then
    $iCount += 1
    ToolTip("Disc" &$iCount)
    _next()

    ElseIf ($status = "NOTREADY") And Not WinExists("Backup","disc and press OK.") Then
    _fertig()

    ExitLoop
    EndIf

    EndIf

    [/autoit] [autoit][/autoit] [autoit]


    sleep(500)
    WEnd
    Func _next()
    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --open --command='&$Unload&' --ifcommandfailortimeoutskip=failedexit --comportrelease --skip=successexit --label=failedexit --notify="Problem with robot on port {comport} for drive {drive}, shutting down..." --set=shutdown:yes:robot --skip=shutdown --exit=0 --label=successexit --exit=0 --label=shutdown --set=needsreset:yes:robot --messagefile={passerrorsback} --message="[cancel batch]" --exit')
    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --command='&$Load&' --ifcommandfailortimeoutskip=failedload --set=loaderrors:0:robot --skip=trayanddiscin --label=failedload --skip=loadmorediscs --label=loadmorediscs --notify="You can cancel the batch with Abort. Hit Retry only after you load more discs on the spindle and CLEAR REJECTS. Hit Ignore if the disc loaded correctly.":"Load may have failed for drive {drive} on port {comport}.":2 --set=rc:{notifyreturncode} --ifsetskip=rc:3:shutdown --ifsetskip=rc:4:resetloaderrors --ifsetskip=rc:5:trayanddiscin --skip=failedload --label=resetloaderrors --set=loaderrors:0:robot --rejectsreset --skip=doreset --label=trayanddiscin --closeblind --sleep=2 --unbindtodrive --comportrelease --label=successexit --exit=0')
    Sleep(2000)
    ControlClick("Backup","OK","Button1")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _fertig()
    RunWait('load.exe --comport='&$comport&' --drive='&$drive&' --open --command='&$Unload&' --ifcommandfailortimeoutskip=failedexit --comportrelease --skip=successexit --label=failedexit --notify="Problem with robot on port {comport} for drive {drive}, shutting down..." --set=shutdown:yes:robot --skip=shutdown --exit=0 --label=successexit --exit=0 --label=shutdown --set=needsreset:yes:robot --messagefile={passerrorsback} --message="[cancel batch]" --exit')
    sleep(1000)
    CDTray($drive,"close")
    sleep(1000)
    MsgBox(64,"Programminfo","Backup" &@CRLF& "Finished",10)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit]
  • Danke für die Antwort "name22"

    Ja vom Prinzip her richtig -DANKE- ich habe aber schon eine While True Schleife laufen.
    Eine Schleife in einer Schleife macht ja keinen Sinn. Oder sehe ich das falsch?

    Hast Du noch eine Idee wie ich den Timer in die IF THEN Abfrage einbauen kann ?


    DANKE!

  • Also so?

    Spoiler anzeigen
    [autoit]

    $Timer=TimerInit()
    While True
    $status=DriveStatus($drive)
    sleep(500)
    If WinExists("Backup","disc and press OK.") Then
    $iCount += 1
    ToolTip("Disc" &$iCount)
    _next()
    ElseIf ($status = "NOTREADY") And Not WinExists("Backup","disc and press OK.") And TimerDiff($Timer) >= 10000 Then
    _fertig()
    ExitLoop
    EndIf
    sleep(500)
    WEnd

    [/autoit]


    Ich hab den Timer einfach in deine ursprüngliche Schleife eingebaut. :)

  • Hallo -name22-
    Ich habe jetzt nochmal elles getestet
    jedoch gibt es noch ein Problem bei der Sache.

    Die geplate "NOTREADY" Zeit von 10s zum ausführen von der Funktion _fertig() kann nicht erreicht werden .
    Sie kann momentan nur 1000ms betragen also die Sleep Time in der Schleife.
    Als Variable für TimerInit müsste man irgenwie den Drivestatus "NOTREADY" setzen können.

    Ich habe gesehen das Du $Timer=TimerInit() außerhalb der Schleife hast, das führt aber dazu das die Zeit nicht richtig bestimmt werden kann.

    Hier nochmal der Code der Schleife

    Spoiler anzeigen
    [autoit]

    While True
    $Timer=TimerInit()
    $status=DriveStatus($drive)
    sleep(1000)
    MsgBox(64,"Programminfo","Backup" &@CRLF& $status,10)
    If WinExists("Backup","disc and press OK.") Then
    $iCount += 1
    ToolTip("Disc" &$iCount)
    _next()
    ElseIf ($status = "NOTREADY") Or ($status = "UNKNOWN") And Not WinExists("Backup","disc and press OK.") And TimerDiff($Timer) >= 20000 Then
    _fertig()

    ExitLoop
    EndIf
    WEnd

    [/autoit]

    Danke!

    Gruß
    Sonyman

  • Ich verstehe das nicht ganz. ?(
    TimerInit habe ich absichtlich außerhalb der Schleife gesetzt weil sonst jedesmal eine neue Zeitmarke zurückgegeben würde, und somit die Zeit kein bisschen fortschreitet.
    Die Differenz zwischen einer Zeitmarke und der jetzigen Laufzeit des Scripts wird mit TimerDiff errechnet. ;)
    Wenn du diese 10 Sekunden anpassen möchtest ändere doch einfach das:

    [autoit]

    TimerDiff($Timer) >= 10000

    [/autoit]


    zu

    [autoit]

    TimerDiff($Timer) >= 1000

    [/autoit]
  • Hallo -name22-
    mit dem Wert habe ich die Nacht noch "experimentiert"
    Wenn der TimerInit außerhalb der Schleife steht bekomme ich jedesmal unterschiedliche Ergebnisse!
    Also z.B. Du stellst 20000ms ein also 20s dann wird die Funktion _fertig() z.B nach 6 sek ausgeführt.
    Warum kann ich nicht sagen.
    Ich habe mir in die Schleife eine Msg box eingebaut und mir den Drivestatus anzeigen lassen.
    somit habe ich gesehen wenn das Drive auf" NOTREADY" geht und wenn die Funktion _fertig() ausgeführt wird.

    Gruß
    Sonyman