From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to insert cluster in to array element

Hi, I have an experiment which need macro data to be saved and I am currently trying to store all this in a cluster which itself will contain clusters and arrays. I have an array of clusters with in a cluster and i want to update the cluster. the code below shows how i do that. basically i pick out the array, index it to get a ref to the cluster, write values and then insert cluster back to the array index. but it doesn't work. Its such a simple problem I'm a little stumped. Any feedback would be great. 

 

thanks 

 

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
Download All
0 Kudos
Message 1 of 32
(4,366 Views)

There's missing typedefs. Do Save As -> duplicate hierarchy and upload a zip of that folder instead.

0 Kudos
Message 2 of 32
(4,351 Views)

You can only replace elements if they exist. That is, if the element you are replacing is empty, it will still be empty after you use the replace function. Try initializing your array first.

 

Also, no need to unbundle the items in your cluster that are not being used/modified.

0 Kudos
Message 3 of 32
(4,348 Views)

Hi Stephen,

 

after getting rid of all those missing typedefinitions I could run your VI and it worked as expected (I think so)…

but it doesn't work. Any feedback would be great. 

Well, saying "it does not work" is a bad error description. It's a very bad description. Enough feedback? 😄

i pick out the array, index it to get a ref to the cluster, write values and then insert cluster back to the array index.

Does the element you want to index even exist? You cannot replace non-existing array elements!

Best regards,
GerdW


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

To edit an existing array element, you need to put it back using "replace array subset". You are using "insert into array, which would grow the array by one element, leaving the old data intact.

 

Have a look at the "in place element structure", it can simplify some of your code.

 

(there is no need to attach the typedef, we can just disconnect from it).

0 Kudos
Message 5 of 32
(4,334 Views)

By doesn't work I mean that the element that i wish to be inserted into the index does not go. Also the array element may be both populated and not. I need to write it the first time but then may need to update it in the future. 

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
0 Kudos
Message 6 of 32
(4,267 Views)

The program worked when the index is 0 but then when i increase it to 1 or higher the element in index 0 will revert to default and so is the element in the index i selected. I need this aray to be 4 element in length and then write to each element depending on what experiment has been run. 

 

Regarding initialising the array how would i do this? The array is part of a type def cluster and so I dont know were I would use the initialise array function. 

 

also I have attached the vi where the type defs shoudl work. 

 

Thanks 

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
0 Kudos
Message 7 of 32
(4,262 Views)

Hi Stephen,

Regarding initialising the array how would i do this?

You use InitArray to create an array of 4 ("inner") clusters. Then you use BundleByName to write this array into your main/"outer" cluster…

 

Best regards,
GerdW


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

When I use the replace array subset this doesn't work either. I will look into the in place elemnet structure you suggested though but I've never come across this so it is all new to me. 

 

thanks 

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
0 Kudos
Message 9 of 32
(4,255 Views)

Okay, I'm not understanding this. I have already initialised the array in the the type def when I made it, haven't I?  

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
0 Kudos
Message 10 of 32
(4,252 Views)