NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Check whether the current step is Passed or Failed and set an error code. (in Step Expression)

Solved!
Go to solution

Hi, I am trying to write an error code, when a step fails.

I tried this code in the post expression:
"FileGlobals.ErrCode=(Step.Result.Status!="Passed"&&FileGlobals.ErrCode==0?3:FileGlobals.ErrCode)"

 

However, this only works for Multiple Numeric Limit Tests.


With all other types of test, the result is always "Running". What is the problem?

m-a-i.de

GREAT IDEAS NEED GREAT SOLUTIONS
0 Kudos
Message 1 of 4
(3,586 Views)
Solution
Accepted by topic author MAIteam

Many layers going on here.  First let me explain something that you probably don't care about.  In general an error and failure are NOT the same thing.  A failure means something was wrong with the UUT.  An error means the code did not behave as expected (could be an unplugged cable, could be a bug in the software).  So what you are asking really doesn't make sense.  It means that you are probably abusing how TestStand is supposed to work and there might be a better solution to your real problem.

 

*stepping down from my soapbox*

 

That being said there are a couple of things you could do here.  I will refer to this page here in the options: https://www.ni.com/docs/en-US/bundle/teststand/page/step-execution.html  It is important to understand what happens when a step executes.  The reason that your other step types don't work is because the Status Expression is what sets the pass/fail status of the step.  As you can see from the chart that happens after the post expression.  Which means your Step.Result.Status is not set to "Failed" at that point so your expression doesn't work.  The Multi-Numeric is different because it has to use a post step sub step to do the evaluation and that occurs at Action 18 (this is all due to the complexity of evaluating multiple measurements), right before the post expression at 19.  Therefore you can see if the step has failed at that point.  

 

Option 1 - This is a hack, but you could do this in the Post Action.  See option 1 in the attachment

 

Option 2 - Throw the error in another step just after that step.  See option 2 in the attachment

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 2 of 4
(3,535 Views)

Thank you very much for the quick and detailed answer.

I understand the difference between an error and a failed test.

We are supposed to send an error number to the master computer for any problems.

 

Both your solutions work well.

 

We have found a third solution.

This expression seems to work, in the post expression as well as in a statemant afterwards.

 

"FileGlobals.ErrCode=(RunState.Sequence.Main["Pass/Fail Test"].Result.Status!="Passed"&&FileGlobals.ErrCode==0?3:FileGlobals.ErrCode) "

 

It seems clear to me that this works in a step after. But why does this also work in the post expression?

If this is only executed after the status expression, as you write.

 

Anyway, you have solved our problem, thank you very much.

m-a-i.de

GREAT IDEAS NEED GREAT SOLUTIONS
0 Kudos
Message 3 of 4
(3,512 Views)

My guess is that you are restarting the test and the status is lingering to a failed state???

 

Let me ask you this, after you run the test does your sequence file have an asterisk (*), meaning it needs to be saved?

 

Try to unload all modules between each run and ensure that what you are doing works.  It may not.  Just a hunch without actually testing it.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 4
(3,469 Views)