LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read/write many matrices through TCP server?

I'm trying to modify the simple data client and the simple data server program in example in LabVIEW6i. How do I send a 2 dimension nummeric matrix? and also how do I send many numeric matrices at a time?
0 Kudos
Message 1 of 6
(3,612 Views)
Hi Irene,
Regarding that example, probably you are wondering how can you pass a 2D array to Type Cast.VI (it accept only 1D array). The answer is Reshape Array.VI. Use this VI to transform your multidimensional array in a 1D array (after that use Type Cast.VI to transform it in a string). Also, you can use Array To Spreadsheet String.VI in order to obtain a string to send via TCP, but in this case the string is longer.
An important aspect is the nature of the data that you are sending. Thus, you have two approaches:
1. If the type of the array (nr of elements and dimensions) is known at design-time, when you receive the string in the other VI you will know how to convert it back to array.
2. If the type of the array could be variable or you want to pass many t
ypes of arrays you have to do a little protocol - for example, for each string that you send, add a header (another string) to the string containing data. In this header you can pass information (like number of elements, dimensions) to the other application. Let's say that you have 2D arrays. Use a header with 10 characters - first 5 for rows and last 5 for columns. This way, when the other application will receive the string, first take out the header, parse it, find the number of rows and columns and you will know how to transform the rest of the string in a 2D array.
If you can not go forward with this explanation, email me at labviewer@yahoo.com.
Good luck!
Message 2 of 6
(3,612 Views)
Lab Viewer wrote:
>
> Hi Irene,
> Regarding that example, probably you are wondering how can you pass a
> 2D array to Type Cast.VI (it accept only 1D array). The answer is
> Reshape Array.VI. Use this VI to transform your multidimensional array
> in a 1D array (after that use Type Cast.VI to transform it in a
> string). Also, you can use Array To Spreadsheet String.VI in order to
> obtain a string to send via TCP, but in this case the string is
> longer.

Or better, wire the 2D array to the Flatten to String function, which
accepts any data type.

When you receive the data, wire the string into the Unflatten from
String function. You'll need to wire a 2D array of the same
representation into the type input of that function.

Mark
0 Kudos
Message 3 of 6
(3,612 Views)
The problem here is that at the receiving end, one cannot know how many
bytes to read before unflattenning into the datatype.

A method that works for *any* datatype (and any data transfer mechanism):
Flatten the data to string.
Flatten again the string to string; this adds a string lenght (U32) header
to the string.
Send the string.
When receiving data, first read 4 bytes and convert to U32.
Read this number of bytes.
Typecast the string to the expected datatype.

Jean-Pierre Drolet



----- Message d'origine -----
De : "Mark Hanning-Lee"
Groupes de discussion : comp.lang.labview
Envoye : 6 septembre, 2001 22:21
Objet : Re: How do I read/write many matrices through TCP server?


> Lab Viewer wrote:
> >
> > Hi Irene,
> > Re
garding that example, probably you are wondering how can you pass a
> > 2D array to Type Cast.VI (it accept only 1D array). The answer is
> > Reshape Array.VI. Use this VI to transform your multidimensional array
> > in a 1D array (after that use Type Cast.VI to transform it in a
> > string). Also, you can use Array To Spreadsheet String.VI in order to
> > obtain a string to send via TCP, but in this case the string is
> > longer.
>
> Or better, wire the 2D array to the Flatten to String function, which
> accepts any data type.
>
> When you receive the data, wire the string into the Unflatten from
> String function. You'll need to wire a 2D array of the same
> representation into the type input of that function.
>
> Mark


LabVIEW, C'est LabVIEW

0 Kudos
Message 4 of 6
(3,612 Views)
Thanks a lot for answering me.I'm using LabVIEW6i and I can't find any "Flatten to string" function. where can I find "Flatten to String" function?
0 Kudos
Message 5 of 6
(3,612 Views)
In Functions>Advanced>Data Manipulation

You can search a function in the palettes clicking on the magnifier button
in the palette menus.

I have written in my post "Typecast the string to the expected datatype". I
should have written Unflatten from String instead of Typecast.

Jean-Pierre Drolet


"Irene" a ecrit dans le message news:
5065000000050000008C400000-999158726000@exchange.ni.com...
> Thanks a lot for answering me.I'm using LabVIEW6i and I can't find any
> "Flatten to string" function. where can I find "Flatten to String"
> function?


LabVIEW, C'est LabVIEW

0 Kudos
Message 6 of 6
(3,612 Views)