Professional Documents
Culture Documents
What is LabVIEW?
LabVIEW is a graphical programming language that implements dataflow programming. LabVIEW was first developed for virtual instrumentation. In other words, the software is the instrument. Each LabVIEW program is called a VI which is short for Virtual Instrument. A VI contains two windows, a Front Panel and a Block Diagram. The front panel is the user interface to the instrument. For example, imagine an oscilloscope, there is a graph, buttons, knobs, dials, etc. The front panel of a LabVIEW VI allows you to create these interfaces in software. The block diagram is like the wiring inside the oscilloscope. You can place blocks to add gain, process waveforms, etc. While LabVIEW was initially developed for instrumentation, it has been used in many different applications. For example, one of the most public applications of LabVIEW is the LEGO Mindstroms NXT. Additionally, LabVIEW has also been used in robots in the DARPA Challenges, to perform real time analysis of the Birds Nest Olympic Stadium in Beijing, and even control CERNs Large Hadron Collider. Today, however, we will be using LabVIEW for its intended purpose and interface with the new NI myDAQ.
interface for our program. For our calculator, we will have two controls and one indicator. A control allows the user to input data to the block diagram. Remember that the end user does not have access to the block diagram at runtime. An indicator will allow the block diagram to communicate data back to the user. Lets place two Numeric1 controls and one Numeric indicator as show in Figure 2. The controls and indicators can be found in the Numeric Palette. In Figure 2, I have named the controls and indicators. To change the name of a control or indicator, double click the existing name, and enter a new name. Also, should you wish to include a name or instructions, you can double click anywhere on the front panel and the text tool will allow you to create a text box. Now lets look at the block diagram. Notice that there are already three blocks on the diagram. These blocks represent the controls and indicators you placed on the front panel. Also note the colors of the blocks. LabVIEW defaults to the double precision data type2. You can select a different data type by right clicking the block and selecting Representation. For our demo, leave the values as double precision.
Figure 2: Calculator Front Panel
Lets wire up our first simple program that performs basic addition. To make LabVIEW perform an add, select ProgrammingNumericAdd from the functions palette. This will place an add block on the block diagram. Now hover your mouse over one of the terminals of the blocks. 3 Note the change in cursor. The wire coming off the spool is the new point of the cursor. Wire each control to a terminal on the add block. Then wire the output of the add block to your indicator as shown in Figure 3. Note how the data will flow from left to right on the block diagram. Congratulations, you have written your first LabVIEW program!
Numeric controls or indicators are number inputs and outputs. Other types include Boolean, String, Array, Cluster, and Graph. There are other data types, but this will be enough for this demo. 2 Double precision is a 64-bit floating point data type. In other words this allows decimal numbers to be returned to the user. Fixed point, integer (both signed and unsigned), and single point data types are also supported for numeric data. 3 When your mouse hovers over a terminal, the mouse cursor will switch to a spool of wire and a dot will appear on the block, representing the terminal.
Page | 3
Running a LabVIEW VI
Now that we have made our program, we need to run it. There are a few options when it comes to running a LabVIEW VI: Single Execution and Continuous Execution. Single Execution will run your program once, while Continuous Execution runs until the software encounters an error or you abort the program. In the upper left corner of both the block diagram and front panel, you will find a set of symbols as shown in Figure 4. These icons perform the following functions Figure 4: Execution from left to right: Single Execution, Continuous Execution, Buttons Abort, Pause, and Highlight Execution. Highlight Execution (sometimes called Debug mode) allows you to see an animation of the dataflow in your program. Little circles, representing the data, flow between blocks and green arrows appear on blocks that are currently running. This can be a great way to debug programs. Lets enter some numbers on the front panel and click the Single Execution arrow. Notice that the indicator now shows the sum of the two numbers you entered. Try Single Execution again, but before you click the arrow, click on the Highlight Execution light bulb. The program runs slower, but if you look at the block diagram during execution you can see the animation. This can be very useful! Now a calculator isnt very useful if we keep having to hit run each time. Try clicking Continuous Execution (you should turn off Highlight Execution). You should be able to change the values in the controls and watch the indicator change as well. This is great and all, but wouldnt it be cool to perform more than one function?
There are no blocks for structures, rather they will change the cursor and allow the user to draw the size necessary for the application at hand. 5 Drawing the case structure around more than the add block will cause the indicators only to be read when running that case. This can cause excess controls and indicators and clutter the front panel.
Page | 4
boolean to control which case is executed: true or false. We will use a simple front panel control to pick add or subtract. Right click on the left terminal of the decision block and select CreateControl. This is a great shortcut when working on the block diagram. If you switch to the front panel, it should look similar to Figure 6. Notice that the run arrow is broken. This means our program is not complete. We need to add something to the false case of the case structure. To switch the structure, click the arrow pointing left or right by where it says True. Now in the same palette as the add block, drop in a subtract block and Figure 6: Boolean Control on Front wire up the inputs and outputs. Our calculator can now add Panel and subtract. Run your program setting the Boolean control to add or subtract.
functions. By selecting 0 through 3 on the switch statement control, you can control which function is performed. This is good and all, but what about looping?
Looping in LabVIEW
We have already seen how we can loop through our code via continuous execution; however sometimes we want control in our Page | 5
code. Looping in the code allows us to have only sections of code loop. LabVIEW provides several types of loops. Like other programming languages, LabVIEW provides For and While loops. Loops are located on the functions palette in ProgrammingStructures. For our code, lets use a While Loop. Like the case structure, you will need to draw the box. This time, however, draw the box around the controls, indicator, and case structure. This ensures the latest values are processed. When you have completed these steps, your code should look like Figure 8. Notice that the run arrow is still broken. This is due to two new blocks in the While loop. The While loop adds both an iterator block (the i inside the blue box in the lower left corner of Figure 8). This counts the number of times the code has executed.6 The other icon in the lower right corner of the loop is the Stop if True icon. The loop will continue to iterate until a value of true is passed to this block. 7 Figure 9: Finished Calculator Block Diagram For our use we will wire a control to the stop condition. Your final block diagram should look like Figure 9.
The counter starts at 0. Thus your stop condition must be one less than the total number of iterations you would like. 7 Another possible symbol in this position is the Continue while True icon. As the name suggests, the loop will continue until a false is passed to the block.
Page | 6