PDA

View Full Version : Use crtr.sleep


eltorres
01-13-2005, 02:13 AM
Hello,
I need to stop my script until a period of time and i use the sleep method for this. I read in your archives that exits a crt.sleep method to do this but itīs necan api for this. Can you explain me how to do this.

Thank you.
Bye.

jdev
01-14-2005, 05:48 PM
The Sleep() method available with crt.Sleep can only be used to sleep for a number of milliseconds, so it can't be used by itself to tell SecureCRT to wait until 6am, for example before continuing with the next section of code.

However, you can use the crt.Sleep command to repeatedly wait for a determined period of time within a loop wherein you can check to see what the current time is (using the builtin Now() function) and then break out of the loop as in the following example:

# $language = "VBScript"
# $interface = "1.0"
Option Explicit

Dim g_nTimeCheckIntervalMinutes
Dim nActionHour, nActionMinute

' Check once every 5 minutes to see if our target time has
' arrived
g_nTimeCheckIntervalMinutes = 5

' Perform the action at 10:30pm
nActionHour = 22
nActionMinute = 30

Sub Main()

Dim szCurrentTime, nToday, nLastDayDone
Dim nCurrentHour, nCurrentMinute
MsgBox "Hello"

' Outer loop... this script will be running forever
' until SecureCRT exits or until a user chooses "Cancel"
' from the "Script" menu.
Do

' Wait for action time to arrive
Do
' Action should only take place once a day
szCurrentTime = Now

nToday = Day(szCurrentTime)

If nToday <> nLastDayDone Then
nCurrentHour = Hour(szCurrentTime)
nCurrentMinute = Minute(szCurrentTime)

' If the action time has arrived, break out
' of the loop and perform the action
If (nCurrentHour >= nActionHour) And _
(nCurrentMinute >= nActionMinute) Then Exit Do

End If

' Wait for g_nTimeCheckIntervalMinutes before
' checking the time again... Sleep method takes
' milliseconds, so it needs to be converted
' first to minutes
crt.Sleep g_nTimeCheckIntervalMinutes * 60 * 1000
Loop

'~~~~ Action/Work to do at specified time goes here ~~~~
' Now that our action time has arrived, do the work
' that we want to do...

'MsgBox "Action time is here!" & vblf & "(" & _
' nActionHour & ":" & nActionMinute & ")"

' Do your real work here...




' Stop doing your real work now...

' Since we only want this done once a day, reset the
' day indicator and start looping again until the
' day changes and our target time arrives...
nLastDayDone = nToday

Loop

End Sub

eltorres
01-17-2005, 03:20 AM
I use de crt.sleep to sleep 1 second in the while loop. When i run my script crt gives my an error: "Error: the object donīt accept this property or method:'Crt.sleep'".
This is my script,

#$language = "VBScript"
#$interface = "1.0"
'************************************************* **************************************
'**************************** VELOCIDAD INTERFACE POR MUESTREO *********************
'******************************** Ernesto Lopez - CGP CAIXANOVA ************************
'************************************************* **************************************
Dim num_tomas
Dim num
Dim i
Dim RESPUESTA
dim toma_out
dim toma_in
Sub Main
With Crt.Screen
.Synchronous = True
Set toma_out= CreateObject("Scripting.Dictionary")
Set toma_in= CreateObject("Scripting.Dictionary")



num=0
num_tomas=TRIM(crt.Dialog.Prompt("Introduce el numero de muestras que quieres tomar :", "num_tomas", "", False))
interface=TRIM(crt.Dialog.Prompt("Introduce el interface donde quieres tomar las muestras (ej. serial0/0)", "interface", "", False))


Do While num < num_tomas

crt.Screen.Send "sh int " & interface & VbCr
RESPUESTA=crt.Screen.WaitForStrings ("swapped out", 5)
If RESPUESTA= 1 Then

screenrow = crt.screen.CurrentRow - 2
readline = crt.Screen.Get(screenrow, 1, screenrow, 60)
crt.Dialog.MessageBox (readline)
MyArray = Split(readline," ", -1, 1)
crt.Dialog.MessageBox (MyArray(8))
MyArray1=MyArray(8)
toma_out.Add num,MyArray1
screenrow = crt.screen.CurrentRow - 5
readline = crt.Screen.Get(screenrow, 1, screenrow, 60)
crt.Dialog.MessageBox (readline)
MyArray = Split(readline," ", -1, 1)
crt.Dialog.MessageBox (MyArray(8))
MyArray1=MyArray(8)
toma_in.Add num,MyArray1
crt.Sleep 1000


Else
crt.Dialog.MessageBox "Error en toma"
End If

Loop

suma_out
suma_in
a = d.Items ' Get the items.
b = d.Items ' Get the items.
For i = 0 To toma_out.Count -1 ' Iterate the array.
suma_out=suma_out + a(i)

Next

For i = 0 To toma_out.Count -1 ' Iterate the array.

suma_in=suma_in + b(i)
Next


vel_out=suma_out*8/(1024*num_tomas)
vel_in=suma_in*8/(1024*num_tomas)
crt.Dialog.MessageBox (vel_in)
crt.Dialog.MessageBox (vel_out)

End With
End Sub

jdev
01-17-2005, 01:38 PM
The Sleep() method is not available in versions prior to 4.0.

What version are you using (Help / About)?

If you are using a version prior to 4.0, you can still wait in 1 second increments by using the WaitForString() function passing in a string that you would never expect to see; for example:Sub Main()
Do
...
Sleep 1
...
Loop
End Sub

Function Sleep(nWaitTimeSeconds)
crt.screen.WaitForString("!@#$%ThisWillNeverAppear!@#$%(((((", nWaitTimeSeconds)
End FunctionUnfortunately, with such a workaround, granularity is limited to one second.

eltorres
01-18-2005, 06:48 AM
Great!! It works !!
Thank you very much.