Beruflich Dokumente
Kultur Dokumente
B. Parts of a VI
LabVIEW VIs contain three main components: 1. Front Panel 2. Block Diagram 3. Icon/Connector Pane
You build the front panel with controls (inputs) and indicators (outputs)
Icon
Connector Pane
Indicators
Graphs, LEDs, and other displays Simulate instrument output devices and display data the block diagram acquires or generates
Numeric Control
Increment/Decrement Buttons Numeric Indicator
Boolean Indicator
Controls Palette
Tack the Controls palette and select CustomizeChange Visible Categories then click Select All
Pratice
Replicate the following front panel
F. Block Diagram
Block diagram objects include the following:
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Change the view type of a terminal by toggling the View as Icon selection from the context menu
H. Selecting A Tool
Create, modify, and debug VIs using the tools provided by LabVIEW A tool is a special operating mode of the mouse cursor The operating mode of the cursor corresponds to the icon of the tool selected When using the Automatic Tool Selection, LabVIEW chooses which tool to select based on the current location of the mouse
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Practice
Look and the block diagram of the previous practice and add the following nodes: Target: Add Simulate a given temperature value, Multiply add a random noise of given amplitude, then light up an alert when such a Random number temperature is greater than setpoint and Greater than another if is less than setpoint . Less than Get date/time in seconds Then use wires to connect all the elements of the block diagram leaving no terminal unconnected.
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Practice solution
In LabVIEW, the dynamic data type is represented with the color dark blue
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
I. Dataflow
LabVIEW follows a dataflow model for running VIs A node executes only when data are available at all of its input terminals A node supplies data to the output terminals only when the node finishes execution
I. Dataflow Quiz
Which node executes first? a) Add b) Subtract c) Random Number d) Divide e) Sine
SummaryQuiz
1. Which function executes first: Add or Subtract?
a) Add b) Subtract c) Unknown
SummaryQuiz Answer
1. Which function executes first: Add or Subtract?
a) Add b) Subtract c) Unknown
I. Case Structures
Have two or more subdiagrams or cases Execute and displays only one case at a time An input value determines which subdiagram to execute Similar to case statements or if...then...else statements in text-based programming languages
I. Case Structures
Case Selector Label: contains the name of the current case and decrement and increment buttons on each side
Selector Terminal: Wire an input value, or selector, to determine which case executes
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Practice
Add to the previous practice a button in order to update the string label ONLY if the button is pressed. Then run. Change its mechanical action and run again. Create a enum control with items Heating, Cooling, Conditioning and use its values to turn on label too hot only, label too cold only, or both, according to the case selected. Make the string indicator display Hi there! if the user inputs Hello, or the same input string if otherwise.
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Right-click the Case structure border to add, duplicate, remove, or rearrange cases and to select a default case
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Avoid using the Use Default If Unwired option on Case structure tunnels Adds a level of complexity to your code Complicates debugging your code
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
D. While Loops
Flowchart
Pseudo Code
D. While Loops
Iteration terminal: returns number of times loop has executed; zero indexed Conditional terminal: defines when the loop stops
Iteration Terminal
Conditional Terminal
Practice
Add a STOP button to the previous practice, then include everything in a while loop in order to stop the program when the user hit STOP. Add a CHART and display the current iteration number on it.
Please note: from now on the RUN CONTINOUSLY button wont be used, use the RUN button instead. AVOID HITTING THE ABORT BUTTON AT ALL COSTS!!
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Practice
Please open again the previous vi. Using an input tunnel display the time the vi has been active (in seconds) and stop it when such time is MORE THAN 20s or if the user hits the STOP button.
Think about this: what are the differences between a simple wire and a tunnel? Can a wire HOLD data? Can a tunnel?
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
F. Timing a VI
Why do you need timing in a VI? Control the frequency at which a loop executes Provide the processor with time to complete other tasks, such as processing the user interface
Practice
Open task manager and run the previous vi. Add to the previous practice the proper wait function in order to force the loop time to 200ms Open task manager and run the vi again. Add to the previous practice the proper function in order to display a string version of time elapsed
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
E. For Loops
Flowchart
Pseudo Code
E. For Loops
Create a For Loop the same way you create a While Loop If you need to replace an existing While Loop with a For Loop, right-click the border of the While Loop, and select Replace with For Loop from the shortcut menu The value in the count terminal (an input terminal) indicates how many times to repeat the subdiagram
Practice
Reproduce the following block diagram
What will be the result displayed in A? in B? in C? When? What will be the content of D?
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
Executes a set number of times unless a conditional terminal is added Can execute zero times Tunnels automatically output an array of data
Stops executing only if the value at the conditional terminal meets the condition Must execute at least once Tunnels automatically output the last value
A. Arrays
An array consists of elements and dimensions
Elements: data that make up the array Dimension: the length, height, or depth of an array An array can have one or more dimensions and as many as (231)1 elements per dimension, memory permitting
Consider using arrays when you work with a collection of similar data and when you perform repetitive computations
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
A. Arrays
The first element shown in the array (3.00) is at index 1 and the second element (1.00) is at index 2 The element at index 0 is not shown in this image, because element 1 is selected in the index display The element selected in the index display always refers to the element shown in the upper left corner of the element display
A. Arrays Creating
1. Place an array shell on the front panel 2. Drag a data object or element into the array shell
A. Arrays 2D Array
Stores elements in a grid Requires a column index and a row index to locate an element, both of which are zero-based To create a multidimensional array on the front panel, rightclick the index display and select Add Dimension from the shortcut menu You also can resize the index display until you have as many dimensions as you want
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
A. Arrays Initializing
You can initialize an array, or leave it uninitialized For initialized arrays, you define the number of elements in each dimension, and the contents of each element Uninitialized arrays have dimension but no elements
You can use an array constant to store constant data or as a basis for comparison with another array Array constants also are useful for passing data into a subVI
Gruppo di Misure Meccaniche e Termiche UNIBS - DIMI
A. Arrays Auto-indexing
If you wire an array to or from a For Loop or While Loop, you can link each iteration of the loop to an element in that array by enabling auto-indexing on tunnel The tunnel changes from a solid square to the image shown above to indicate auto-indexing
Practice
Create a new VI having the following block diagram
Practice
Open the thermostat practice VI, Instead of generating a single temperature value per cycle, create a set of 100 samples, put them in an array. Display all the 100 samples on both the CHART and the GRAPH, while controlling the boolean indicators only on the AVERAGE of the array