User | Kudos |
---|---|
10 | |
3 | |
2 | |
2 | |
2 |
Labview has a way of creating the equivalent of static variables in a VI similar to static variables in OO languages or function-scoped static variables in C. This way is through the use of uninitialized shift-registers in single-iteration loops (i.e dummy loops).
If multiple instances of a VI is created and the VI contains such a static variable, the value of the static variable persists from one instance to the next. I can see why this is useful, but I think it would also be useful if there was an option to make static variables of different instances of a VI separate.
Static variables are primarily useful for VIs that have some concept of state and you don't want to explicitly create a state variable or cluster that the user has to manually feedback with outside signals. For example, if you created a VI for a PID controller or a state machine, and you wanted to use an uninitialized shift register to store that state, you can not create multiple instances of that VI with out having the two instances intefere with each other. The two instances cannot maintain independent state.
I ran into this problem while creating a VI to implement a moving window of values. (as a side not, it would be useful to have a moving window VI)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.