labview tutorials

Upload: chris-mmata

Post on 05-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 LabVIEW Tutorials

    1/6

    Lesson 1

    Objective

    This lesson introduces the LabVIEW environment and the G programming model. Core concepts, such as

    the flow of data from sources to sinks on the block diagram, are presented with supporting examples.

    Some of the many common block diagram structures and front panel widgets are also detailed in this

    lesson.

    Index

    Virtual instrumentsFront panel

    Block diagram

    Controls

    Indicators

    Palettes

    Structures

    While-loops

    Case structures

    Projects

    Download

    Instruction

    Virtual instruments

    LabVIEW 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 theycan contain any number of internal or user created VIs in an endless number of configurations.

    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).1.

    The program executes an addition VI taking the user's number and the number 10 as its inputs (data

    sink).

    2.

    The addition VI returns the result of the addition operation (data source).3.

    The result is displayed on the screen (data sink).4.

    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.

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...

    6 2/17/2012 4:55 PM

  • 8/2/2019 LabVIEW Tutorials

    2/6

    Front Panel

    Every 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.

    Block diagram

    Nearly 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.

    Controls

    The 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.

    Figure 1: Typical controls and their associated data types. In general, any control can be turned into an

    indicator and vice-versa.

    Indicators

    The 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.

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...

    6 2/17/2012 4:55 PM

  • 8/2/2019 LabVIEW Tutorials

    3/6

    Figure 2: Typical indicators and their associated data types. In general, any control can be turned into an

    indicator and vice-versa.

    Figure 3: The front panel and block diagram for the simple number plus ten example given above. It

    should be noted that the number control and answer indicator have their similarly named analogs on the

    block diagram.

    Palettes

    Front 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.

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...

    6 2/17/2012 4:55 PM

  • 8/2/2019 LabVIEW Tutorials

    4/6

    Figure 4: Typical top-level block diagram and front panel palettes.

    Structures

    In 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 performtraditional 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,

    some of which will be introduced within these lessons--while-loops, case structures, event structures,

    for-loops, sequence structures, and formula nodes.

    While-loops

    One 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 contains its own loop counter the provides the

    current loop iteration starting at zero.

    Figure 5: 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. More on parallel execution will be discussed in Lesson 2.)

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...

    6 2/17/2012 4:55 PM

  • 8/2/2019 LabVIEW Tutorials

    5/6

    The 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. (Thankfully, the use of the

    delay VI has been superseded by the new event structure discussed in another tutorial.)

    Figure 6: 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.

    Nearly 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, powerfuloptions are available for shaping data flowing through tunnels, most of which will be discussed in the next

    lesson.

    Figure 7: 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.

    Case structures

    Another 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 byclicking on the arrows to the left or the right of the case name.

    Figure 8: 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.

    Projects

    Project 1a

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...

    6 2/17/2012 4:55 PM

  • 8/2/2019 LabVIEW Tutorials

    6/6

    Create a VI called Project1a.vi. The VI should simply multiply two numbers together and display

    the result once when the program is run.

    Improve the Project1a VI so that it loops infinitely and allows a user to change the two input

    numbers on the fly.

    Project 1b

    Create a VI called Project 1b.vi that has a boolean control and a string indicator on the front panel.When the boolean control is true, the string indicator should read True. When the boolean control is

    false, the string indicator should read False.

    Add another boolean control to the front panel. Use an AND operation on the two values of the

    boolean controls. Have the string indicator display the correct result of the AND operation. For

    example, if one boolean control is true and the other is false, the string indicator should read False.

    Download

    To download all of the examples and project solutions from this lesson click this link.

    VIEW Tutorials http://www.cipce.rpi.edu/programs/remote_experiment/labview/lesson1...