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: 

How does "Unflatten From String" take a type and return a value of that type?

http://zone.ni.com/reference/en-XX/help/371361E-01/glang/unflatten_from_string/

 

How exactly does the "type" argument for "Unflatten From String" work? I need to create a VI that takes a type, passes it as an argument to several calls of the "Unflatten From String" function, and returns an array containing elements of the type originally passed. The "Unflatten From String" function seems to do some magic though, because the type of the "value" that it outputs changes depending on the type it is passed as input. How do I do the same magic in my VI?

 

Ultimately, what I need to accomplish is an unflatten-list operation. Given a type T and a byte string of length L (which contains a concatenation of T elements that are flattened to their bytes), create a VI that unflattens all the types in the string and return an array of length (L / sizeof(T)) that contains each type.

 

Note: performing the unflatten-list operation is trivial, but I cannot for the life of me figure out how to do it in a VI that takes a type and returns an array of the appropriate type. By the way, my data is being given to me from another source, so please don't bother suggesting that I should be flattening an array using LabVIEW's "Flatten To String" function in the first place. My data is not given in LabVIEW's array format: http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/flattened_data/

 

Thanks a ton!

 

-Wakka

0 Kudos
Message 1 of 7
(6,206 Views)

You cannot make a single VI that does the same magic as "unflatten from string".

 

However, if you only have a relatively "short list" of possible datatypes, you could make a polymorphic VI.

Message 2 of 7
(6,185 Views)

You can do something close with LabVIEW Classes and Dynamic Dispatch. But Altenbach is right, there is generally in LabVIEW no capability for templatizing code in this way. The Flatten/Unflatten functions work because they are primitives, not subVIs. This allows them to generate their code at edit-time according to the input parameter types.

Jarrod S.
National Instruments
Message 3 of 7
(6,154 Views)

Take a look at this example:  You can see that the flattened string contains several bytes.  The first four bytes contain the length of array (number of elements).  Since the data type is U32, the next 32 bits (4 bytes) contains the value of the first element, and so on.  Could you possibly use this scheme to do what you want to do?  Other data types present different outputs.  You would have to experiment with them.

 

Example_VI.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 7
(6,148 Views)

There might be a way of doing this, but I'm not sure as I'm having some difficulty understanding your problem.  I think the confusionn is coming from the fact that you appear to be using the word type synonymously with value.  In some cases you mean of type X and sometimes you mean a value that is of type X. Could you please clarify as I hate trying to figure out what people are saying and saying more than I need to, to cover all possible cases that could have been meant.

 

Thanks,

 

 

A

0 Kudos
Message 5 of 7
(6,120 Views)

 


@wakka wrote:

Ultimately, what I need to accomplish is an unflatten-list operation. Given a type T and a byte string of length L (which contains a concatenation of T elements that are flattened to their bytes), create a VI that unflattens all the types in the string and return an array of


 

Ignoring the rest of what you said and jsut focusing on this section here, you can do this semi genericly.  LabVIEW doesn't support templates as stated before, BUT, you can do a variation of copy coding using polymorphic VIs and have the VI adjust to the type of input you give it.  I.e. you give it an int as an input and it will output an int array, you give it a string as an input and it will output a string array.

 

 

A

0 Kudos
Message 6 of 7
(6,107 Views)

Thank you, but I believe the first response answered the question best.

 

LabView simply does not support what I'm looking for. Looks like I'll be sticking with copy and paste.

 

0 Kudos
Message 7 of 7
(6,051 Views)