Ex2 - First LabView program PDF

Title Ex2 - First LabView program
Course Méthodes numériques
Institution Université Savoie Mont Blanc
Pages 4
File Size 253.1 KB
File Type PDF
Total Downloads 2
Total Views 141

Summary

First LabView program...


Description

Exercice 2 Your First LabVIEW Program A program written in LabVIEW uses a slightly different approach to than programs written in other languages. This is called dataflow programming and, when a function such as addition or subtraction executes it receives all required inputs before it can be executed. A function will produce output data and passes the data to the next node in the dataflow path. The movement of data through the nodes determines the execution order of the VIs and functions on the block diagram. You may have done computer programming in languages such as Visual Basic, C++, or JAVA which follow a control flow model of program execution. In control flow, the sequential order of program elements determines the execution order of a program. In LabVIEW, the flow of data rather than the sequential order of commands determines the execution order of block diagram elements. Therefore, you can create block diagrams that have simultaneous operations. Take a look at the LabVIEW code to calculate the equation below.

Notice in the equation we have parenthesis around the addition operation and subtraction operation. Without those, Numeric2 would be multiplied by Numeric3 and then the addition would be performed and finally the subtraction and this is not what we want. In LabVIEW there are no parenthesis because we specify the order of execution by the placement of the function. In other programming languages, such as C++ or JAVA, each statement is executed sequentially meaning that one statement executes, then the next, and so on. In our LabVIEW program the addition operation and the subtraction operation can execute at the same time since one does not depend on the other. Now you have a few options on where to go next. The next lesson will how you how to build the user interface which goes in the LabVIEW front panel. If you already know how to create the user interface you can do that on your own and moving to the lesson on creating the code which goes in the block diagram. The program you saw on the previous page is actually going to be used in this lesson to learn how to use LabVIEW, for the next lesson on tracing a program as it executes, and for a third lesson on debugging a program when you have errors.

It is probably very useful to go through some detailed tutorial instructions that tell you how to create a LabVIEW program and we will do that at this time. Make sure that you have a LabVIEW up and running. 1.

Every LabVIEW program has a user interface where the user can enter data for the program to process and output that the program has generated and it has a set of code that indicates that processing is to take place. The user interface is called the front panel and the code is called the block diagram. To have both of these on the screen at the same time press ctrl-t to tile the windows.

2. 3.

Now you are going to create the user interface in the front panel and it will look the Front Panel above. Make sure your cursor is in the front panel. You are going to add the four values called Numeric, Numeric 2, Numeric 3, and Numeric 4. These are input values used by the program and LabVIEW calls them controls. To add these to your front panel right click in the front panel and the controls window will come up. Click on Express»Num Ctrls and a window will come up, titled "Numeric Controls" containing some icons. You want to drag the one labeled "Num Ctrl" to the front panel. It will have the name of "Numeric" which is the default value. Position this control in the front panel like you see in the diagram above. To add the other controls you will want to do the same exact thing dragging 3 of the "Num Ctrl" icons to the front panel. The names will be Numeric 2, Numeric 3, and Numeric 4 which is the default name. Notice that when you add a control to the front panel one also gets added to the block diagram. The front panel is what the users will see when they run the program and enter data into it. In the diagram above notice that the 4 controls are on the left side of the screen and there is "Result" on the right side. "Result" is an output value that is computed by the program and is called an indicator. Generally, you want controls on the left side of the front panel and indicators on the right side. This simplifies the user interface for the user. Add an indicator to the front panel by right clicking on it and selecting Express»Num Inds and then dragging a "Num Ind" to the front panel. The name will be "Numeric 5" by default. Notice that the name of the numeric indicator that you just created is "Numeric 5" and you need to change the name to "Result". If you double click on the Numeric 5 label it will turn to a solid black background and you can type "Result". Be sure to click somewhere in the front panel after you type "Result" and it will set the name. If you want to change the names of the controls to something like "a", "b", "c", and "d" feel free to do that. Notice that each of the four controls have values in them. When a control is created the default value is zero. To change this to a different value start by entering the value you want as the default in the control, then right click on the value and select Data Operations»Make Current Value Default. This means that every time the program is executed if the user does not enter a different value the value you entered in the control is used. Try setting the default value for the four numeric controls to the values shown above. Now you have the front panel created and it is time to create the code to process the four controls and produce the Result indicator. The next page will show you how to do this.

4.

5.

6.

7.

8.

Now it is time to create the programming code which, in LabVIEW, goes into the block diagram. As a reminder, we are trying to create a program that will calculate the equation below.

You have the user interface to read the value of the input values and to display the value of the equation after it is calculated. Now we have to add the code to compute the value of Result in the LabVIEW block diagram. The following steps will guide you through the development of this code. 1.

Make sure your cursor is in the block diagram. If it is not visible you can press Ctrl-T and the front panel and block diagram will be tiled and, from there, you can move to the block diagram.

You have the user interface to read the value of the input values and to display the value of the equation after it is calculated. Now we have to add the code to compute the value of Result in the LabVIEW block diagram. The following steps will guide you through the development of this code. 1.

Make sure your cursor is in the block diagram. If it is not visible you can press Ctrl-T and the front panel and block diagram will be tiled and, from there, you can move to the block diagram.

2.

The code for the LabVIEW program that you are going to create is below.

You have the user interface to read the value of the input values and to display the value of the equation after it is calculated. Now we have to add the code to compute the value of Result in the LabVIEW block diagram. The following steps will guide you through the development of this code. 1. 2. 3.

4.

5. 6.

Make sure your cursor is in the block diagram. If it is not visible you can press Ctrl-T and the front panel and block diagram will be tiled and, from there, you can move to the block diagram. The first thing that we need to do is to add the code to add "Numeric" and "Numeric 2". In the block diagram, Right click and select Mathematics»Numeric and drag the addition operator to the block diagram. LabVIEW passes data from one function to the next with wires and you will see these in he diagram above. The addition operator has two input values, which are called terminals in LabVIEW. You want to connect the terminals coming out of "Numeric" and "Numeric 2" to the input terminals of the addition operator. Move the cursor to the right of "Numeric" and the icon turns into a spool of wire. Hold the cursor and drag it to the top of the addition operator. Now add a subtraction operator to the block diagram and position it down by "Numeric 3" and "Numeric 4" similar to the diagram above. After you do that you want to wire it just like you did with the addition operator. The last icon to add is the multiplication operator between the addition and subtraction operator an wire the terminals coming out of the addition and the subtraction operator into it. The final step is to wire the output of the multiplication into the Result indicator.

7.

The program is now finished. You can tell if there are errors if the arrow between Edit and View is broken. A solid arrow means that there are no errors and a broken arrow means indicates that you have errors in your code. If you have a broken arrow compare your program to the one listed above to see what is different.

8.

To run the program click on the solid arrow. If you don't type in any values the default values will be used which means that the program will calculate 5+10 * 8-3 which is 75 and that will be displayed in the Result indicator. The front panel will look like this:...


Similar Free PDFs