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: 

Add element from for-loop to array after every Wait time

I need help with adding an element into a 1-D array from within a for-loop which has a Wait timer. Please refer to my front panel and block diagram for clarity. Also attached is my VI.

 

The above works and outputs into the array with no issue without the timer. However, after addition of the delay timer, the array is empty always. I'm sure I'm missing something but I can't figure it out myself. What I'm after is for elements to get appended into the output array whereby each iteration is timed by the delay timer and elements get added into its respective index location.

 

Thanks in advance

0 Kudos
Message 1 of 7
(2,537 Views)

Worked perfectly for me.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(2,522 Views)

It might take a long time (or forever) for the loop to finish (depending on the number of iterations and the wait). With your particular inputs, it will take 21 seconds. Did you really wait that long?

 

Dataflow dictates that the output in the loop is only available after the loop has completed. Seems obvious. If you want to see the array building during the loop, you need to append the new data inside the loop using  "built array" and a shift register.

 

What is the point of the delay inside the loop? The only indicator you have is TIMER" which displays a completely arbitrary and useless tick count. What do you expect to see there? (If you would use a suitable integer format and make the indicator wide enough, you'll actually see that it increments by about 1000 for each iteration. With your current width and DBL format, the display appears invariant to the eye. Both displays are useless, but with one you actually see activity 🐵

 

If you don't want the delay to be changed arbitrarily by the user while the loop is running, place the "delay" control before the loop. Also, that control should be U32. Did you notice the coercion dot?

 

Of course we also have this function. Might be simpler. 😉

0 Kudos
Message 3 of 7
(2,471 Views)

The time indicator is just an arbitrary one I added in to see if the timer works, I don't intend to keep it.

 

Anyway, I tried your suggestions on using Ramp Function (Delta) and placing the indicator (array) inside the for-loop with a Build Array (concatenate inputs selected) before it. It does work, however it only displays array elements is full after the loop has ended. I intended for the elements to appear one by one with each "tick" of the timer.

 

How should I incorporate the shift registers with Build Array and output array?

 

Thanks for the help too, greatly appreciate it as a first-day user!

0 Kudos
Message 4 of 7
(2,403 Views)

Hi nukeboy,

 

THINK DATAFLOW!

 

- when you want to build an array inside the loop, then you need to build the array inside the loop: use a shift register and a BuildArray node

- when you want to display the (growing) array inside the loop then the indicator must be placed inside the loop

 

General hint: When you got problems with your VI it most often helps to attach that VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(2,398 Views)

Thanks for the tip

 

I managed to incorporate shift registers and went back to my original VI. Now it works as I intended and it shows elements one at a time each tick.

 

Thanks all for the suggestions

0 Kudos
Message 6 of 7
(2,393 Views)

@nukeboy wrote:

I managed to incorporate shift registers and went back to my original VI. Now it works as I intended and it shows elements one at a time each tick.


You still should show us your creation so we can give further advice. You probably don't need any shift registers. You can just form the ramp once then display subsets of incremental size as follows. It won't look any different to the user!

 

bydelta.png

 

Remember to use the correct representation for all inputs.

0 Kudos
Message 7 of 7
(2,364 Views)