03-04-2016 08:42 AM
Hello,
my measurement teststeps return results like 1,7267326467267236423 and only the first two values after the comma are interesting.
How can i set a Postexpression to round the result that ist put in Step.Result.Numeric before it is returned and displayed/reported?
Thx
Solved! Go to Solution.
03-04-2016 09:23 AM
You don't need a post expression necessary. I'm assuming you are using the Numeric Limit Test. Under the Limits tab, there's the Numeric Format cell, click on it and choose custom. Go into the Format box at the bottom and put "%0.2f". This will display the value and the limits in the report as 2 digits after the decimal place.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
03-04-2016 09:53 AM
Hmm, i clicked to early 🙂
This changes are only valid inside of TestStand and TestStand reporting.
The value that is delivered via API to the OPUI is still the original value...
03-04-2016 10:14 AM
That would make most sense. When you report or display the data is when you can cut off digits of precision or round. We know for certian at that point we don't need the accuracy.
While the data is still 'live' and can potentially influence other data (using it subtract from another value, like an offset), TestStand should use all available digits of precision.
I'd suggest rounding your value in the Operator User Interface if you want to only display the 2 digits of percision.
The only other method I can think of is to create your round function.
"Step.Result.Numeric = Round(Step.Result.Numeric*100)/100"
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
03-04-2016 11:32 AM
While Round will do what you want, it has a flaw in that it can false pass or false fail for values that are just outside of the precision of your limit you are rounding to unless you use a multiplier/divisor that is at least 10x greater than the precision you are interested in. So using PI, and looking for a precision of 3 digits, the following would false pass:
Step.Result.Numeric = PI,
Step.Result.Numeric = Round(Step.Result.Numeric*1000)/1000
For limits 3.140 <= x <= 3.141
As Round would set Step.Result.Numeric = 3.141, which is not correct (it should round to 3.142)
while:
Step.Result.Numeric = Round(Step.Result.Numeric*10000)/10000
would properly pass with the same limits.
An alternative option is to use the following:
Step.Result.Numeric = Val(Str(Step.Result.Numeric, Step.Limits.Low.NumericFormat))
so that the result is automatically properly rounded and truncated to the precision desired.
I hope this helps.
03-07-2016 03:33 AM
Thx for the solution. Looks very good.
Is there a callback to do this for all existing numeric limit tests at once?
Or do i have to do it manually for each step separate?
Thx
03-08-2016 11:44 AM
HI OnlyOne,
No unfortunately - See The Execution section of the TestStand Reference Manual, which has a Step Execution order-of-events list. There's no callback between the Module call, the Post Expression and the Status Expression evaluations. In theory you could create a custom step and add a Post-Step substep that could do this, but that's an advanced technique that I'll leave for someone who's done substep development like this.
Hope that helps.
-Jack
10-19-2016 01:43 PM
I've implemented this before in the SequenceFilePreStep callback although it does add overhead. You have to weigh in the added development time to copy/paste the rounding call into numeric tests versus the added overhead if you are running thousands of numeric limit tests in a row each time.
Essentially you should check that Parameters.Step.StepType.Name == "NumericLimitTest", and that rounding isn't already applied. Then you can add Jack's suggested text to the datasource (with whitespace) with the expression: Parameters.Step.DataSource = "Val(Str(\n" + Parameters.Step.DataSource + "\n,Step.Result.Numeric.NumericFormat))"