LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting string to array

Hi,
I am receiving a string over UDP that is a 50x100 array, well its a more like one long long line over 20000 in length. The problem I'm having is that I need to convert this string to an array of doubles. How can I do that? So bottom line is that it's an array of doubles on the C++ side then its packed into a buffer..sent across and received as one long string. So is there any way of quicly converting the string to an array of doubles WITHOUT having to decode it with the use of 2 for loops,
Thanks any help will be appreciated,
Alex
0 Kudos
Message 1 of 5
(3,604 Views)
> I am receiving a string over UDP that is a 50x100 array, well its a
> more like one long long line over 20000 in length. The problem I'm
> having is that I need to convert this string to an array of doubles.
> How can I do that? So bottom line is that it's an array of doubles on
> the C++ side then its packed into a buffer..sent across and received
> as one long string. So is there any way of quicly converting the
> string to an array of doubles WITHOUT having to decode it with the use
> of 2 for loops,

You are likely looking for the typecast node. Given a string buffer,
you can typecast it to a 2D array of doubles in this case. Since LV
needs to know the size of the array, you likely need to prepend the
sizes, 50x100 to the front of the string.

The sec
ond thing you need to keep in mind is that the standard format
for LV is big endian. If you are doing this on an Intel machine, thent
he C++ object likely wrote things out in little-endian format. That
means that in LV you will need to reverse the bytes in each eight byte
double to get it into big-endian format.

Greg McKaskle
0 Kudos
Message 2 of 5
(3,602 Views)
Thank you for that answer, can you please explain in a bit more detail as to what you mean by prepending the sizes 50x100 to the front of the string? And how it would be used in the typecast node?
Thanks
0 Kudos
Message 3 of 5
(3,602 Views)
I don't know if you have control over the C++ side, but you could always use DataSocket which takes care of the conversion for you. You could use it in C++ and LabVIEW if you have Measurement Studio.
J.R. Allen
0 Kudos
Message 4 of 5
(3,602 Views)
> Thank you for that answer, can you please explain in a bit more detail
> as to what you mean by prepending the sizes 50x100 to the front of the
> string? And how it would be used in the typecast node?

My assumption was that the flat binary string contains the bytes of the
doubles. You know the size is 50x100, but is that because it is a
constant size? Or are the dimension sizes written down?

Users often do the same sort of binary to string coversion within LV,
ship the string somewhere else in LV via UDP, serial, GPIB, or file I/O,
then unflatten the data back to the binary format. So, if your binary
encoding matches what LV expects, you can just use the typecase or the
unflatten from string to do the same to this buffer.

You migh
t play around with this a bit, making various 2D arrays,
flattening them to string, then displaying in a HEX string to see what
LV's format is. What you will find is that is is the dimension sizes,
using an int32 for each, followed by the data bytes in big-endian
format, with no additional alignment.

So what I meant was to take the binary string you received via UDP, use
the string concatonate node to add eight bytes to the front that
represent the sizes, if they aren't already there, and then rearrange
the bytes to be big-endian if they aren't already.

Greg McKaskle
0 Kudos
Message 5 of 5
(3,602 Views)