NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do i configure a FOR loop to have the behavior of the step Loop Type: Pass/Fail count?

Hello,

I'm using the Pass/Fail count set to one Pass to capture an event generated by my DUT.  I originally used a numerical compare step with the Looping type of Pass/Fail count to accomplish this.  Unfortunately the implementation changed and now I need to execute a few steps that can not be combined within one code module as before. Nor can these steps be put into a subroutine.  One of the steps executes a .NET asembly and I haven't figured out how to pass the reference to the subroutine.  When the subroutine is intered the reference is lost and the methode does not execute correctly.

I have an evaluation function the exits the loop when the expected conditions are met. Everything works except for the Overall Pass/Fail result of the For loop.  If the loop exits due to the first numerical compare test passing, I want the loop overall execution to report as "Passed".  If the loop reaches it's predetermined number of iterations, the overall result needs to report as "Failed".  It would also be nice to have the radio button functionality of "Record Result of Each iteration".  Some conditions require a wait over a minute for the event to occur and I don't want to generate needless data for the report.

Currently I get the pass/fail status for each For loop iteration, but only "Done" for each loop iteration.  I don't want the initial few failures to cause the test to fail.

Does anyone know how to do this? Suggestions?

Thanks,

0 Kudos
Message 1 of 7
(6,883 Views)

I think this problem would be easier to understand if it were broken into pieces:

When the first instance of the numerical compare within the For Loop passes, Step.Result for the loop = “Passed” AND the loop is terminated.

 

        OR

 

If the For Loop reaches the maximum count, the Loop Status should report as “Failed” (Locals.index < 5 is no longer true).

I have the loop termination piece worked out with a function to set the index out of range: PreviousStep.Result.Status == "Passed" ? (Locals.index = 100) : (Locals.index = Locals.index)

 

I believe I’ll need to uncheck the “Step Failure Causes Sequence Failure” Run Options Property for all the numerical compares. This allows the steps that fail to not effect the overall sequence failure while it is iterating through until the event is detected.

 

I can also use the Result Recording Option of Disabled for the loops that run long.

 

I think I’ll need to use a separate step to record the iteration result as “Done” and ultimately “Passed” / “Failed” depending on if the event is detected or the loop limit is exceeded. Is there a way to access the Status Expression of a multiple numerical compare? I have to jump through these extra hoops because the status expression is not available.

 

Please advise if this approach is plausible or any better way of accomplishing this.

 

Thanks,

Tim

0 Kudos
Message 2 of 7
(6,859 Views)
Hi Tim,
 
Is there a reason you're using a For Loop instead of a While Loop? Just from the initial functionality that you described that you wanted to get, I think a while loop might be the better way to go, since you can specify your loop conditions.
 
You mentioned using a separate step to record the iteration result as “Done” and ultimately “Passed” / “Failed”, that would be my first instinct on how to get the functionality you want.
 
Can you elaborate on what you mean by the status expression of multiple numerical compares? I just want to make sure I understand this correctly, do you mean the overall status of different numeric tests?
 
0 Kudos
Message 3 of 7
(6,848 Views)

I have 2 steps in the loop that can not be combined into one step. This forces me to implement the behavior in some form of loop.  A While Loop could be an option.  I would need to pass the Step.Result.Status from the Multiple Numerical compaire step to the condition of the While Loop.  I tried to use the Step.TS.ID without success.  Some form of reference to the numerical compare step would be needed. I'm using a For Loop as I do want to limit the number of iterations of the loop.  In the case where the loop iterations are reached, the event I am trying to detect did not occur at the correct time and a failure needs to be reported.

 

I came up with something based on my comments in the second post:

1) To start with I configured a Locals.ForLoop_5 variable.  This is used to set the limit on the loop iterations and for comparison after the loop has finished executing. More on that later.

2) The first step inside the loop invokes a method within a .NET assembly that has been packed in a DLL This method gets the required data from the DUT and stores it to a text file.

3) The next step is the Multiple Numeric Limit step.  This step invokes a VI that extracts the data from the text file.  This step has been customized in several ways.

  i)  In Run Options, the Results Recording Option was disabled.  This prevents recording of "Failed" while the loop executes when waiting for the event to happen.

  ii) In Run Options, the Step Failure Causes Sequence Failure is unchecked.  Same reasoning as i)  These steps are not true failures.

  iii) A Post Action is configured to go to the nexxt step after the For Loop End step On Condition True with the logic of Step.Result.Status == "Passed".  This causes the loop to exit when the first "Passed" is encountered which corrolates with the event I'm trying to detect. On Conditon Fail remains set to default.

4)  The step after the For Loop End is an expression step with everythin set to default except for the Status Expression logic set to: Locals.Loopindex < Locals.ForLoop_5 ? (Step.Result.Status = "Passed") : (Step.Result.Status = "Failed"). This step performs the overall Pass/Fail reporting for the For Loop.  If the number of loop iterations is less than the maximum it could have only gotten there by the previous logic triggered by the numerical compare passing, therefore "Passed".  If the loop index has reached the limit, then the event was not detected, therefore Failed.

 

I have tested this work around with success, it just a pain to now have to implement this on my 40 some odd For Loops.

 

If there is a better way, I'd still like to hear it.

 

0 Kudos
Message 4 of 7
(6,832 Views)
That's pretty much how I would do it, but I would use a while loop instead to avoid the go to next step you described in 3iii). So I would have the same functionality but my while loop expression would check if the number of iterations has reached a limit OR if the numeric limit step has passed, in either case I'd exit the loop. With this implementation you'd still require that extra step outside to compare the loop index (which you'd have time increment in the while loop after each iteration).  The while loop implementation would only minutely improve efficiency however you will get the same functionality in either case. 
 
Does anybody else in the community have any suggestions?
0 Kudos
Message 5 of 7
(6,799 Views)

Hello,

 

How is the result from the numerical compare used in the While Statement logic?

 

I've tried RunState.PreviousStep.Result without success.  I've also tried using the TestStand Step ID:# as well without success.

 

I'm sure I'm missing something simple.

0 Kudos
Message 6 of 7
(6,762 Views)
I would just save that numeric compare result in a local variable and just read that variable in the expression of the while loop. Does that make sense?
0 Kudos
Message 7 of 7
(6,741 Views)