07-21-2017 02:57 AM - edited 07-21-2017 02:59 AM
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
07-21-2017 03:20 AM - edited 07-21-2017 03:20 AM
07-21-2017 03:30 AM - edited 07-21-2017 03:32 AM
Thanks!
I had an error in my thinking because of the further functionality. Dumb question 🙂
07-21-2017 04:04 AM
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.
07-21-2017 06:59 AM
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!
07-21-2017 07:04 AM
Use a cluster and then use Unbundle By Name to get the exact values you want and Bundle By Name to update them.
07-21-2017 08:26 AM
@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.
07-21-2017 08:36 AM
@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.