LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to create a circular buffer using the INSERT ARRAY function?

I saw the example using the REPLACE ARRAY function, but it uses too much CPU power on my laptop. I'm using it for a very sensitive application and saw that the INSERT ARRAY function used much less CPU power.

I am also not wiring the index on the INSERT ARRAY function so that whatever is read from the buffer is added to the array.

However, since it is not indexed, I don't know how to set the "write" index back to 0 when it reaches a certain sized array (ie 1000 elements). I was looking for an array property node, but couldn't figure out if one exists for the "current write index".

Can anyone help?
Thanks
0 Kudos
Message 1 of 2
(2,697 Views)
I will try to answer this question to my best understanding. I apologize if I interpreted the question wrong.

You are using the "Insert Array" vi without wiring the index. By doing that, new elements will be added (appended) to the array.

If you just want to know the current index to stop your acquisition when the array reach certain amount of elements, then you can use the "Array Size" vi to keep track of the size of the growing array. Remember that Array Size = last index + 1 because the index start at zero.

A second option is that you may want to start over the array when it hits the maximum number of elements that you will allow. If that's the case, then you may want to re-initialize the array to a NULL state by stablishing a condition (for example, when the
size of the array is 1000, re-initialize). I provided an example attached to this message showing how this can be accomplished. In the example, an 1D array grows in size using the "Insert Array" vi and inserting a random number. When the array reach 4 elements, it is re-initialized. You can expand this example by saving the array first to a file or some other holder before re-initializing the array. The example is in LabVIEW 6.

Finally, if you want to replace the current values with new values, I think you do not have other choice but to use the "Replace Array" vi.

Hope this can be of help.

Regards;
Enrique Vargas
www.vartortech.com
0 Kudos
Message 2 of 2
(2,697 Views)