Presentation is loading. Please wait.

Presentation is loading. Please wait.

EET 2259 Unit 8 Other Structures; Local Variables

Similar presentations


Presentation on theme: "EET 2259 Unit 8 Other Structures; Local Variables"— Presentation transcript:

1 EET 2259 Unit 8 Other Structures; Local Variables
Read Bishop, Sections 5.6 to 5.12. Lab #8 and Homework #8 due next week. Quiz #4 next week. Handouts: Quiz 3

2 Review: Structures This week we’ll look at:
Structures control the flow of a program’s execution. We’ve looked at: For Loops While Loops Case Structures Sequence Structures (flat or stacked) This week we’ll look at: Formula Nodes Diagram Disable Structures Local Variables Global Variables

3 Entering Formulas You can perform just about any calculation using LabVIEW’s many built-in mathematical functions on the Functions >> Mathematics palette. A simple example: 𝑦=5sin⁡( 𝑥 4 + 𝑥 2 ) But for long, complicated formulas, there’s an easier way, called a Formula Node. Demo how to build the example using built-in functions.

4 Formula Node The Formula Node lets you type formulas.
Formulas must end in a semicolon (;). To raise a number to a power, type **. For example, to set y equal to x4, type y = x**4; (Bishop, pp ) Use one to do example on previous slide. Then show various errors (missing semicolon, using Y instead of y, using ^ instead of **).

5 Diagram Disable Structure
The Diagram Disable structure lets you disable specific sections of code on the block diagram. It is similar to commenting out code in a text- based programming language. (Bishop, p. 254)

6 Usefulness of Diagram Disable Structure
This structure is primarily useful as a debugging tool. If you’ve got some code that you know or suspect is not working correctly, you can temporarily disable that code while you test the rest of your program. Eventually you’ll probably want to remove all diagram disable structures, after all of your code works correctly.

7 Example of Diagram Disable Structure
-Send them this file (diagramDisableExample.vi) for demo purposes.

8 Local Variables Local variables let you access front panel objects from more than one location in a single VI. They pass information between objects that can’t simply be connected with a wire. (Bishop, p. 255) Local variable

9 Creating Local Variables
To create a local variable, right-click the desired front panel object and select Create >> Local Variable. A silly example: Better to wire the button directly to the LED! Local variable Have them build it. Then use local variable for the pushbutton too, with the local variables connected to each other.

10 Use Local Variables with Care
Since local variables are not inherently part of the LabVIEW dataflow execution model, overusing them or misusing them can make block diagrams difficult to read or create unpredictable situations. (Bishop, p. 257)

11 Local Variables: A More Useful Example
Suppose that we want to turn off all the LEDs at the end of the program you wrote named P5_4_LEDSeqStruc.vi. It’s not easy, unless you use local variables. Local variables More useful, show how to use it to turn off all LEDs at the end of. (Add a frame with False wired to local variables for all three LEDs.)

12 Global Variables Local variables are called local because they only let you pass data from one place to another within a single VI. In LabVIEW you can also create global variables (not discussed in the text) that pass data between VIs running on the same computer. Global variable

13 Global Variables: An Example
First VI: Place a global variable, open its front panel and place an LED named “Magic!”, save global variable as global.vi. Then inside a While loop, wire a switch to the global variable. Second VI: inside a While loop, place the same global (using “Select a VI…” on functions palette), change it to read, and wire it to an LED. Then run both VIs. -Shared Variables let you do similar things, but with VIs running on different computers connected via a network.

14 Use Global Variables with Extreme Care
With global variables it can be very hard to see where data is going or where it’s coming from. Misusing them can make block diagrams very difficult to read and can create unpredictable situations. LabVIEW provides better ways to pass data between VIs, but they’re more complicated and more difficult to set up than global variables.


Download ppt "EET 2259 Unit 8 Other Structures; Local Variables"

Similar presentations


Ads by Google