130 likes | 261 Views
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. Review: Structures. Structures control the flow of a program’s execution. We’ve looked at several kinds: For Loops While Loops
E N D
EET 2259 Unit 8Other Structures; Local Variables • Read Bishop, Sections 5.6 to 5.12. • Lab #8 and Homework #8 due next week. • Quiz #4 next week
Review: Structures • Structures control the flow of a program’s execution. • We’ve looked at several kinds: • For Loops • While Loops • Case Structures • Sequence Structures • This week we’ll look at two more: • Formula Nodes • Diagram Disable Structures • We’ll also look at local variables.
Entering Formulas • You can perform just about any mathematical calculation using LabVIEW’s built-in arithmetic functions on the Functions >> Mathematics palette. • Example: • But for long, complicated formulas, there’s an easier way, called a Formula Node.
Formula Node • The Formula Node lets you type formulas using the same syntax used in C or C++. • 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. 250-253)
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)
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.
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
Creating Local Variables • To create a local variable, right-click the desired front panel object and select Create >> Local Variable. (Bishop, p. 257)
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)
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
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 difficult to set up than global variables.