LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wiring Data in a State Machine

I have a state machine with about 20 cases all handling different user interactions and all completely independent of one another. That is, what one case does has nothing to do with what another does (for most of them anyway). They just execute one case and then go back to the default case. Some of them though do require data to be passed out of one case so that it can be read in another (actually not the data but just the data structure to be reused). Shift registeres work just fine of course, but this requires me to wire this data through all the other cases that don't need it just so they can have an output for the tunnel. Is there anything else I can do to avoid wiring paths through every case that doesn't actually need the data?
0 Kudos
Message 1 of 7
(3,525 Views)
Hopefully I understand what you are describing. Have you considered using local variables to pass the data (or structure). If only a few of the cases need the data, then you shouldn't have too much of a problem with excess memory consumption. You could write to a local variable in one case and read from it in the next case where its required. This would require a "dummy" indicator on the front panel to store the data.
0 Kudos
Message 2 of 7
(3,525 Views)
A common way to do this is to use one shift register to carry a cluster of variables. The initail value of the cluster (left side of the shift register) is a cluster of constants that matches they types of all your variables. In a case where you need a value, you just unbundle that value. If the case modifies and variables, you just bundle the new values and wire it out to the shift register.

This does force you to wire through every case, but it's only one wire. Plus, if you decide you need a variable in a case that previously didn't, it's just and unbundle away.

Hope this is clear. Let me know if you want an example.

~Tim
Message 3 of 7
(3,525 Views)
I hadn't considered that given all the experts' preferrece to avoid local variables if the data can be wired. Here's another question: Does passing a very large amount of data through a wire in and out of cases (whether the case needs it or not) take up system resources? What I mean is, is it "effortless" to pass the data through there using a wire, whereas, using a local variable uses more system resources. The reason I am asking this is to clarify if block diagram neatness is the only reason to consider another option other than to pass all my data structures through every case. Some of the data structures are arrays of images (lots of memory) and I was wondering if just wiring them through, even if nothing is done with it, takes up system resources?
0 Kudos
Message 4 of 7
(3,525 Views)
An example is always helpful to save me time of figuring this out if you don't mind. My concern about using system resources in wiring through so much data (stated in detail in reply to Steve W.'s answer to the question) is still unresolved. If you have any insights on this matter as well, I would appreciate it.

Thanks.
0 Kudos
Message 5 of 7
(3,525 Views)
True, a lot of people (myself included) try to avoid using local variables if possible, but sometimes using them is a good solution. As far as wiring data through many cases, the only resources that should be taken are for the one instance of your data. In other words, wiring that data through other cases is just for data flow and won't take up more resources for each additional case you wire it through. In your case, it sounds like wiring the data would be a better solution than trying to use the local variables (each local variable you create DOES use up more memory).
0 Kudos
Message 6 of 7
(3,525 Views)
Here's a real simple example. I can't give you too much insight with respect to the memory usage, except to say that I've never had any problems doing things this way. I've written a couple of big vi's with 30 - 40 variables clustered this way.
0 Kudos
Message 7 of 7
(3,525 Views)