Sequence Locals
Exercise 6-4 Formula Node Exercise
D. Replacing Sequence Structures
Updating an indicator from different frames of a Sequence structure is not easily accomplished. For example, a VI used in a test system may have a “status” indicator that displays the name of the current test or process in progress. If each test is a subVI called from a different frame of a Sequence structure, you cannot update the indicator from each frame by building the diagram shown below:
You cannot use the “status” indicator as shown above because according to the data flow paradigm, nothing leaves a node until the node finishes running. Therefore, the sequence structure will not pass data outside its borders until frames have completed. You can use Local variables to solve this problem, but a better solution would be to replace the Sequence structure with a loop and a Case structure.
Note Local variables are discussed in the LabVIEW Basics II course.
Shown below is a new structure that is equivalent to a Sequence structure with three frames, where each case in the Case structure is equivalent to a sequence frame. Each iteration of the While Loop executes the next “frame.” A front panel string indicator is updated to display the status of the VI for each frame. Notice that the status is updated in the “frame” prior to the one that calls the corresponding subVI. This updates the indicator before the named subVI is called. Putting the status string constant in the same frame as the one calling the test would not work because data is passed out of a Case structure after it finishes executing.
Broken wire— broken Run arrow gives the following error message: "Sequence Tunnel: multiple assignment to tunnel."
Another advantage to replacing a Sequence structure with a Case structure in a loop is that the Case structure can pass data to end the While Loop during any case. For example, if an error occurs while running the first test, a False value can be passed to the loop condition to end the loop. In contrast, a Sequence structure must run all of its frames to completion whether or not an error occurs.
Summary, Tips, and Tricks
• LabVIEW has two structures to control data flow—the Case structure and the Sequence structure. LabVIEW depicts both structures like a deck of cards; only one case or one frame is visible at a time.
• Use the Case structure to branch to different diagrams depending on the input to the selection terminal of the Case structure. You place the subdiagrams inside the border of each case of the Case structure. The case selection can be Boolean (2 cases), string, or numeric (231–1 cases).
LabVIEW automatically determines the selection terminal type when you wire a Boolean, string, or integer control to it.
• If you wire a value out of one case, you must wire something to that tunnel in every case.
• Use the Sequence structure to execute the diagram in a specific order. The diagram portion to be executed first is placed in the first frame of the structure, the diagram to be executed second is placed in the second frame, and so on.
• Use sequence locals to pass values between Sequence structure frames. The data passed in a sequence local is available only in frames
subsequent to the frame in which you created the sequence local, and not in frames that precede the frame.
• With the Formula Node, you can directly enter formulas in the block diagram. This feature is extremely useful when a function equation has many variables or is complicated. Remember that variable names are case sensitive and that each formula statement must end with a semicolon (;).
• Sequence structures can be replaced using a loop and a Case structure. This is useful if you need to update an indicator from different frames or if you need to end the program from any frame.
Additional Exercises
6-5 Build a VI that uses the Formula Node to calculate the following equations.
y1 = x3+ x2+ 5 y2 = m * x + b
Use only one Formula Node for both equations. Remember to put a semicolon (;) after each equation in the node. Name the VI
Equations.vi.
6-6 Build a VI that functions like a calculator. The front panel should have digital controls to input two numbers and a digital indicator to display the result of the operation (Add, Subtract, Divide, or Multiply) that the VI performs on the two numbers. Use a slide control to specify the operation to be performed. Name the VI
Calculator.vi.
6-7 Modify the Square Root Exercise (Exercise 6-1) so that the VI performs all calculations and condition checking using the Formula Node. Name the VISquare Root 2.vi.
6-8 Build a subVI that has two inputs and one output. The inputs are “Threshold” and “Input Array,” and the output is “Output Array.” Output Array will contain values from Input Array that are greater than Threshold. Save your subVI asArray Over Threshold.vi. Test your subVI by creating another VI that generates an array of random numbers between 0 and 1, and uses the Array Over
Threshold subVI to output an array with the values above 0.5. Save the test VI asUsing Array Over Threshold.vi.