LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert datatypes in byte array?

Hi, I have a question. I'm trying find a clean way to insert various datatypes (ie. U16,U32.etc...) into a U8 byte array at various locations in an array without having to use the replace subset array control which forces you to split datatypes to load each element. There should be a way to use the typecasting method like in the attached example and just overlay the datatype at a desired location in an array I would assume. The attached example shows the typecasted U16, but the replace subset array only allows one element change. Can someone point me in the right direction?

 

Tnx

0 Kudos
Message 1 of 8
(3,257 Views)

Hi QRP,

 

- you should typecast to an array of U8 when you want to have such data (right now you typecast to U16 array as seen by the coercion dot...)

- you can also typecast U16 arrays to U8 arrays, so there is no limit in the number of elements...

- ReplaceArraySubset allows one or more elements of an array to be replaced. It's only limited as it cannot replace non-existing elements...

Best regards,
GerdW


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

Yes, I relize that, but that doesn't answer my question 😃 I want to place for example a U16 into an 8-byte array at a given location without having to split the datatype into bytes to insert them. There has to be a way to overlay any datatype into a byte array at a given index. In C it's a piece of cake, but in Labview it's matter of finding the right control to accomplish the task and that is what I'm looking for.

btw, the U8 byte array must stay a U8 type.

 

Tnx.

0 Kudos
Message 3 of 8
(3,146 Views)

How would you do this in C?  The only way I can think of requires using pointers and can be very dangerous.

 

You are essentially doing the same thing in LabVIEW.  You are replacing parts of the array with the U16.  But you have to define the U16 as a byte array first.


GCentral
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 4 of 8
(3,140 Views)

We'll I'd use a memcpy in C for starters. It's pretty dumb you can't do this simple task with such an expensive application, but oh well, that's just the way it is. I'll just split the datatypes into bytes and load them manually since that works. I have to maintain a strict U8 byte array, so I can't just change this pre the datatype I need to insert into it.

 

0 Kudos
Message 5 of 8
(3,124 Views)

This works, it's not clean, but I suppose this is all I have with Labview 😃

0 Kudos
Message 6 of 8
(3,122 Views)

What is so "unclean" about it?  You have to have the same data types.

 

The problem in C is that you are manipulating memory locations and not caring about what the data type really is.  LabVIEW doesn't work that way.  It is a higher level language.  With that, you lose some of the ultra low level control.  But for 99.999% of the cases, you don't care.


GCentral
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 7 of 8
(3,102 Views)

Yeah I agree. The problem is, I've been in the C world too long and switching to Labview has taken a while to get use to.

 

 

0 Kudos
Message 8 of 8
(3,096 Views)