05-01-2019 09:46 AM
Hello all,
Is it wise to use multiple local variables of a control in the read mode to remove unnecessary wiring on the block diagram and make it more readable.
In my experience when making large VIs, even after making necessary SubVIs, the wiring makes the block diagram difficult to read and interpret. By using local variables, I clear up the clutter and make block diagram more readable.
But is it wise to do so?
Thanks
Solved! Go to Solution.
05-01-2019 10:04 AM
Local variables are dangerous when you are reading and writing to them in multiple places. The WORM method, write once read many is not dangerous.
However, local variables make COPIES of your data, if you are using them for large arrays, it may run into memory problems.
To avoid local the wire mess, I typically bundle everything into a giant cluster to pass around a loop, and use unbundle by name to access the variables I want.
mcduff
05-01-2019 10:05 AM
No. It is not wise. It may not cause a problem. Or it may when you started modifying the code further and you introduce a race condition you can't see.
If you are still having issues reading your VI's even after making the necessary subVI's, then you haven't gone far enough with the cleanup, or way you've structured your VI's doesn't align well with what you are trying to do.
05-01-2019 10:06 AM - edited 05-01-2019 10:09 AM
This really depends on the context.
I have sometimes seen it used to share a constant (such as a selected value from an enum, selected before running) with several places in the block diagram. Its quite self documenting in this context, and because the data won't change, there is zero chance of a race condition.
I generally don't do it myself, but it doesn't annoy me.
Anywhere that the control contains lots of data, you are best to use a wire.
Anywhere you expect the data to change, using the wire will avoid possible race conditions.
0xDEAD
05-01-2019 10:27 AM
@gkartik wrote:Is it wise to use multiple local variables of a control in the read mode to remove unnecessary wiring on the block diagram and make it more readable.
It is wise to use wires to remove unnecessary local variables to make the diagram more readable.
Only with wires you are sure where the data is coming from, where it got modified last, what other parts depend on the data, and where the data is going. All that information is lost with local variables, making the diagram significantly more confusing and harder to follow.
@gkartik wrote:In my experience when making large VIs, even after making necessary SubVIs, the wiring makes the block diagram difficult to read and interpret. By using local variables, I clear up the clutter and make block diagram more readable.
Overuse of local variables cause significantly more clutter than wires. There are plenty of coding techniques that are much better and maybe you have not found them yet. Feel free to show us some of your code so we can possibly make suggestions.
Local variables are most useful for things involving the UI. They have no purpose in pure computations.
05-01-2019 10:33 AM
"local variables make COPIES of your data"
Oh! Is it?? Why LabVIEW does that?
Instead, it can just point to the address of the variable and read it.
05-01-2019 10:42 AM - edited 05-01-2019 11:04 AM
Well here is my VI, after using local variables. As you can see I have already used many SubVI wherever possible. With the use of local variables I don't have to back trace the wire to see where it is coming from, so it makes the VI more readable.
05-01-2019 10:54 AM
I am hoping the Sir CA can work his postage stamp magic, ie, reduce that diagram down to a postage stamp size.
You can use queues, notifiers, user events, to share data among loops, although each loop will have a copy of the data.
I can not look at it in depth at the moment due to a plethora of meetings.
mcduff
05-01-2019 10:57 AM
Unfortunately, the forum does "pre-processing" of pictures before displaying them, so your snippet won't work. You'll have to upload the snippet as a file. I'm already afraid of what I'm seeing though. You know that LabVIEW doesn't really flow left to right; it just appears that way because you connect the nodes together from left to right - usually. That being said, the "floating code" that you have in there can execute at any time it feels, and if you have locals attached to it, you may or may not be operating with stale data.
05-01-2019 11:00 AM
"local variables make COPIES of your data"
Oh! Is it?? Why LabVIEW does that?
Instead, it can just point to the address of the variable and read it
LabVIEW is a dataflow language. Unlike many text based programming languages data flows from source to sink along wires. It is possible to create a Data Value Reference that does point to a memory location but, that is merely a "Hack" around understanding and using dataflow and its advantages.
Looking at your vi, There is no data dependency between where you calculate" lo pt" and when you read the value via any of the 8 different local variables. So, the calculation and the 8 reads can happen in any order! Imagine, 4 reads of stale data, a write to the indicator and 4 reads of new data! as an example! without dataflow the values read are unknowable. This is an unwise use of local variables!