0

I have created a simple LabView program shown below that attempts to flatten an array [1,0,3] and then unflatten it and print out the contents.

However, I am unsuccessful in doing so. What am I doing wrong?

enter image description here

user1068636
  • 1,871
  • 7
  • 33
  • 57

2 Answers2

3

What am I doing wrong?

You're not going through tutorials or you're not reading the context help for the unflatten function (Ctrl+H) or you're not reading the full help for the function (right click>>Help) or you're not looking at the examples (from the help or Help>>Find Examples). Take your pick (preferably all four).

If you want an actual answer it is that LV is strictly typed, and therefore you need to tell the unflatten function which data type you want it to output (1D DBL array) and you're not doing that, but the real answer is what's in the previous paragraph - you should use those tools to learn how to find such an answer yourself.

Yair
  • 2,266
  • 12
  • 12
  • I have taken a look at the help (CTRL-H) but they don't tell you what the possible "type" values can be. Am I supposed to guess this? Is there a place they are all written? For example, how did you find "1D DBL array"? Also, I have looked for examples in Help >> Find Examples but all I see is flattening and unflattening data structures that are not arrays, which was not helpful. I will try passing in "1D DBL array" as the "type" input to unflatten function and repost if it works. However, if you could also point me to a list of all possible types that would be great. – user1068636 Jun 11 '13 at 12:58
  • Maybe you don't understand what flattening and unflattening means (which I hope the help explains). Flattening means taking a piece of data (which is represented in memory using whatever rules LV has for representing data, which can be found in the docs) and converting it to a continuous stream of bytes, represented as a string. Unflattening simply means taking a flattened string and converting it back to the original data form. In this case, you unflattened a DBL[], so that's what you would unflatten to. While there are some tricks, most other types would simply throw an error. – Yair Jun 11 '13 at 17:40
  • I wired a string "1D DBL array" into the type input of "Unflatten from String" function shown in the image above per your suggestion, however this did not work. – user1068636 Jun 11 '13 at 20:41
  • 1
    I wired the actual DBL array itself to the type input and it worked. – user1068636 Jun 12 '13 at 03:11
  • Also, assuming this is you - http://forums.ni.com/t5/LabVIEW/why-can-t-the-client-receive-array-over-TCP/m-p/2456140#M753768 - don't cross-post. It tends to just waste people's time, because multiple people try to answer the question. I would suggest you stick with the NI forums for these questions, as they're more suitable for this. – Yair Jun 12 '13 at 05:37
1

The string returned by Flatten to String only contains the data, not the description of what data type was passed in, so in order to unflatten it again you need to tell Unflatten from String what type it was. You do this by wiring some data of the appropriate type (any data - if it's an array it can be an empty one) to the Type terminal.

I don't think this is immediately obvious from the LabVIEW 2012 help but I think it's fairly clear if you follow the link from the Unflatten from String help page to one of the examples. The Read Flattened Data.vi example has an array wired to the Type input.

nekomatic
  • 5,988
  • 1
  • 20
  • 27