LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I send data in this format over the Network?

Total Size of Packet : 268 bytes
First 68 Bytes (Index 0 to 67): Header
            byte[0] = 70;
            byte[1] = 108;
            byte[2] = 111;
            byte[3] = 97;
            byte[4] = 116;
            byte[5] = 53;
            byte[6] = 48;    ( byte[7] to byte[66] are zeros )
            byte[67] = 200;
Rest of the 200 Bytes: 50 floats ("single" data type in LabView), each consisting of 4-bytes, in Big-Endian network byte order
First Number
            byte[68] =
            byte[69] =
            byte[70] =
            byte[71] =
Second Number
            byte[72] =
            byte[73] =
            byte[74] =
            byte[75] =
(...and so on)
 

This data is to be send using UDP. How do I convert single precision date into 4 bytes data?
0 Kudos
Message 1 of 7
(4,701 Views)

The flatten to string function will convert a floating point value into bytes. Another function will convert the resulting string into an array of U8s if that is what you desire.

 

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 7
(4,697 Views)

UDP accepts strings, so flattening to a string is all you need.

 

What's on the receiving end that will unflatten the data back to numeric type? If it's not LabVIEW, you might need to worry about byte order.

 

There are many ways to do this, here's one possible code fragment to form the binary string. (Of course the byte order does not matter for the U8 part ;))

 

"Reshape array" pads the U8 array to the desired lenght. If this is always fixed, you could replace the upper string with a string diagram constant.

 

Message Edited by altenbach on 01-01-2009 01:54 PM
Message 3 of 7
(4,676 Views)

Thanks a lot for the reply . One more question. If I send a single precision number to flatten to string, how many bytes would it occupy? The receiver is expecting foure bytes per each single data item. How can I make sure that each single is being converted exactly into four bytes. I am attaching the (yet incomplete) VI. Actually there is a flight simulator written in a dot net language (and I don't have the source code for it). It is expecting data via UDP for operating (as mentioned above). Could you be kind enough to look into it.I am also attaching the readme doc which explains the requirements for the LabVIEW portion. I'll be most indebted if you could help me.

Is there a way to find out how many bytes a data item occupy (in LabVIEW).

 

Thanks a lot for your time!

Have a very pleasant day!

Download All
0 Kudos
Message 4 of 7
(4,642 Views)

Wow! Thanks ! That was real help. I have attached the requirements doc in a reply post to mikeporter. Would be kind enough to look into it. I'll be soooo grateful.

 

Thanks for being so nice and helpful!

0 Kudos
Message 5 of 7
(4,640 Views)

C .DOT wrote:

Would be kind enough to look into it.


The document is a bit "sparse". 🙂

 

The first 68 bytes is easy, because we can simply do it as a string diagram constant. The rest is unclear, because the specifications call for 50 SGL numbers in big endian format, while the "Sequence of dat' Part talks about 13 numbers. Are these supposed to map into the 50 SGLs somehow?

 

Lets assume that these are the first 13 SGLs (two seem to be booleans, so we need to convert to 0,1 SGL). Since you need big-endian, we can get away with typecast for the SGL array.

 

Here's a draft for the formatting.  I assume that sending these packets is a repetitive process, so you should place this in a while loop, open and close the UDP connection outside the loop, and simply keep writing in the same connection inside the loop at a predefined interval or whenever the values change.

 

 

 

Message Edited by altenbach on 01-02-2009 10:50 AM
Download All
Message 6 of 7
(4,612 Views)
Thanks a lot ! for the help.
0 Kudos
Message 7 of 7
(4,560 Views)