LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting different types of data to ONE byte array

Hello,

 

i have a quick question about labview.

for example if i have a bunch of variables like

 

bool bVar1

int iVar2

dint dVar3

string Var4

 

and i want to have this data in ONE BYTE array (input rule for an external function)

how can i solve this?

thanks in advance

0 Kudos
Message 1 of 8
(4,374 Views)

Hi stef,

 

how should fit all those variables into just ONE byte?

 

If you want a byte array containing all those data you could typecast each value:

check.png

(There might be different definitions of a "bool" so please check them…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(4,356 Views)

Thanks!

I had an error in my thinking because of the further functionality. Dumb question 🙂

 

0 Kudos
Message 3 of 8
(4,350 Views)

I prefer to use Flatten Into String since it allows me to set the endianness of the data.  From there, Cancatinate​ String and String To Byte Array.  The String To Byte Array often is not needed since most of the communication methods (VISA, TCP, UDP, etc) use the string.



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 4 of 8
(4,340 Views)

Hm my problem is the following:

 

data:

int iVar1

string Var2

(many)

 

function wants to have an array (bool, byte, int, string, ...) as input AND output (same variables)

 

i thought the best way would be to put them all in an array of the same type, send it to the function and when i read through the function

i have to split them up again

 

any suggestions maybe?

 

thanks!

 

 

 

0 Kudos
Message 5 of 8
(4,318 Views)

Use a cluster and then use Unbundle By Name to get the exact values you want and Bundle By Name to update them.



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 6 of 8
(4,316 Views)

@crossrulz wrote:

I prefer to use Flatten Into String since it allows me to set the endianness of the data.  From there, Cancatinate​ String and String To Byte Array.  The String To Byte Array often is not needed since most of the communication methods (VISA, TCP, UDP, etc) use the string.


I recently ran into this "endian" issue and I swear to whatever deity will listen to me at the moment, I remembered crossrulz saying that he preferred to use "flatten to string" to control the endian-ness of the data.  Problem solved.  Of course, I had to re-convert to byte array (because the communications VIs were expecting byte arrays), but it was simpler than trying to follow the code around to see where it was broken and replace all those "build array" nodes with "concatenate string" nodes.  I normally don't like to add "extra" code, but in this case, I felt the trade-off was in my favor.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 8
(4,299 Views)

@billko wrote:

I normally don't like to add "extra" code, but in this case, I felt the trade-off was in my favor.


Well, if you had the endianness issue and you kept with the original byte array, you would need to add some interesting index and build array code to rearrange the bytes.  That is a lot more difficult than adding a simple String To Byte Array (Quick Drop makes it even easier).  And the Byte Array To String and String To Byte Array functions are actually noops in the compiled code (strings and array of bytes have the exact same data format).

 


@billko wrote:

I remembered crossrulz saying that he preferred to use "flatten to string" to control the endian-ness of the data.  Problem solved.


Glad to see I instilled some sanity into the world.  I know I have contributed lots more to the contrary.



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 8 of 8
(4,296 Views)