‘Examples’ Category Archives

16
May

For Loop Examples

by Christina in Examples, LabVIEW

Thanks for all the responses to my last post! The humble For Loop is much more complicated than it appears at first glance. (I’ll get to While Loops as well, but later).

Here’s a recap of the suggested “function” examples:

  • Contrasting the For Loop’s operation (iteration from zero to N times) with a While Loop’s operation (iteration until a condition is met).
  • Automatic indexing
    • 1D array
    • 2D array (row vs. column, how to transpose if needed)
    • Multiple indexing sources (and which will stop the loop)
  • Shift registers
    • passing data to the next iteration of the loop
    • uninitialized shift registers
    • shift registers with depth > 1
  • Reading the N terminal inside the loop
  • Conditional terminal to “break” the loop early

And the suggested “concept” examples:

  • How to stop the execution of parallel loops
  • How to control loop timing (including the Timed Loop)
  • For Loops that execute zero times – how to know when it can happen and how to handle it correctly
  • Error handling in loops
  • Data communication between loops. (I’m going to punt on this one. Anyone who heard about this year’s CLA Summit knows that Data Communication in LabVIEW is a huge topic, and not something I can address with a simple example. Rest assured, there are people working on clarifying the data communication options for our customers and I’ll keep you posted about what they come up with).
  • Performance considerations (e.g. optimizing loops), including the Parallel For Loop.

And the suggested “application” examples:

  • Filtering an array to only the elements meeting a constraint
  • Displaying progress of a loop

Whew! Well, as the saying goes, the longest journey begins with a single step, so let’s get started.

Here’s a simple For Loop example: For Loop Basics (I’m not claiming this VI is perfect; it’s just something I put together quickly).

For Loop Basics Front Panel
For Loop Basics - Example

Here are some experiments I’d like feedback about:

  1. It’s an exercise. Rather than just giving you something to run, it has steps which require you to edit the VI. Do you like examples like this?
  2. The instructions are on the panel in a String control. This approach has some advantages over a free label (e.g. it gives us a scrollbar, which handles system font changes more gracefully) and some disadvantages (e.g. you probably wouldn’t use controls for documenting “real” VIs). What do you think of this idea? Also, would you rather have the instructions on the diagram?
  3. It’s built so that it can be a VI Snippet, which means that (if you’re using a supported web browser and LabVIEW 2009 or later) you can drag it to a VI diagram. Is this useful at all?
13
Apr

What Does a Loop Example Need?

by Christina in Examples, LabVIEW

Loop Quandry Cartoon
The recent LabVIEW Example contest got me thinking about our example offerings. I categorize LabVIEW examples three ways:

  • Application examples. These examples are fully-functional applications that show off what LabVIEW can do. They can be great starting points for building your own, similar applications. However, they’re usually difficult to learn from because they are large and contain many different concepts. These kinds of examples seem to be popular in contests.
  • Concept examples. These are “teaching examples” that illustrate a concept. Although not VIs that you would modify and incorporate into a real application, they can present “how to” information with minimal extra code.
  • Function examples. I think these examples are the unsung heroes of the example world. With a good example, you can quickly learn what a function can do. Sometimes you can also learn what a function can’t do or common mistakes in its usage.

Even though Concept and Function examples are smaller than Application examples, they can be just as difficult to write. They require having a thorough understanding of the material without having lost sight of the new user’s point of view. In my experience, people who have taught LabVIEW are invaluable when it comes to crafting these kinds of examples.

Another recent, thought-provoking event for me was NI Tech, an NI-internal R&D conference. In two of her presentations, Nancy Hollenback (who recently re-joined NI as a Field Architect – more on that in a future post!) showed a slide illustrating several “hurdles” that LabVIEW users encounter when progressing from the “three icon demo” to large systems.

The first of these hurdles was “arrays and loops.”

Having been thus inspired, I’m now setting out to find (or build) the best possible function/concept examples for loops. There are somethings I already know they need to show:

  • how to decide if you should use a For loop or a While loop
  • array indexing on loop tunnels
  • the “zero iteration For loop” problem
  • early termination of For loops (“For loop with break”)
  • loop timing.

What other things would you expect from loop examples? Do you have any examples (from NI or elsewhere) that you recommend? Please send them my way!

6
Apr

Example Program Challenge 2011 Winner

by Christina in Examples, LabVIEW

Winning Example Application

Congratulations to peter_smith, the winner of the LabVIEW Code Madness: Example Program Challenge 2011!

His winning entry was: Browse NI Community User Groups and Sort Documents as You Want! This code allows users to extract all documents from a Community Group and sort them by their score. As the code progressed through the rounds of the challenge, peter_smith added the functionality to display the selected document in a new LabVIEW window and generate a report of the selected group. The final code extension during the Finals round allows users to store reports in the Amazon S3 cloud storage service.

I am impressed with this example’s attractive user interface and clean, commented diagrams. I hope you check it out!