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: 

flatten to string and unflatten from string help

hey... can someone please help me!!! I need a simple example using flatten to string and unflatten from string.. I am using Labview 6.1 but i can't find any example in the software. Thanks alot...
0 Kudos
Message 1 of 9
(6,503 Views)
Flatten basically converts anything you give it to it's equivalent bytes in string form.

I use it all the time with TCP WRITE ( and unflatten with TCP READ)

If you have an arbitrary structure ( a cluster of stuff), how do you transmit it via TCP, which only takes a string? The answer is to FLATTEN it. Wire your structure into the ANYYTHING terminal of a FLATTEN function, and wire the outout string into TCP WRITE.

On the receive side, it's only slightly more complicated: Wire one of your clusters to the TYPE input of an UNFLATTEN function (so the function knows what the structure looks like). Note that the values in this cluster are unimportant, the function needs to know the TYPE of the cluster. Wire the received data from TCP READ into the BINARY
STRING input. What comes out of the UNFLATTEN function is one of your clusters !

(Of course, with TCP, if your structure is more than 1500 bytes, you have to break it up into two or more packets, but that's a side issue).

You could also use these functions to transmit an arbitrary cluster over a serial port or some other connection.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 9
(6,503 Views)
Dear CoastalMaineBird:

I've been following the steps you have indicated, but I get an error when I try to send the numbers array resulting of flattening a especified cluster ("type string output" of the function "Variant to Flattened String").
After sednding the flattened data, how can I send the array?. I get an error when I try it, and this is necesary for being able to unflat the string received on the other side.

Many thanks in advance!
Dani
0 Kudos
Message 3 of 9
(6,503 Views)
Please see this answer to your question.

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000000EF60000&USEARCHCONTEXT_CATEGORY_0=_49_%24_6_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(6,503 Views)
> I've been following the steps you have indicated,
> but I get an error when I try to send the numbers
> array resulting of flattening a especified cluster
> ("type string output" of the function "Variant to
> Flattened String").
>
> After sednding the flattened data, how can I send
> the array?. I get an error when I try it, and this
> is necesary for being able to unflat the string
> received on the other side.

All data is contained in the string, the type string is just an empty shell, telling the "shape" of the original data. Just create a diagram constant of the same data type and copy it to the receiving VI.

(See also 096.14&EXT=gif>this picture that I posted in this thread).
0 Kudos
Message 5 of 9
(6,503 Views)

Hello guys,please i have attached below the server and client sceen shots of a simple TCP/IP communication i am trying to do.When i run both vis i get an error message saying "LabVIEW:  Unflatten or byte stream read operation failed due to corrupt, unexpected, or truncated data." Please can you look at both screen shots and let me know what i am doing wrong?if possible give me a step by step solution on what to do.Thanks

 

Osowoaji


Download All
0 Kudos
Message 6 of 9
(5,506 Views)

Elimiate the typecast operations, they make no sense.

 

Convert your data to a 1D DBL array and flatten to string. Send via network. On the other end, unflatten the received string to a 1D DBL array.

0 Kudos
Message 7 of 9
(5,500 Views)

Hi there and thanks for the reply.This is what i have done but its still giving me the same error message.I'm i still doing it wrong?

 

Osowoaji

Download All
0 Kudos
Message 8 of 9
(5,490 Views)

@osowoaji wrote:

Hi there and thanks for the reply.This is what i have done but its still giving me the same error message.I'm i still doing it wrong?

 

Osowoaji


Let's try to keep the questions in a single thread.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 9
(5,487 Views)