02-06-2020 10:49 AM
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?
Solved! Go to Solution.
02-06-2020 03:25 PM
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).
02-07-2020 03:13 AM
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.
02-07-2020 03:34 AM
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.
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.
02-07-2020 06:55 AM
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,
02-07-2020 07:01 AM
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.
02-07-2020 07:16 AM
Could you save your recursion vi to 2017? I haven't upgraded to 2019 yet. Maybe next year.
02-07-2020 07:45 AM
@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.
02-07-2020 09:16 AM
@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.
02-07-2020 09:19 AM
@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.