Forum Discussion
Abramova
Staff
14 years agoHi Andreas,
Robert is right, to calculate the maxTime value, use the aqDateTime.AddSeconds method.
Also, I have modified your function a bit. Now, it works as you expect. If the checkpoint has passed, it returns True and posts the time the checkpoint required. If the checkpoint has failed or if it does not work until the specified timeout elapses, the method returns False.
function waitUntilImageIsInStateA(maxTimeInSeconds)
{
var TimeNow = aqDateTime.now();
var maxTime = aqDateTime.AddSeconds(TimeNow,maxTimeInSeconds)
while(maxTime > TimeNow)
{
if( Regions.Compare("Image", Aliases.QObject.lblNavigation, false, false, true, 0, lmNone ) )
{
var Time = aqDateTime.now()- TimeNow;
Log.Message(":: TEST :: State A Occurred after " + Time + " milliseconds.");
//or using another way:
var Hours = aqDateTime.GetHours(aqDateTime.now()) - aqDateTime.GetHours(TimeNow) ;
var Minutes = aqDateTime.GetMinutes(aqDateTime.now()) - aqDateTime.GetMinutes(TimeNow) ;
var Seconds = aqDateTime.GetSeconds(aqDateTime.now()) - aqDateTime.GetSeconds(TimeNow) ;
Log.Message(":: TEST :: State A Occurred after "+ Hours + "Hours" + Minutes + "Minutes" + Seconds + "Seconds");
return true;
}
else
{
Log.Warning("Checkpoint failed or timeout elapsed while waiting for the checkpoint");
return false;
}
}
}
In this script, I have demonstrated two ways to calculate the difference between the two time values. The first one is the same as you used:
var Time = aqDateTime.now() - TimeNow;
Log.Message(":: TEST :: State A Occured after " + Time + " milliseconds.");
In this case, the result value is the amount of milliseconds.
Another way is to calculate the difference between hours, minutes and seconds separately:
var Hours = aqDateTime.GetHours(aqDateTime.now()) - aqDateTime.GetHours(TimeNow) ;
var Minutes = aqDateTime.GetMinutes(aqDateTime.now()) - aqDateTime.GetMinutes(TimeNow) ;
var Seconds = aqDateTime.GetSeconds(aqDateTime.now()) - aqDateTime.GetSeconds(TimeNow) ;
Log.Message(":: TEST :: State A Occurred after "+ Hours + "Hours" + Minutes + "Minutes" + Seconds + "Seconds");