02-05-2008 04:55 AM
02-05-2008 05:05 AM
02-05-2008 05:34 AM
02-06-2008 11:14 AM
In your case, a shift register is more suitable. However, local variables do definitely have their uses.
"Use local variables to access front panel objects from more than one location in a single VI and pass data between block diagram nodes that you cannot connect with a wire.
With a local variable, you can write to or read from a control or indicator on the front panel. Writing to a local variable is similar to passing data to any other terminal. However, with a local variable you can write to it even if it is a control or read from it even if it is an indicator. In effect, with a local variable, you can access a front panel object as both an input and an output."
02-06-2008 09:48 PM
02-07-2008 12:13 AM - edited 02-07-2008 12:14 AM
wuliao23 wrote:
in the program, it have a case structure inside a while loop, which is true at the initial of the program, and i need to make this case become false at the next loop..
wuliao23 wrote:
which 1 have the shorten loop time??and more consistent in loop??
02-07-2008 03:40 AM
05-04-2021 03:02 PM
I agree with TMC-NI, both local variables and shift registers each have useful function. It's not always appropriate to constrain yourself to a shift register, especially if that means you'll need more than one or two. That approach could lead to unnecessary wiring complexity that can inhibit debugging and maintenance. On the other hand, local variables do incur some overhead in terms of speed and storage. But modern PCs have so much performance this is seldom a serious problem (going RT on a micro controller is a counter example.). As TMC-NI mentions, local variables offer a level of flexibility and scope that shift registers do not and I agree with that also.
05-04-2021 03:50 PM
@pbisson wrote:
It's not always appropriate to constrain yourself to a shift register, especially if that means you'll need more than one or two. That approach could lead to unnecessary wiring complexity that can inhibit debugging and maintenance.
You should try using a cluster in a single shift register. As many data items as needed with only one wire.
05-04-2021 04:44 PM
Yes, clusters are useful. But I'm doing maintenance on an app (which I didn't write) with half a dozen different shift registers. There's a UI event handler too and about a dozen events handled. The code is absolutely un-readable with all those through lines for the various events. Many of the shift registers deal with variables irrelevant to a particular event, so they're just wired through. What a mess.
Consolidating literally scores of data items into a single cluster is probably also not good practice. Plus, you've also got to un-bundle and re-bundle them at the point of use. This burns up lots of block diagram space.
Just bear in mind, a local variable is actually just a pointer to the original storage location (the control), so it's really only just a 32/64-bit address. In the case just described, using a few local variables, judiciously, really cleans up the block diagram and makes the code much easier to read, understand, and maintain. If there's a small storage and cpu-clicks penalty, I'll take it gladly.