Sie sind auf Seite 1von 8

ECE 100 Fundamentals of LabVIEW Programming

CASE STRUCTURE IN LABVIEW


Activity No. 7

I. INTENDED LEARNING OUTCOMES

At the end of this activity, the student shall be able to:


1. Understand the concept of Case Structure
2. Create an important program using Case Structure

II. BACKGROUND INFORMATION

When programming in LabVIEW, you may want to choose between multiple sections of code based on an
input. Based on the input it receives on the case selector terminal, the case structure chooses which case, or
section of code, to execute. The case selector terminal appears as a small question mark (?) on the left side of the
case structure.

If you change the input to the case selector terminal, the section of code that is executed changes. In the
figures below, the case structure executes different code for the input strings True and False.

Selector Terminal
The case selector terminal can receive multiple data types. You can use the following data types as inputs
to the case selector terminal:
Integers
Boolean values
Strings
Enumerated type values (Enums)
A case structure with a Boolean wired to its selector terminal has a maximum of two cases; all other data
types allow two or more cases.

Page 51
ECE 100 Fundamentals of LabVIEW Programming

III. LEARNING ACTIVITIES

1. Create a new LabVIEW VI by navigating to FileNew VI.

2. Place two numeric controls and a numeric indicator on


the front panel. Name the numeric controls Input A and
Input B. Name the indicator Result.

3. Place an Enum control on the front panel. This control is


located in ControlsModernRing & Enum. Rename
the control Operation.

4. Right-click on the Enum and select Edit


Items to open the Enum Properties.

Question: What are the options contained in the


Ring and Enum palettes? State their functions

5.Text Ring
Click- contain lists of
the Insert stringsand
button pairedadd
withthe
numeric values through which you can cycle. text rings allow you
following
much more freedom in assigning a numeric
Items: Add, Subtract, Multiply, and Divide. value.
Menu Ring - These give the number associated with the item the user selected.
Enum - contain lists of strings paired with numeric values through which you can cycle. Enums require the
numeric values to be sequential, unsigned integer values.
Pict Ring - is stored in the ring control in the form of an image/value pair, where the image is a bitmap displayed
by the control when the item is selected, and the value is the numeric or string value corresponding to that item.
Text & Pict Ring - is stored in the ring control in the form of an image/value pair, where the image is
a bitmap displayed by the control when the item is selected, and the value is the numeric or string value
corresponding to that item with a text.

Page 52
ECE 100 Fundamentals of LabVIEW Programming

6. Click the OK button at the bottom of the Enum Properties box to close it.

Your front panel should look similar to the following figure.

7. View the block diagram by selecting WindowShow Block Diagram or pressing <Ctrl-E>.

8. Place a case structure on the block diagram, between your controls and indicator. Find the case
structure at
FunctionsProgrammingStructures.

Page 53
ECE 100 Fundamentals of LabVIEW Programming

9. Wire the Operation Enum control to the case structures selector terminal, located on the left side of the
case structure.

10. Right-click on the border of the case structure and select Add Case for Every Value. The case
structure now has a case for every value of the Enum that is wired to the case selector terminal. This
tutorial demonstrates four cases: Add, Subtract, Multiply, and Divide.

Page 54
ECE 100 Fundamentals of LabVIEW Programming

11. Switch to the Add case of the case selector terminal by clicking the right or left arrows at the top of
the case structure, or by placing your mouse inside the case structure and pressing <ctrl> while scrolling
with the mouse.
12. Place the add function in the Case Statement when the Add case is selected.

13. Wire the controls Input A and Input B to the inputs of the add function. Wire the output of the add
function to the Result indicator. You can wire through the case structure, which acts much like a loop and
creates tunnels automatically.

14. Switch to the Subtract case of the case selector terminal by clicking the right or left arrows at the top
of the case structure, or by placing your mouse inside the case structure and pressing <ctrl> while scrolling
with the mouse.

15. Add the subtract function to the Subtract case. Wire the function to the controls and indicators in the
same way you wired the add function.

