Presentation on theme: "Based on LabVIEW 2011 Student Edition"— Presentation transcript:
1 Based on LabVIEW 2011 Student Edition LabVIEW BasicsBased on LabVIEW 2011Student Edition
2 Virtual instrumentsLabVIEW works on a data flow model in which information within a LabVIEW program, called a virtual instrument (VI), flows from data sources to data sinks connected by wires. The data can be modified as it is passed from source to sink by other VIs. LabVIEW supports two types of VIs--internal VIs and user created VIs. Internal VIs are packaged with LabVIEW and perform simple functions like adding numbers or opening files. User created VIs consist of both a graphical user interface called the front panel and a code pipeline called the block diagram. These VIs tend to be much more complex considering that they can contain any number of internal or user created VIs in an endless number of configurations.
3 Virtual instruments - cont. Consider a simplistic LabVIEW program which takes a single number from the user and multiplies it by 10. Analyzing such a program reveals the following data flow structure:The user inputs a number (data source).The program executes an addition VI taking the user's number and the number 10 as its inputs (data sink).The addition VI returns the result of the addition operation (data source).The result is displayed on the screen (data sink).While this example is simplistic, it exemplifies how all LabVIEW VIs work. Data always flows from data sources to data sinks according to the block diagram, much like how water flows through a pipe.
4 Front PanelEvery user created VI has a front panel that contains the graphical interface with which a user interacts. The front panel can house various graphical objects ranging from simple buttons to complex graphs.Various options are available for changing the look and feel of the objects on the front panel to match the needs of any application.
5 Block diagramNearly every VI has a block diagram containing some kind of program logic that serves to modify data as it flows from sources to sinks. The block diagram houses a pipeline structure of sources, sinks, VIs, and structures wired together in order to define this program logic. Most importantly, every data source and sink from the front panel has its analog source and sink on the block diagram.This representation allows the input values from the user to be accessed from the block diagram. Likewise, new output values can be shown on the front panel by code executed in the block diagram.
6 ControlsThe most common form of a data source in LabVIEW is a control. This element appears as some type of graphical element on the front panel of a VI that can receive input from a user or even another VI. As stated previously, any data source also has an analog symbol that appears on the block diagram so that its value can be read and used in the code pipeline. Controls make no exception to this rule.Every control has an associated data type that determines what kind of data flows from it on the block diagram. Every data type also has an associated color shown on the block diagram.Typical controls and their associated data types. In general, any control can be turned into an indicator and vice-versa.
7 Data types Different data types are indicated with different colors. Floating point numbers (decimal numbers) are shown in orange color. The letters DBL on the icon is for double, which refers to floating point numbers with double precision, which expresses the numerical accuracy of the internal representation of the number in the computer. You can think of floating point numbers as decimal numbers.Integers are shown in blue color. One example is a numeric constant.Boolean data are shown in green color. The letters TF on the icon is for True/False, which are the two possible boolean (logical) values of the element. One example is the Stop terminal.Textual data are shown in pink color.Cluster data are shown in brown color. Clusters are multivariables. They contain one or more elements of possibly different data types.
8 IndicatorsThe most common form of a data sink in LabVIEW is an indicator. This element appears as some type of graphical element on the front panel of a VI that can display output to a user or even another VI. As stated previously, any data sink in LabVIEW also has an analog symbol that appears on the block diagram so that its value can be updated in the code pipeline. Indicators make no exception to this rule.Every indicator also has an associated data type that determines what kind of data can be written to it on the block diagram.The front panel and block diagram for the simple number plus ten example. It should be noted that the number control and answer indicator have their similarly named analogs on the block diagram.Typical indicators and their associated data types. In general, any control can be turned into an indicator and vice-versa.
9 PalettesFront panel controls and indicators as well as block diagram VIs are available from a palettes visible depending on what window is currently active in the LabVIEW environment. These palettes have their contents separated into sub-categories containing controls, indicators, and VIs.Typical top-level block diagram and front panel palettes.
10 StructuresIn addition to controls, indicators, and VIs, the block diagram can also contain a number of programming structures that modify the sequence of data flow on the block diagram. These structures perform traditional functions like looping or case-selection, but many also provide services that have no clear counterparts in text based programming languages. LabVIEW currently supports six different structures -- while-loops, case structures, event structures, for-loops, sequence structures, and formula nodes.
11 While-loopsOne of the most common structures encountered on a block diagram is the while-loop. Much like in text-based languages, the LabVIEW while-loop continually executes until a given boolean condition is met. Unlike in text-based languages, the LabVIEW while-loop contains its own loop counter that provides the current loop iteration starting at zero.Three different ways of using a while-loop. The first loop continues forever because the loop conditional never becomes false. The second loop continues until a button on the front panel is pressed, sending a value of true to the loop conditional thereby stopping the loop. The third loop also continues forever, but also displays the current loop counter value in an indicator on the front panel. (It is important to note that these three loops will execute in parallel because their inputs are not dependent on each other.)
12 While-loops - contThe while-loop is typically used in LabVIEW to continue some operation until either the user or some code event indicates that the operation should stop. Normally, some kind of millisecond delay is also inserted into the loop so that it doesn't occupy all of the computer's CPU time.A while-loop that will stop when the loop iterator passes 1000 or when the user presses the stop button. A loop delay is also used to ensure that the loop operation doesn't occupy all of the CPU time.
13 While-loops - contNearly all structures in LabVIEW, including while-loops, can have inputs and outputs. Wires that pass into and out of while-loops form small connection points called tunnels on the structure. Various, powerful options are available for shaping data flowing through tunnels, ie. shift registers.Input and output loop tunnels. The while loops takes a numeric value through an input tunnel and multiplies it times its current iteration value. When the loop is stopped, the value of the last multiplication is passed through an output tunnel and displayed in another indicator.
14 Case structuresAnother common structure encountered in LabVIEW is the case structure. Like in text-based languages, the case structure executes a block of code based on the value of a certain variable. In LabVIEW, a case selector located on the case structure is wired to a data source. The value fed into the case selector determines what case executes. Only one case is shown at a time, but the visible case can be cycled by clicking on the arrows to the left or the right of the case name.The use of a case structure as a simple boolean if-statement. If the two numbers entered by the user add to zero, then a string message is displayed on the front panel saying so. If the two numbers do not add to zero, then a string message is displayed stating that they do not. The false case of the case structure is not shown.
15 For-loopsAnother common looping structure encountered on a block diagram is the for-loop. Much like in text-based languages, the LabVIEW for-loop continually executes until a given count is reached. Unlike in text-based languages, the LabVIEW for-loop can only step towards the final count by increasing the loop counter by one each iteration. To make larger steps or to step in the negative direction, while-loops with shift registers must be used.For-loop counter. The loop runs from zero to ninety-nine and increases the loop counter by one each iteration.
16 Formula NodesA Formula Node is a box where you enter algebraic formulas directly into the Block Diagram. It is useful when an equation is complicated or has many variables. Below is an example of how you would implement y = x^2 + x + 1 with regular block diagram nodes:It is much easier to use the Formula Node. Below is an example:
17 ClustersCluster data types are somewhat unique to LabVIEW and act as containers capable of storing a number of variables of different data types. In the simplest sense, clusters can be thought of as a group of data values that are bundled together to form a more complex, and often more meaningful, data type. From an object oriented perspective, clusters can be thought of as primitive objects with a number of properties without any methods to acts on them.A cluster with a number of elements. This cluster can be thought of representing a set of properties of a college course that can flow as a single object through the wires on the block diagram.
18 Clusters - contA number of operations exist for clusters, the most important of which are the bundling and unbundling operations. Individual pieces of data flowing through different wires can be bundled together to form a cluster that flows through a single wire. Likewise, a cluster flowing through a single wire can be unbundled so that its elements can flow through their own wires.Cluster bundling and unbundling. The person cluster is unbundled to reveal its elements so that the age element can be increased by one. The data is then bundled again to create a new cluster with the updated values. Notice that the cluster elements are given by name here.
19 Clusters - contClustering is commonly used for two purposes. First, clusters help to logically group related data values together, thus supporting the object oriented idea of encapsulation. Second, clusters help to minimize the number of wires on the block diagram that flow into VIs. If clusters did not exist, VIs with cluster inputs would have to receive all of their data through separate wires leading to drastic decreases in readability.