NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating Time Difference between 2 steps

I'm trying to calculate the time difference between two steps.

My first step (as a Statement) step sets the current time to a Local Number:

Locals.nCurrentSeconds = RunState.Main.Locals.ResultList[Runstate.Main.Runstate.StepIndex].TS.StartTime

The second step (with some execution time between) is a similar step and contains:

Locals.nCurrentSeconds = RunState.Main.Locals.ResultList[Runstate.Main.Runstate.StepIndex].TS.StartTime - Locals.nCurrentSeconds


However, I seem to have a problem with the "RunState.Main.RunState.StepIndex", in that I seem to get the exact same time return from both steps.

What am I doing wrong here? How do I reference "THIS STEP" for the StepIndex?

Mike
0 Kudos
Message 1 of 2
(3,553 Views)
If the steps that you are getting the times with aren't in your main sequence, then you are referring to the same step since you specify RunState.Main.

Also, you can't rely on the TS portion of the result for a step to be filled in until the step completes execution (or at least until you get the PostResultCallback for that step).

So, you must either look at the results of the correct steps AFTER they execute, or even easier, just call Seconds() whenever you need a time stamp. For example, in a pre-expression or a preceding statement step, use an expression like Locals.StartTime = Seconds(). When you reach the end of the region to time, use an expression like Locals.ElapsedTime = Seconds() - Locals.StartTime
Message 2 of 2
(3,553 Views)