NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I iterate using elements of an array in TestStand?

I have a 2D array in TestStand that I have populated using Labview and reading from an Excel spreadsheet. I have columns X, Y, and Z in the array stored as a Local in TestStand. What I am trying to do is iterate on this array using the ForEach function in TestStand. So for each row in the array I have parameters that I am using for my test. Each row again has a value from column X, Y, and Z. In Labview this is a breeze. I want to use the TestStand methods to perform this function. Is this possible and if so how? I would appreciate any help.

 

Thanks,

Troy

0 Kudos
Message 1 of 16
(12,029 Views)

As you would in any other programming language, simply nest two for loops to iterate over the 2D array by index. If there's going to be a variable number of rows/columns, you can parse the return values of the GetArrayBounds() function to set the bounds of your iterations. Depending on how exactly you're retrieving the data, however, it may be more straightforward to store boundary information in additional locals while reading the data.

0 Kudos
Message 2 of 16
(12,024 Views)

That is why I am asking the question. The NI s/w environment is the only programming language I use. So what I was looking for was maybe an example of how this is done in TestStand.

0 Kudos
Message 3 of 16
(12,010 Views)

check out jigg's example, I haven't looked at it but as it's just a seq file it must be doing all the array indexing in TestStand.

 

http://forums.ni.com/t5/NI-TestStand/Foreach/m-p/1153817

 

Hope this help, otherwise I generate a simple example later on today

 

Regards
Ray Farmer
0 Kudos
Message 4 of 16
(11,998 Views)

jigg's example is effective, but it may not be easy to reuse.

 

The attached demonstrates both a for loop and a foreach loop. Notice that the foreach uses fewer steps but iterates down a column; the for loop can iterate either across a row or down a column.

Message 5 of 16
(11,990 Views)

Thanks for taking the time to post. I see what is going on here although I have to admit the expression at the beginning is a little hazy to me as far as what it is doing and how. Non the less I put my array of data in place of what was in the example and it is working. I have to say that the ForEach is actually working better for me. I have an array of strings as follows:

 

Freq, Symrate, Modulation

1000, 512, QPSK

1001, 1024, QPSK

1010, 2048, QPSK

 

and so on. What I am trying to do is get the Freq, Symrate, and Modulation all at the same time and put them into variables that will be used for each step of the test. So I would want to get in the first instance 1000, 512, QPSK into their own variables to configure my test. Is there a way to do this using the example forwarded? Again, thanks for the help provided so far. One other thing, if there were another column added in the future would that make changes needed in the expression that is evaluating the array at first? An explanation of that expression in the beginning would also help. Thanks again.

0 Kudos
Message 6 of 16
(11,979 Views)

The expression is a tad hairy 😉 Try this on for size:

 

First, notice that there are three separate expression here, delimited by commas. The first (GetArrayBounds()) retrieves the upper and lower boundary sizes of the array and stores them to a local. Unfortunately, TestStand only uses string-based values to look up indicies, so this is why parsing is necessary.

 

GetArrayBounds(Locals.TwoDeeArray, Locals.LowerBounds, Locals.UpperBounds)
Locals.LowerBounds isn't used in this example because the data array has a known lower boundary of 0,0, but the function calls for both parameters.

 

Locals.Rows = Val(Mid(Locals.UpperBounds, 1, Find(Locals.UpperBounds, "]") - 1)) + 1
This line effectively pulls out the first dimension from the bounds string. The first character will always be "[" so the starting index can be hard-coded. The subset length is dependent on where the first "]" is in the string, using Find() the expression can adapt for 1, 2, or n digit dimensions. The significance of the "- 1" is more clear in the next expression. The Val() wrapper simply turns the parsed string into a numeric value, which is necessary for the For step type and the "+ 1" adjusts the bound to be 1-based instead of 0-based.

 

Locals.Columns = Val(Mid(Locals.UpperBounds, Find(Locals.UpperBounds, "[", 0, True, True) + 1, Find(Locals.UpperBounds, "]", 0, True, True) - (Find(Locals.UpperBounds, "[", 0, True, True) + 1))) + 1
The gist is the same for this line, but it's a bit more complicated because the start and end positions are dependent upon the length of the first dimension. The trick is to find the last "[" and last "]". Using those positions, you can calculate where to subset the string. Take a look at the parameters for Mid() and Find() and everything should click. If it helps, you can break each call (Mid(), Find(), etc) into watch expressions and look at what their return values are.

 

As for integrating this method with your example, you should try to have another go at implementing this yourself. If you still get hung out, post what you've come up with and it'll be much easier to help.

Message 7 of 16
(11,978 Views)

Hi,

 

i do not want to highjack this thread but, if this would be my task here,

i would think about an array of datatype. With this you can use foreach to iterate.

and you can access the elements of the type better.

 

Regards

 

juergen 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 8 of 16
(11,965 Views)

I am currently working through the post from asbo. I now understand what is happening in the expression. However I am still open to ideas. Right now I am trying to access the data as explained earlier where I am loading my three elements/row into their respective variables. That is the part right now where I am stuck but working on. Can you explain or give an example of the method you are referring too?

0 Kudos
Message 9 of 16
(11,961 Views)

Hi,

 

Maybe this helps

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 10 of 16
(11,954 Views)