LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert byte array to specific data type

Hi there

 

I have a strong from TCP port being read, which I'm converting to a byte array. Now this byte array has various types of data in it. I need to convert specific bytes to different data types. For eg.

4 bytes to unsigned INT

8 bytes to float 

8 bytes to unsigned long long etc.

 

Can someone please help me with the unpacking of the bytes.

 

Shall be highly grateful

 

Thanks 

0 Kudos
Message 11 of 21
(3,166 Views)

This message is a year and a half old.  You probably should have started a new thread.

 

What is "a strong"?  Maybe you meant "string"?

 

Did you try following the advice of earlier messages in this thread to use the Typecast function?

 

If you need more specific help, then you should attach a VI with the string saved as a constant, and the list of data types you need.

0 Kudos
Message 12 of 21
(3,161 Views)

We would also need to know the specific format/protocol for the data your are receiving. It is defined somewhere. Without that are advice would be very general.



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 13 of 21
(3,153 Views)

I recommend using Unflatten From String to decode your data.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 14 of 21
(3,146 Views)

Hi Mark

 

Thank you for your revert. It's a huge data packet wherein the data type varies depending on the packet type and hence needs to be unpacked accordingly. For now I just need to know if I have a 8 bytes of UINT (an array) , how do I convert that to a double value?

0 Kudos
Message 15 of 21
(3,133 Views)

Hi

Thank you so much for your revert. Yes that's a typo. I meant "string". My bad. 

I'm aware of the type cast function, just that not too sure of how to use in this case. Could you please help me with an example? 

I have 8 bytes of UINT byte array which I need to convert into a double float.

 

0 Kudos
Message 16 of 21
(3,137 Views)

Hi crossrulz

Thank you for your revert. Since it's a large chunk of data, I'm not too sure how would un flatten from string be helpful. I converted the string to an UINT byte array so that I can parse the bytes (different types and lengths of packets) and unpack them accordingly. Could you please help me out with this?

 

Thanks a ton!

0 Kudos
Message 17 of 21
(3,136 Views)

Hi sakshi,

 

typecast or Deserialize your 8 U8 bytes:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 18 of 21
(3,125 Views)

What the heck is a "revert"?

0 Kudos
Message 19 of 21
(3,115 Views)

@sakshi14 wrote:  Since it's a large chunk of data, I'm not too sure how would un flatten from string be helpful.

You can do all of the conversion with just one call by unflattening a cluster.  I also prefer to use the Unflatten From String since it has an option for Endianness (how the bytes are arranged in a multi-byte data type).



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 20 of 21
(3,095 Views)