NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

best practice for Logical OR pre-condition evaluation

Solved!
Go to solution

Greetings,

 

I'm finding TS doesn't have basic features for decision making (imp) for execution. Any recommendations are welcomed and appreciated. Please see below scenario.

 

I'd like to execute setup steps (custom step types) for a signal generator based upon the user selected "Test".

 

To keep it simple for the signal generator let's say we have the following steps:

 

Set Freq | Set PWR lvl | Set Modulation Type | Set Modulation ON/OFF | Set RF Power ON/OFF

 

For User Selected Tests let's say we have Test A(0) | Test B(1) | Test C(2) (Test  A & C requires Modulation, B does not)

 

Here's my issue:

 

I can't get SET Freq | SET PWR lvl | Set RF Power ON/OFF to execute a pre-condition setup for evaluating Logical OR's. (i.e. locals.TestSelected ==0||1||2)

 

Same for Set Modulation Type | Set Modulation ON/OFF (i.e locals.TestSelected ==0||2)

 

Thanks in advance for any guidance provided.

 

Chazzzmd78

0 Kudos
Message 1 of 6
(6,302 Views)
Solution
Accepted by topic author chazzzmd78

locals.TestSelected ==0||1||2 would equate to local.TestSelected == 3.  You are doing a bitwise OR on the numerics and then the comparison.

 

You need

(locals.TestSelected == 0) | (locals.TestSelected == 1) | (locals.TestSelected == 3)


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(6,300 Views)

That makes sense....thanks! Enjoy the holiday

0 Kudos
Message 3 of 6
(6,294 Views)

Just want to clarify, there seems to be a misunderstanding about the difference between bitwise OR (i.e. the | operator) and logical OR (i.e. the || operator). Bitwise OR results in the combination of all of the bits which represent an integer stored as binary, while logical OR (i.e. what you really want in this case) results in a True, non-zero, value (usually 1) if either operand is non-zero.

 

Also, the == operator has a higher precedence than either the bitwise OR or logical OR operators.

 

So what this means:

 

locals.TestSelected ==0||1||2

 

is to give a result of True (i.e. 1) if either locals.TestSelected ==0, 1 is non-zero, or 2 is non-zero. Since 1 and 2 are always non-zero that expression will actually always result in a True value.

 

Similarly, although the following will likely give you the behavior you want:

 

(locals.TestSelected == 0) | (locals.TestSelected == 1) | (locals.TestSelected == 3)

 

That's not really doing what you are probably thinking it does. It's actually getting the value True (i.e. 1) for each of the sub-expressions in parethesis and then bitwise OR'ing them together. Since the result for the == operand is always either 0 or 1, this ends up giving the same result as logical OR (i.e. the || operator), but what you really want in this case is logical OR and for other expressions using bitwise OR when you mean logical OR might give you incorrect results. So, you should really be using something like the following:

 

Locals.TestSelected == 0 || locals.TestSelected == 1 || locals.TestSelected == 3

 

The parenthesis don't really matter in this case (so can be left out, but also doesn't hurt anything so you can leave them in if you prefer) because the == operator has a higher precedence than the || operator so all of the == operations will be done first.

 

Hope this helps clarify things,

-Doug

Message 4 of 6
(6,203 Views)

Hi Doug,

 

Is there another way this expression can be writtien?  Within a sequence file, if I was using values 0-14 to represent 15 different products this expression would seem really inefficient.

 

For example, if I set a precondition expression for a sequence step to be only run for products 3-9 (using a numeric Local called ProductType), the precondition expression would be:

 

Step Precondition Expression: (Locals.ProductType == 3) || (Locals.ProductType == 4) || (Locals.ProductType == 5) || (Locals.ProductType == 6) || (Locals.ProductType == 7) || (Locals.ProductType == 😎 || (Locals.ProductType == 9)

 

This seems very inefficient.  Is there a simpler syntax (more efficient way) to do this?

 

Thanks!

0 Kudos
Message 5 of 6
(4,748 Views)

testdesign,

 

I just wanted to make you aware that this forum thread is no longer active as it is over a year old. It is therefore no longer monitored by National Instruments to ensure a timely response. I would recommend creating a new forum thread to generate a better response from the forum users regarding your question. You can reference this thread as a link in the new post to create context.

Mena S.
Applications Engineering
National Instruments
Message 6 of 6
(4,709 Views)