LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Ref Array of clusters from Variant to values.

Solved!
Go to solution

I am trying to get the information from the Kistler Channel control. Normally this would be somewhere else in the code and all I would get would be the reference to the control. When I use the code that I made I can get some of the elements from this array of clusters. I get the 1-3 elements. I can not get the 0 element. Am I missing something here?

 

Is there a way to get the number of array elements?

Is there a way to index through the array elements?

When I get the values of the array it comes out as variant but it does not seem to be an array.

 

Is there a way to break this down and get the data out of it?

 

Example.png

Tim
GHSP
0 Kudos
Message 1 of 10
(4,237 Views)
Solution
Accepted by topic author aeastet

Perhaps the attached VIs will help you get going.

Note: The "Array Element" reference property of an array doesn't necessarily reference the element specified by the "Index Values" property; it references the element that most recently had text focus (thus it's not useful for getting element values).

Notice also that you have a loop with 4 iterations, but you don't do anything differently with the different iterations (pointless).

"If you weren't supposed to push it, it wouldn't be a button."
Download All
Message 2 of 10
(4,190 Views)

You might benefit from recursion. You do use recursion at the moment, but the way you do it is often called "fake recursion".

 

I'd refactor the code so it uses variant values, not references. You can easily get the variant value from a reference, but by using variants, you can also use the VI to convert constants, and actually any value.

 

If you then make the VI reentrant, you can actually:

1) Get the type (array in this case)

2) Get the (variant) value from the array.

3) Convert the variant value to an array of variants (Variant To Data)

4) In a for loop, call the same VI

 

That works for clusters too.

 

The reentrancy will make things harder to debug and maybe more complex conceptually, but it will a lot be less code.

Message 3 of 10
(4,167 Views)

Here's a quick mockup. It only returns the data types (because that is easy for me to setup). You can specialize for specific data types, just like you are doing with the references.

 

Recursion.PNG

 

You'll run into the usual problems: floating point nr. of decimals, strings escape characters, empty array of strings vs empty string in 1 element array, etc.. This will happen for every solution you come up with.

 

Note that it's easy to format the output string to be valid JSON. You might look into JSON, and JSON libraries. JSON might actually be exactly what you are trying to make.

Message 4 of 10
(4,165 Views)

Hi Paul,

 

Thanks for the info. It did what I wanted to do with the data. This is part of a much larger data processing system. I made something quick to show what I was trying to do. I figured I was missing a step.

 

Thanks,

Tim
GHSP
0 Kudos
Message 5 of 10
(4,151 Views)

Hello wiebe,

 

This code is very old. This is the first time I have touched it in around 15 years. It is implemented in hundreds of programs and I have never had a problem. Back when it was developed variant data was not developed like it is today and recursion was not allowed. I forget what version of LabVIEW that came out to allow recursion. I should take the time to go back through this and update everything to work with variant data better. I think if you saw the full construction you would understand why I am using references.

 

Thanks for your input.

Tim
GHSP
0 Kudos
Message 6 of 10
(4,147 Views)

Could you save your recursion vi to 2017? I haven't upgraded to 2019 yet. Maybe next year.

Tim
GHSP
0 Kudos
Message 7 of 10
(4,138 Views)

@paul_cardinale wrote:
 

That is a complicated way to get variant values from a cluster.

 

Variant To Data will convert the cluster elements to an array of variants if you wire an array of variants constant to it.

 

I bet that will be an order of magnitude faster as well.

Cluster variant.PNG

Message 8 of 10
(4,129 Views)

@aeastet wrote:

Could you save your recursion vi to 2017? I haven't upgraded to 2019 yet. Maybe next year.


Here it is in LV13.

Message 9 of 10
(4,104 Views)

@aeastet wrote:

I think if you saw the full construction you would understand why I am using references.


 Nothing wrong with working with references (in modesty).

 

What I ment was: from a reference, get the variant and recurse the variant. This in stead of recursing the references. That is a dead end for arrays, but I guess we established that already.

 

Of course you still need to recurse references if you want to 'step into' tab pages.

0 Kudos
Message 10 of 10
(4,102 Views)