Jump to content

Having Sleep() Problems!


Recommended Posts

Autoit Gurus,

I am trying to delay keystrokes to a DOS program running in a DOS window on a Windows 2K system. The delay is required to wait for things to happen (a test to complete) on an external piece of hardware controlled by the DOS program. The basic script is as follows:

Func Do_Button_4()

$Menu_Mouse_Pos = MouseGetPos() ; Save current mouse position

WinActivate($win)

Send("fc 40 {enter}")

Send("la {enter}")

Send("x2_dig_test.out {enter}")

Send("fc 10 {enter}")

Sleep (4000) ; Wait for test to complete

Send("vt {enter}")

Passit()

WinActivate($win_2) ; Reactivate menu window

MouseMove($Menu_Mouse_Pos [0], $Menu_Mouse_Pos [1], 0) ; Restore beginning mouse position

EndFunc ; Do_Button_4

"x2_dig_test.out" loads the test file and takes about 5 seconds to complete.

"fc 10" starts the test.

The test takes about 2.5 seconds to complete so need to Sleep during this time.

"vt" queries for test result status.

The Passit()function reads the status and determines pass/fail.

The current code appears to blow right past the "fc 10" with ZERO delay. If I change the Sleep parameter to "14000" the DOS program pauses at the correct point but only for 10 seconds not the 14 seconds it is supposed to be!

Does anyone have any ideas of what I am doing wrong? This seems so simple but doesn't appear to be working!

Thanks,

Steve

Link to comment
Share on other sites

Hi,

i can't reproduce or say anything about the sleep behaviour. Haven't had serious problems.

But if you are afraid of, you may use function timerinit () and timerdiff () and code your sleep. It may 'tick' better:

$start = TimerInit ()

Do
    $sleep = TimerDiff ($start)
Until $sleep > 14000 ; 14 seconds
Msgbox (0,"", "Code sleeps for " & $sleep & " ms!")

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Welcome to the AutoIt forum!

You say the test file takes around 5 seconds to load, but your code shows you're Send()ing the next keystrokes immediately. They are likely to be bufferd by DOS at this stage, but if the test program (which also needs a 2.5 seconds to run) has the idea of resetting (flushing) the keyboard queue, your input gets out of sync.

Func Do_Button_4()
 $Menu_Mouse_Pos = MouseGetPos() ; Save current mouse position
 WinActivate($win)
 Send("fc 40 {enter}") ; <-- doesn't this need some time to have the dust settled as well?
 Send("la {enter}")     ; <-- ditto
 Send("x2_dig_test.out {enter}") ; <-- that takes 5+ seconds, right?
Sleep(6000)     ; better late than sorry
 Send("fc 10 {enter}")
 Sleep (4000) ; Wait for test to complete
 Send("vt {enter}")
 Passit()
 WinActivate($win_2) ; Reactivate menu window
 MouseMove($Menu_Mouse_Pos [0], $Menu_Mouse_Pos [1], 0) ; Restore beginning mouse position
EndFunc ; Do_Button_4

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks for your input. You are correct in that DOS is apparently buffering the keystrokes. Any idea how big that buffer is? The DOS program DOES NOT clear the key buffer in between commands so this is not an issue.

However, as you mention the 4000 delay may be taken up with program loading therefore it appears to be non-existent when I am intending it to occur. I will try your suggestion and add a sleep delay after the program loading.

Steve

Welcome to the AutoIt forum!

You say the test file takes around 5 seconds to load, but your code shows you're Send()ing the next keystrokes immediately. They are likely to be bufferd by DOS at this stage, but if the test program (which also needs a 2.5 seconds to run) has the idea of resetting (flushing) the keyboard queue, your input gets out of sync.

Func Do_Button_4()
 $Menu_Mouse_Pos = MouseGetPos() ; Save current mouse position
 WinActivate($win)
 Send("fc 40 {enter}") ; <-- doesn't this need some time to have the dust settled as well?
 Send("la {enter}")     ; <-- ditto
 Send("x2_dig_test.out {enter}") ; <-- that takes 5+ seconds, right?
Sleep(6000)     ; better late than sorry
 Send("fc 10 {enter}")
 Sleep (4000) ; Wait for test to complete
 Send("vt {enter}")
 Passit()
 WinActivate($win_2) ; Reactivate menu window
 MouseMove($Menu_Mouse_Pos [0], $Menu_Mouse_Pos [1], 0) ; Restore beginning mouse position
EndFunc ; Do_Button_4

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...