LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

retrieve iteration from stacked sequence structure

I have a stacked sequence structure with 15 iterations. Is there a functional equivalent to the "i" from the For loop or a way to make one?

 

I need to trigger some other events based on what iteration of the stacked sequence is running. 

0 Kudos
Message 1 of 10
(3,440 Views)

In a sequence structure they are called frames rather than iterations.  And you have run into one of the reasons why sequence structures are usually not the best arrchitecture for involved programs: They are hard to modify and essentially impossible to branch.

 

You can context-click on the edge of the frame and choose Replace with Case Structure.  Enclose the case structure in a while loop.  With just a little extra effort you will have a state machine which is much more flexible.

 

Lynn

Message 2 of 10
(3,434 Views)

Hi,

 

you can put numeric value 0 to case 0, then pass that value + 1 to next stack (right click the sequence structure, add sequence local). It would be better design to use state machine than sequence structure.

 

seq.png

Message 3 of 10
(3,428 Views)

Let me first reiterate what the others have said. Avoid stacked sequences like the plague!

 

I have found that except for very few situations there is always a better way then using a sequence structure.

 

That being said you could use a local variable to do this too...

========================
=== Engineer Ambiguously ===
========================
Message 4 of 10
(3,414 Views)

I've convinced myself it's better to use a proper state machine.

 

So to do this, the best method is to have 15 serparate case structures, and place that into a while loop with N=15?

 

..then read the iteration number, and depending on that logic, select the proper case structure within the while loop?

0 Kudos
Message 5 of 10
(3,406 Views)

@Synbios wrote:

I've convinced myself it's better to use a proper state machine.

 

So to do this, the best method is to have 15 serparate case structures, and place that into a while loop with N=15?

 

..then read the iteration number, and depending on that logic, select the proper case structure within the while loop?


That should be ONE case structure, containing 15 different cases.  Then you wire the iteration number directly to the ? terminal of the case structure.

Message 6 of 10
(3,402 Views)

That makes sense. thanks!

0 Kudos
Message 7 of 10
(3,399 Views)

May I humbly suggest this article: Application Design Patterns: State Machines

 

You can create a state machine using the VI template that ships with LabVIEW. File -> New... Then expand the "From Template" branch.

Message 8 of 10
(3,389 Views)

In your example though, how do you get the dark bolded local variables? Or the part of the first frame that says I32 Iteration.

0 Kudos
Message 9 of 10
(3,379 Views)

They're drawn that way automatically my setting the local variable to "read". With the addition of the little arrows (as a consequence of an idea submitted in the LabVIEW Idea Exchange) it's somewhat redundant now.

Message 10 of 10
(3,366 Views)