Jump to content

Sometimes my script hangs on a loop


Recommended Posts

Dear All,

I have written this function:

Func Esposizione ($qsi,$tempo,$filtro,$nomefile)
       If ($qsi.Expose ($tempo,1,$filtro)) Then
               ConsoleWrite ( "Inizio cattura frame" & chr(13))
               while (Not $qsi.ImageReady)
                       WEnd
               $qsi.SaveImage ("c:\\tmp\\" & $nomefile)
               ConsoleWrite ( "Fine cattura frame" & chr(13))
       EndIf
EndFunc

The script, sometimes, hangs with the error at the "Wend" statement. Unfortunately is "sometimes" and not "always" and that makes me difficult to debug this. I tried to put a sleep() inside the while loop, with different timings, but it didn't help.

$qsi.ImageReady is a call to a boolean COM property.

Thanks to everyone who can help me in sort this out :blink:

Best regards,

Nicola

Edited by nmontec
Link to comment
Share on other sites

"The error" -> error message please. (don't skip this one if you got one!)

Only error that makes sens to me is a "not a object" error. -> Relevant $qsi object code please.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

You ought to have an "out" for your loop. Put a timer on it in case "ImageReady" is never true.

Func Esposizione ($qsi,$tempo,$filtro,$nomefile)
    If ($qsi.Expose ($tempo,1,$filtro)) Then
        ConsoleWrite ( "Inizio cattura frame" & chr(13))
        $timer = TimerInit()
        While TimerDiff($timer) < 10000 ; 10 seconds
            If $qsi.ImageReady Then
                $qsi.SaveImage ("c:\\tmp\\" & $nomefile)
                ConsoleWrite ( "Fine cattura frame" & chr(13)
                Return 1 ; function was successful
            EndIf
        WEnd
    EndIf
EndFunc

Have you also set up a COM error handler?

Link to comment
Share on other sites

"The error" -> error message please. (don't skip this one if you got one!)

Only error that makes sens to me is a "not a object" error. -> Relevant $qsi object code please.

I get the following error:

C:\Users\betelgeuse\Documents\QSIDitheringConPHD.au3 (38) : ==> The requested action with this object has failed.:
WEnd
WEnd^ ERROR

Line 38 is "WEnd"

Link to comment
Share on other sites

You ought to have an "out" for your loop. Put a timer on it in case "ImageReady" is never true.

Thank you for your reply. I did try the timer code as you wrote and I got the same error

The requested action with this object has failed

at the line

If $qsi.ImageReady Then

Have you also set up a COM error handler?

What is a COM error handler? May you point me out to the related documentation?

Thank you very much!

Nicola

Link to comment
Share on other sites

Hi, just to let you know that I browsed the forum a little bit digging for info and I tried also this:

Func Esposizione ($qsi,$tempo,$filtro,$nomefile)
    Dim $Pronto
    $qsi.Expose ($tempo,1,$filtro)
    $Pronto=False
    Do
        $Pronto=$qsi.ImageReady
        if @error Then
            ConsoleWrite ( "Bad Luck!" & chr(13))
            Exit
        EndIf
    Until $Pronto
    $qsi.SaveImage ("c:\\tmp\\" & $nomefile)
    ConsoleWrite ( "Fine cattura frame" & chr(13))
EndFunc

Despite the @error the $Pronto=$qsi.ImageReady always hangs the program and the consolewrite inside the "@error if statement" is never reached.

Link to comment
Share on other sites

COM error handler code.

;; add somewhere at the top of your own code. below last include for example.
If Not ObjEvent("AutoIt.Error") then Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

;; object error test code, delete after seeing it work.
Global $var1 = ''
Global $var2 = $var1.iuy ;; error -> @@(xx,0) COM Error:000000A9, Variable must be of type 'Object'.
Exit
;; object error test code, delete after seeing it work.

The relevant $qsi code is where the $qsi object is last set.

On your error. I'm not sure. But it could be that your using the wrong property name. ($qsi.wrongname)

PS: nmontec. Just to eliminate any confusion. Only use "hangs" when your program actually stop reacting and you have to kill it with the task-manager. And not for when you program exit's with a error.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...