NIVeriStandAdd-Ons / VeriStand-steps-for-TestStand

NI TestStand Step Types for automating NI VeriStand.
Other
8 stars 16 forks source link

Incorrect Step.Result.Numeric When Looping with Get Channel Value Step #42

Closed droohy closed 5 years ago

droohy commented 5 years ago

Refer to the attached reproducing case for the code that demonstrates this. It is saved in VS 2018 and TS 2017. My sys def is completely blank except for a single user channel called "Test". This is the TS sequence:

image

I'm using the looping property of the two Get Channel Value steps to wait until a channel has changed value. When the sys def is deployed, "Test" is equal to 0. (The UI Manager confirms this.) This is what the sequence should do:

Deploy the sys def and wait for "Test" to equal 1:

image

Once "Test" is equal to 1, wait for "Test" to equal 0. I used the same looping logic as above except:

image

Once "Test" is equal to 0, undeploy and close VeriStand.

What I actually see is that after deploying, the sequence waits at "Wait for Test to Equal 1" until I change "Test" to 1 in the UI manager. Then, the sequence finishes out and DOES NOT wait for "Test" to equal 0. If I put breakpoints and debug, I see that all of the logged Step.Result.Numeric results for the "Wait for Test to Equal 1" are zero until the last one, which equals 1. This is expected. Then, the Step.Result.Numeric for the only iteration of "Wait for Test to Equal 0" is 0! The UI Manager, of course, still reads "Test" equal to 1.

Very curiously, if I put another Get Channel Value (with no looping) between the two Wait steps, its Step.Result.Numeric also reports the correct value of 1.

I can work around this by using a TestStand while loop around a single Get Channel Value step and setting a local variable equal to Step.Result.Numeric and using that variable's state to break the loop. That said, this involves 3 lines of TestStand "code" instead of one plus the use of a local variable instead of just using the looping feature of the step. This is really annoying! Let me know if you have trouble running the project.

Reproducing Case.zip

mbilyk commented 5 years ago

@droohy, looks like this is related to the way TestStand handles the looping function. It checks the looping expression before executing the step like a normal while loop (as opposed to a do while loop which checks the expression afterwards). The easiest way to see this for yourself is to set the Loop While Expression to false and notice that the step doesn't even execute. I tested this using a Message Popup step and setting the Loop While Expression to false.

What this means is that if you tie the Loop While Expression directly to the default value of a Step.Result or a Parameter, then the step won't execute. If you want to perform a do while then you should set a post expression for the step that checks the loop condition and sets a looping variable. There may be other ways to do this as well, but this is what I did Post-Expression: "Step.Result.Numeric == 0 ? Locals.EndLoop = True : False" Loop While Expression: "Locals.EndLoop == False"

mbilyk commented 5 years ago

Since this is related to the way that TestStand works rather than the VeriStand steps I am going to close this out, let me know if there is other information I'm not considering.