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.

Example Code

"Sequence Loop" Template

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview

This is a very basic example of a design pattern we've dubbed the "Sequence Loop". The VI is set up to place VI contents (created with this cool Quick Drop tool) so it is easy to add a sequence loop to your VI via the palettes or Quick Drop.

 

Description

Stacked sequences are hard to read and generally disliked (for good reasons). That is why they are no longer on the palette. But what do you do if you have a VI with a lot of relatively simple logic that needs to get executed sequentially? A block diagram with a width many times the width of a monitor is hard to read. The overhead associated with introduction and maintenance of numerous subVIs may not be worth the trouble. A string or enum driven state machine is overkill, because you will never need decision making, but the design pattern is appealing for its readability.

 

Enter the Sequence Loop. It is a simple way to keep your code clean and compact while utilizing Shift registers to pass values around (yay for no sequence locals or backwards wires!).

 

 It looks like this:

sequence loop 4.PNGsequence loop 3.PNG

 

Super simple and effective, and easy to extend. Here's a typical loop that could be used in a test program developed with TestStand Semiconductor Module (TSM):

sequence loop 2.PNG

 

Requirements

 LabVIEW 2015 (or compatible)

 

Steps to Implement or Execute Code

  1. Download this VI
  2. Follow the steps listed in the LabVIEW Help topic for adding items to the palette
  3. Enjoy being able to drop Sequence Loops from the palette (or even faster with Quick Drop since QD automatically pulls in all the VIs on the palette)

 

Additional Information or References

FAQ:

Q: Isn't this just a stacked sequence structure in disguise? Is it terrible too?

A: No. Sequence Loop satisfies the needs that the Stacked Sequence was intended for without the downsides of the Stacked Sequences. Stacked sequences have sequence locals which break dataflow and are difficult to reason through and debug. The Sequence Loop looks and feels like a very simple state machine and is easy to read.

 

Q: Why is there an increment function, why didn't you just start your case structure numbering at 0?

A: This was the subject of much debate. From a functional standpoint 0 would be fine. From a linguistics standpoint we all agreed that we don't like using the word "zeroth" in normal conversation and that calling case 0 the "first case" would be super annoying, so the increment stuck.

 

Q: What if I want to add a case in the middle? Do I have to renumber all X remaining cases to preserve execution order?

A: Not at all! If you're using this design pattern you can download the companion right-click menu that makes adding or removing frames as simple as a couple clicks.

 

Alex W.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
croohcifer
Member
Member
on

I've been playing around with the Caraya Unit Test Framework and have found that these sequence loops are a really nice way to easily add new unit tests to the same VI without bloating the block diagram:

 

Capture.PNG

 

When testing class methods, it's also nice to be able to store the class in the cluster from frame to frame.

croohcifer
Member
Member
on

Also, please ignore my lack of shift registers on the error wires...

Darren
Proven Zealot
Proven Zealot
on

FYI for anyone following this thread, I have developed an alternative sequencing pattern called the Natt Sequence that was inspired by the Sequence Loop. Check it out on ni.com here:

 

http://bit.ly/nattsequence