View Single Post
Old 10-14-2015, 07:01 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
The risk I see with your code is that you're waiting for "busy", but you're also passing in a timeout parameter of 5 seconds.

Is there ever a time where you won't see "busy" within 5 seconds of issuing the check-status command? If so, you'll need to up your timeout to accommodate the worst of cases.

Another approach would be to wait for more than one string, one for the failure (busy) case, and another for the success case.

If the device is not "busy", what shows up in the output of the command instead? In other words, is there something you see on the screen that tells you it's *not* busy as a result of running the check-status command? If so, then you can tell SecureCRT to wait for multiple strings, and tell you which one it found, so you can branch on that data to either exit your loop or continue waiting, or call your Aunt Sandra, or whatever you desire .

For the sake of example let's say that your router says "Router ready" instead of "Router resources are busy" when it's, well, ready instead of busy. Your loop would look like this instead (throwing in a little bit of extra cool-ness in there for fun ):

nTimeOut = 5
nSleepTime = 60
    nResult = crt.Screen.WaitForStrings("busy", "ready", nTimeOut)
    Select Case crt.Screen.MatchIndex
        Case 1
            For nCounter = 0 to nSleepTime - 1
                crt.Session.SetStatusText "Found 'busy'; Sleeping for " & nSleepTime - nCounter & " seconds..."
                crt.sleep 1000
            crt.Screen.Send "CHECK_STATUS" & VbCr
            crt.Screen.WaitForString "CHECK_STATUS"
        Case 2
            ' Ah! found "ready"; time to exit the loop
            crt.Session.SetStatusText "Found 'ready'; exiting loop"
            Exit Do
        Case 0
            ' In this case, we timed out...
            crt.Session.SetStatusText "Timed out waiting for strings."
            crt.Dialog.MessageBox "Timed out after " & _
                nTimeOut & " seconds." & vbcrlf & _
                "You will want to increase your time out, or add " & _
                "additional strings to look for."
            Exit Do
        Case Else
            ' In this case, you have a mismatch between the number of
            ' strings you're passing to WaitForStrings(), and the number
            ' of case statements you've written code to handle. Ooops.
            ' Time to write another case statement!
            crt.Dialog.MessageBox _
                "Oops! Time to write another case statement for string #" & _
            Exit Do
    End Select
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel:
Reply With Quote