NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Property Value - Array element, indexing with another variable

Solved!
Go to solution

Hi.

 

I am trying to obtain the value of an array element in TestStand using the LabVIEW Get Property Value VI. My lookup string looks like this:

Locals.IdArray[RunState.TestSockets.MyIndex]

 

But it I get an error -17306, saying that RunState.TestSockets.MyIndex cannot be found. I know this is not true, since I have no problem accessing it from a TestStand expression executed in the step just before my LabVIEW step. I have tried to use a numeric value placed in Locals instead of the RunState variable, but the result is the same.

 

So my question is this: Can it really be true that I can only use a constant as index for an array when using the Get Property Value VI?

 

/Jens Christian Andersen.

Best regards
Jens Christian Andersen.
CLA, CTA, CPI
0 Kudos
Message 1 of 8
(10,072 Views)

The parameter required is string based as the name suggest therefore you have to match sure it's all in the format of a string

 

eg

"Locals.IdArray[" + str(RunState.TestSockets.MyIndex) + "]"

 

 

Regards
Ray Farmer
0 Kudos
Message 2 of 8
(9,959 Views)

Thanks for you reply.

 

The way of writing the lookup string works well when I put it in to an expression in TestStand. But when I use it from within LabVIEW it does not work like I expected. I the VI is use a string control as input to the Get Property Value VI, and putting " " around the whole statement will not be like doing this ""<Variable>"" in a TestStand expression. So I tried to make it like this Locals.IdArray[" + str(RunState.TestSockets.MyIndex) + "] and this Locals.IdArray[str(RunState.TestSockets.MyIndex)] but it did not work.

 

Any suggestions on how to make this work correct from LabVIEW?

 

Regards

Jens Christian Andersen

Best regards
Jens Christian Andersen.
CLA, CTA, CPI
0 Kudos
Message 3 of 8
(9,955 Views)

Since you are using this lookup string in a module, not within TestStand itself, you cannot use string-parsing-capabilities from TS.

 

So your code has to look like something like this:

VI_Module_Code.PNG

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 8
(9,952 Views)

Let me try to clarify:

 

What you are doing (i.e. Locals.IdArray[RunState.TestSockets.MyIndex]) is fine from a teststand expression, but using a variable as an index does not work when you are just specifying a lookup string, you have to use an integer or string literal (if indexing an array of objects by name, but I don't think that's what you are doing in this case) instead. Probably the easiest thing to do is build a lookup string with the integer index hardcoded into it as Norbert is suggesting. Another possibility, but a more complex one, is to create a TestStand expression with your string in it and evaluate it programmatically using the current sequence context as the evaluation context.

 

Hope this helps,

-Doug

Message 5 of 8
(9,939 Views)

OK, it is just like it looked from the error message then. The PropertyObject methodes GetVal<Type> only passes the first statement and not recursive statements.

This look like I will be making my own version of the Get Property Value VI, which analyses the string for recursive expressions.

 

Thanks for your help.

 

Regards

Jens Christian Andersen.

Best regards
Jens Christian Andersen.
CLA, CTA, CPI
0 Kudos
Message 6 of 8
(9,936 Views)
Solution
Accepted by J.C._Andersen

1) This has nothing to do with recursive statements. Lookup strings are not expressions. They are just the location of a subproperty or element.

2) If what you want is expression evaluation, there is no need to create such a thing from scratch. You can use the TestStand API to execute an expression rather than using the lookup string feature if that is the behavior you want. For example this is what it would look like in a text based language:

 

double mynumber = mySequenceContext.AsPropertyObject().EvaluateEx("Locals.myarray[Locals.myindex]", EvalOption_DoNotAlterValues).GetValNumber("", 0);

 

Hope this helps,

-Doug

Message 7 of 8
(9,923 Views)

Thanks Doug.

This is what I was looking for. Sice this is to be used in the setup GUI of a custom step type, I want it to look as simple as possible to the user of the step type, and at the same time be flexible enough to handle a variable as array index.

 

Regards

Jens Christian Andersen.

Best regards
Jens Christian Andersen.
CLA, CTA, CPI
0 Kudos
Message 8 of 8
(9,884 Views)