From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading an array data type that has been bundled in a cluster and converted to variant

Solved!
Go to solution

Hi,

 

I am building a saving VI that takes a generic cluster and converts all of its contents into strings [first column variable name, second column variable] so I can use the 'write delimited spreadsheet' VI. I figured converting the cluster to variant, then accessing the elements of the cluster with the 'get cluster information VI' in the variant palette, then specify what to do with each data type would do the job.

 

Everything went well until I tried to extract an array, it doesn't spit any errors, but returns a blank array. I've attached a simplified code snippet -- I can't figure out what I'm doing wrong. 

snippet.png

 

I have also attached the more complex VI I'm working on.

0 Kudos
Message 1 of 13
(2,721 Views)
Solution
Accepted by topic author pablo.doc

So I've found a workaround. It turns out you can convert the cluster into an array of variants first and this works, although I find it a bit inelegant. I'm still unsure of what was wrong with my original thinking.

snippet_fixed.png

0 Kudos
Message 2 of 13
(2,701 Views)

Wouldn't is be simpler to just convert your numeric array to strings first?

 

Here's an example:

xCapture.PNG

 

Then then create a string array with your headers and write it with "write delimited spreadsheet.vi".

 

BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 13
(2,695 Views)

@pablo.doc wrote:

So I've found a workaround. It turns out you can convert the cluster into an array of variants first and this works, although I find it a bit inelegant. I'm still unsure of what was wrong with my original thinking.

snippet_fixed.png


You are wrapping your data within a cluster.  You need to decode it the same way:

convert.png

 

Edit:

Oops, I see you wanted it as an array.  Forget the FOR loop.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 13
(2,693 Views)
Solution
Accepted by topic author pablo.doc

Get Cluster Information.vi returns an array of variants each containing the elements type and not the values. You need to store the flatten string form of the original data as well to be able to convert it back:

Get Cluster Information.png

Lucian
CLA
0 Kudos
Message 5 of 13
(2,676 Views)

Hi RTSLVU,

 


@RTSLVU wrote:

BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.


Can you provide any reference for this information in the LabVIEW help?

Apparently it does some "digits of precision conversion"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(2,657 Views)

WOW this thread is becoming more Rube Goldberg by the minute.

 

Do me a favor and upload an actual copy of your cluster containing some sample data.

 

I am obviously missing something as your small example makes what you are doing an over complicated solution to something as simple as saving a numeric array to a file 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 13
(2,654 Views)

@GerdW wrote:

Hi RTSLVU,

 


@RTSLVU wrote:

BTW: the %S format makes the string an exact duplicate, it does not do any digits of precision conversion.


Can you provide any reference for this information in the LabVIEW help?

Apparently it does some "digits of precision conversion"…


I can't actually find anything but I have been doing this for years. You can specify the number of decimal places like this %.3S converts to a string with three decimal places

 

ARRAY2STRING.png

LabVIEW's normal rounding and numeric limitations do apply

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 13
(2,646 Views)

Hi RTSLVU,

 


@RTSLVU wrote:


I can't actually find anything but I have been doing this for years. You can specify the number of decimal places like this %.3S converts to a string with three decimal places


Then why do you use "S" when you want to use "f" (or any other format code for floats) instead? As can be seen in my image above "%S" behaves the same as "%f" with a default of 6 decimal places.

(IMHO this "S" is a bug within ArrayToSpreadsheetString: this format code results in an error when you want to use it with FormatIntoString. I guess it only works with ArrayToSpreadsheetString because NI doesn't want to "unfix" code running for years with this undocumented/wrong format code…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(2,634 Views)

There are quite a few libraries out there that do cluster to string conversion. The OP might want to look into a couple of those to learn some of the techniques.  A recent one that I have written is JSONtext, available on the Tools Network.  

0 Kudos
Message 10 of 13
(2,621 Views)