LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get values out of stacked sequence?

 


@kristofparedis wrote:
I used For loops, but they don't give out their values until finished, so they didn't allow real time plotting unless you use a local, but your way makes the for loop disappear (why do they even exist, same with sequences???)

 

A FOR loop is one of the classic structures that has equivalent constructs in all serious programming languages. A FOR loop is used when you know the number of iterations before the loop starts. This allows efficient code, because the compiler can optimize things and you don't need to constantly check for termination conditions as in a while loop. Autoindexing output arrays can be allocated in one simple swoop because the size is know. In a while loop, this is not possible.

Many times a FOR loop does not need to update the front panel with every iteration. It would only slow down the code. Often only the end result is needed (e.g. if you need to calculate a million prime numbers).

Your update problem has nothing to do with the FOR loop, it is a result of dataflow. If you need to update an indicator with every iteration of the loop, you simply place the indicator terminal inside the loop. Simple as that! 😄

 

The existence of sequence structures is more tricky to explain because linear text programs don't need them. In LabVIEW, execution order is primarily defined by dataflow and data dependency. However, LabVIEW is inherently parallel so many things can execute at once (e.g. on a multicore CPU) and for any code parts, the compiler can arrange and schedule things to most efficiently to take advantage of it. Sequence structures are needed in the rare cases where you want to enforce an certain execution order for some good reason or where dataflow is not sufficient to control order (and order is actually important!). This can have legitimate reasons, but for most beginner codes it is due the overuse of local variables. Since local variables break data dependency, misuse of local variables leads to race conditions that need to be "fixed" by using sequence structures. In this case, the compiler not only need to create additional data copies in memory, it also no longer can efficiently utilize all computing resources, because all code is serialized and can no longer utilize multiple cores. Before placing a sequence structure, think long and hard if it is actually needed. Often execution order outside of dataflow is not important if everything is programmed correctly.

0 Kudos
Message 31 of 35
(850 Views)

 

 I agree, placing the indicator inside the for loop would give an output for every iteration, but what if your data comes from different for loops? But this inherent to labview i guess, because releasing the values after each iteration breaks the data flow ...

 

anyway, I now know how to circumvent this, thanks to you all !

 

0 Kudos
Message 32 of 35
(844 Views)

Now look back at your first posted example and see how much you've learned in a short time. I'm sure you agree that your current program is alot easier to read, understand and maintain. 🙂

 

Thanks for being a good listener.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 33 of 35
(839 Views)

 


@kristofparedis wrote:

 

 I agree, placing the indicator inside the for loop would give an output for every iteration, but what if your data comes from different for loops? But this inherent to labview i guess, because releasing the values after each iteration breaks the data flow ...


Actually, no, it's not inherent to LabVIEW. You could just as easily have a program written in a text-based program that's running two threads in which each thread has a for-loop, and one for-loop uses data that the other for-loop generates. How is this problem solved? Depends on what's available in the programming language. You could use global variables, static variables, queues, etc. This question has come up many times, and there have been several recent threads on just this topic.

 

0 Kudos
Message 34 of 35
(820 Views)

 


@kristofparedis wrote:

 

 I agree, placing the indicator inside the for loop would give an output for every iteration, but what if your data comes from different for loops? But this inherent to labview i guess, because releasing the values after each iteration breaks the data flow ...


Two words: "Action Engine". 😄

 

0 Kudos
Message 35 of 35
(813 Views)