07-15-2009 09:17 AM
I’m having a very confusing problem with populating an array of cluster strict type defs. Attached is an example VI with the necessary ctls. The shift register has to be un-initialized. This entire VI will later be used as a sub-VI within a while loop of a main VI. Since this VI is called over and over again with the while loop, I had to include the single step for loop to create the shift register. I want the shift register to (on the first loop of the while loop) initialize the array type with the default values. Any subsequent while loop frame, the shift register should output the updated array from the last frame. This method has worked fine for many other occasions in my code. The problem seems to be with the replace element in array function.
I created another VI that shows that the replace element in array with a cluster type does work… but the architecture wasn’t correct for my application. For some reason it doesn’t work here!
Help please!
07-15-2009 09:24 AM
07-15-2009 09:30 AM
You start out with an empty array, so nothing can be replaced, of course. You cannot replace an nonexisting element! What is the correct array size?
You have several options:
07-15-2009 09:47 AM
I agree with what you said... However... My understanding of how an uninitialized shift register works is that it sets the values of the type to the type's default values. I believe in the example I sent you I had set the defaults values of the array control type for the first 7 elements to some numerical value, made current values default, and then saved and applied changes. Therefore, the arrayOfClusters type, in my opinion, should NOT be an empty array in the first executing of the loop using the shift register. I have attached my example again with the array populated in the control type.
the first seven elements are populated and then the 256th index of the array have -1 as the value of the numerics.
Obviously... This doesn't work. Is it then safe to assume that the shift register does not initialize the array to it's default value (populated)?
Thanks for everyone's input on this. I plan on using the approach of using the First Time block (against my will).
07-15-2009 09:57 AM
PhilipJoeP wrote:I agree with what you said... However... My understanding of how an uninitialized shift register works is that it sets the values of the type to the type's default values.
Don't really know where you got this understanding, as that's not how it works. There's a difference between type and value. The type is a 1D array of clusters. The value is empty. Because it's uninitialized. Don't believe me? Place an indicator inside the for-loop to the left of the case structure. What's the value of the array of clusters?
07-15-2009 10:02 AM
07-15-2009 10:32 AM
You'd get zero. Why doesn't it make sense? You're not understanding the use of typedefs and shift registers. The shift register is picking up the datatype based on the fact that you have a Replace Array Subset and that you're wiring a cluster of 2 elements into the element input of that function. Where does the array typedef come into this? Nowhere, so why would there be any connection between the typedef (regardless of whether you set default values), and the shift register.
Now, if you had created a constant (i.e., a value) from the typedef (which had default values) and wired that to initialize the shift register, then you'd get a shift register populated with data.
07-15-2009 10:33 AM
In my case... my data type is an array (arrayOfCluster.ctl). When I created that strict type def... I populated a number of elements in that array and then made those values defaults in that type def. When you open up the arrayoclsuter.vi... the indicator shows that the array data type is populated. BUT as soon as you press RUN, the array is emptied. Similarly... in the attached example... if I created my own numeric control type def _custome_numeric.ctl), set the type defs default value to 111, and use that in the example... the shift register sets the value to zero instead of the default data type value of 111. It seems that you cannot use a strict type def with a shift register.
This seems to be inconsistent with what the help documentation explains. Right? Throw me a bone here!
07-15-2009 10:41 AM
07-15-2009 11:00 AM
To be perfectly blunt, I'm not the one who's not understanding here.
While the help could be a little clearer, it's not inconsistent. Let's try this a different way. Do the following exercise: