02-20-2013 10:22 AM - edited 02-20-2013 10:24 AM
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
02-20-2013 10:34 AM
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...
02-20-2013 11:12 AM - edited 02-20-2013 11:17 AM
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.
02-20-2013 11:17 AM
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.
02-20-2013 12:55 PM
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.
02-20-2013 01:00 PM
This works, it's not clean, but I suppose this is all I have with Labview 😃
02-20-2013 02:27 PM
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.
02-20-2013 02:36 PM
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.