LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send float array from vb to labview over tcp/ip

I used tcp/ip for getting one float array data from Visual Basic.Its not working fine.FRom Vb i have converted that array into string function.Here i'm getting it as a single string.Can anyone help me please.
0 Kudos
Message 1 of 11
(5,222 Views)
On the VB end, how exactly are you converting the array into a string? If the result is a string of values that is the binary representation of the values in the array, it might be as simple as doing an unflatten from string. (If you are using single precision in VB each element in the array will be a series of 4 characters in the string. Segmenting the input string into 4-byte chunks and then unflattening from a string to a SGL float might recover your data.)

Conversely, if you are formatting the data as ascii, a function such as spreadsheet string to array might do the trick.

It all depends on how you converted the data in the first place.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 11
(5,222 Views)
See my code how i'm converting.
Dim data(4) As Variant
Dim s As String
Dim st(4) As String
Dim i As Integer
data(0) = 34.46
data(1) = 56.78
data(2) = 68.89
data(3) = 45.22
For i = 0 To 4
st(i) = Str(data(i))
Next
s = st(0) + st(1) + st(2) + st(3)
Winsock1.SendData s
Now tell me how to receive this data there.
Or give me an idea of sending this array from VB itself.
0 Kudos
Message 3 of 11
(5,222 Views)
If I understand properly what this code is doing, it should come across as a string of binary values that you be able to convert like I said before. The only thing you need to know is the precision of you floating-point numbers.

An easier solution might be to format them for transmission as ascii strings such that number 34.46, for example, comes across as the string "34.46". That gives you something readable to look at and is easy to convert.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 11
(5,222 Views)
Hi actually i tried the unflatten function at the terminal dataread in the TCPREAD.vi.BUt nothing is displayed.Plz send me the example vi what u r mentioning abt.
0 Kudos
Message 5 of 11
(5,222 Views)
Maybe if you show what the received string looks like when you receive it, we can find the problem.

One problem which I see is that you`re actually generating a non-delimited string i.e.
12.2234.4412.32 for the numbers 12.22, 34.44 and 12.32. Try
s=str(i)+", "str(i+1)+", " and so on.
This should produce a string of
12.22, 34.44, 12.32,

You can then split the string into individual numbers using the commas.

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 6 of 11
(5,222 Views)
Its a good idea.On other end ie at my vi i'm receiving the datas as single array.i tried unflatten string and typecasting functions. i cant able to reproduce my float array.
0 Kudos
Message 7 of 11
(5,222 Views)
When you receive the string representing your array, you need to use some string formatting functions to ger the four individual values as the data type you want (using the convert from string is the best option), and then build them to an array. I don`t think the "unflatten" approach will work as LabVIEW is very specific as to the acceptable data tapes for strings. I recall having seen the specifications for flattened data once, but I can`t recall where.

I have an example in LV 6.0 attached.

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 8 of 11
(5,222 Views)
parimala wrote:
> Its a good idea.On other end ie at my vi i'm receiving the datas as
> single array.i tried unflatten string and typecasting functions. i
> cant able to reproduce my float array.

Can you be more specific ?

What do you get when you try ?
smoke from the monitor ?
Blue screen of death ?
Labview crash ?
No data in your array ?
Wrong size array ?
Wrong data in correctly sized array ?

You may find it helpful to get lv to display the string it receives
and try and unpick it by hand. Hex display can be useful for this.

You could also try creating the array in labview by hand for a set
of sample data and then flattening this to a string and displaying it,
by comparing this with the string you get back from VB along side
the refer
ence material about how lv stores data you may be able to
work out what is happening.




--
Remove "spamkill." when replying to this message
0 Kudos
Message 9 of 11
(5,222 Views)
Run this example so that u may understand what's my problem.
my vb code
Dim data(4) As Variant
Dim s As String
Dim st(4) As String
Dim i As Integer
data(0) = 34.46
data(1) = 56.78
data(2) = 68.89
data(3) = 45.22
For i = 0 To 3
Winsock1.SendData data(i)
Next
{®Gá:A@¤p=
×cL@)\�Âõ8Q@\�Âõ(�
This what i'm getting in my example vi.
0 Kudos
Message 10 of 11
(5,222 Views)