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: 

Local variables in state machines

Hallo community,

my major pattern for the vast majority of LV applications is the
statemachine, consisting of While loop with Case-structure. All variables
(or properties to speak OO-oriented) that are local to that statemachine
are realized via cluster which is shifted from one while iteration to the
next. I think you imagine how it looks like.
Now, I've come across the idea to realize my statemachine locals with real
controls and locals instead of my cluster and shift register thing. Either
I bundle all variables in a cluster that I access via read locals and write
locals or I have a separate control for each of my variables accessing via
locals.

What do you think of that? What's the best solution in terms of
performance, memory, readability of code, data flow aspects.

I'm looking forward to the hopefully upcoming discussion 😉

Best regards

Oliver Friedrich
0 Kudos
Message 1 of 4
(2,754 Views)
I think you will find that the shift register outperforms locals on all the criteria you listed: performance (wires are always faster), memory (local make copies, I think), readability of code, data flow (locals completely break dataflow) aspects. One way to enhance the readability of the cluster in the shift register is to create a control/indicator on the front panel and then use bundle/unbundle by name. I have done this on several projects over the past few years. The cluster control can be hidden if there is no need for it to be seen on the front panel.

Lynn
Message 2 of 4
(2,746 Views)
I would also strongly encourage the use of the bundle/unbundle by name functions to improve the readability of the code, more especially as it is not necessary to create a control/indicator.
 
1) Right click on an element in a constant of the cluster
2) Make its label visible
3) Type a label
4) Repeat for every element
0 Kudos
Message 3 of 4
(2,720 Views)
Thanks JB. I have done that to label each element of a cluster but forgot. In my applications the indicator is usually used.

Lynn
0 Kudos
Message 4 of 4
(2,715 Views)