16. Add the multiply function to the Multiply case and the divide function to the Divide case. Wire
these functions to the controls and indicators in the same way you wired the add and subtract functions.
Your case structure should now contain four cases similar to the following:

17. When you have successfully wired all the outputs, the tunnel to the Result indicator changes from a
hollow square to a filled square, as shown in the following figures.
Question: How do you think will the case structures above work? Explain shortly the process

Page 55
ECE 100 Fundamentals of LabVIEW Programming

.
In this case The VI shown a Selector of operation which contain mathematical
event that can be used in a certain time but this operations cant runs
simultaneously, as you can see in the case the user can pick only 1 operation in
a time he desire to put a Values on 2 different control that can be divided, added,
subtracted or can be multiplied

18. View the block diagram by selecting WindowShow Front Panel or pressing <Ctrl-E>.

19. Change the value of Input A to 1 and the value of Input B to 2.


Question: What do you notice as you change the value of Input A and B?

I notice in this cases is there is a changes only when the VI runs. But if you run it,
there will be change in input A and B the result will not be the same as the 1 st
result came up

20. Change the value of the Operation Enum to Add.

21. Run the VI, which changes the value of the Result indicator to 3.

22. Experiment with different values of the Operation Enum and run the VI again. Save VI as Act7.VI
Question: Explain how the VI works totally?
In this VI It works based on the Structure inside the Font panel and working
structure of block diagram, it performs based on the givens inside the block
diagram that indicate operation which is subtraction, Addition, Multiplication and
division, the VI works when you put a certain values in input A and B that can be
operate in a certain time like example if you put at values on A and B you can
choose an operation either you choose add or multiple it will show your desire
values Page 56
ECE 100 Fundamentals of LabVIEW Programming

IV. MACHINE PROBLEM

1. Create a 25-item test examination, multiple choice types that allow to user to select the option of the best
answer. Your VI should use the Case Structure. The questions should appear in the Front Panel with the
control that will allow preference of answer. Once the 25-item test is answered, the program will check the
answer and will notify the user of his score and percentage rating. Customize your VI such that it is visually
presentable. Save your VI as MacPro7_1.VI.

2. Create a VI that will allow you to classify the winds speed into the following category using the Case
Structure. Your VI should be customized and be saved as MacPro7_2.VI.
0-20 KPH (Calm Wind)
21-30 KPH (Breezy)
31-50 KPH (Windy)
51-80 KPH (Low Pressure)
80-90 KPH (Tropical Depression)
90-120 KPH (Tropical Storm)
120-150 KPH (Typhoon)
150 and above (Super Typhoon)

V. ASSESSMENT TASKS

1. What is a Case Structure? How does it work?


A case structure contains one or more sub diagrams, or cases, exactly one of
which executes when the structure executes. The value wired to the selector
terminal determines which case to execute. It works as a selector or an option for
the user. If it is wired to a Boolean it becomes a Boolean type case. If it is wired
to a numeric it becomes a numeric type case, and if it is wired to a string it
becomes a string type case.

2. Cite some real-life applications of Case Structure.


Scientific calculator, Computers, ATM, Rice Cooker, water dispenser.

3. What is the importance of a Case Structure in building a LabVIEW program?


The case Structure is Very useful in labview, because this structure is capable of
taking multipool cases, this structure can indicate a difference of wrong in a
certain area of the VI. This operation can use in every days electronic device like
calculator or computer. Page 57
ECE 100 Fundamentals of LabVIEW Programming

VI. CONCLUSION
This activity the case structure that allows the user, use different execution depending on the
values of the label. The case structure is analogues to the C++ case block which based on case
value that input variables matched on the case execution, this case can be use a Boolean that can
change when the user desire a different operation, its either true or false or yes or no. so that this
topic is essential to use in any cases that operation a two or more structure.
VII. RUBRICS FOR LABORATORY PERFORMANCE

Page 58

Das könnte Ihnen auch gefallen