cs320n –visual programming labview foundations. visual programminglabview foundations2 what we...

43
CS320n –Visual Programming LabVIEW Foundations

Upload: howard-malone

Post on 19-Dec-2015

247 views

Category:

Documents


4 download

TRANSCRIPT

CS320n –Visual Programming

LabVIEW Foundations

Visual Programming LabVIEW Foundations 2

What We Will Do Today• Hand back and review the midterm

• Look at the basic tools in the LabVIEW programming environment

Visual Programming LabVIEW Foundations 3

LabVIEW Programming Elements

• Controls and Indicators arranged on palettes according to function

• Controls = inputs (from user or other devices) = source terminals

• Indicators = outputs = destinations or sinks

• They are not interchangeable

Visual Programming LabVIEW Foundations 4

Controls• On front panel

– White background– values may be typed in– Increment / decrement

control• can hide by right clicking,

selecting visible items, and unchecking

• On Block Diagram– thick border– arrow on right hand side,

going out of icon

Visual Programming LabVIEW Foundations 5

Indicators• On front panel

– background is gray– no way to type in value

• On block diagram– thin border– arrow on left hand side,

going into icon

• DBL indicates data type is a double, a number with a fractional component

Visual Programming LabVIEW Foundations 6

Adding Components on Front Panel

• Express view of palette

• Change to advanced view by clicking options button and selecting Advanced from pull down menu for Palette View

Visual Programming LabVIEW Foundations 7

Selecting Advanced View

• Advanced View of front panelpalette

• When mouse rolls over buttontitle of sub palette shown

Visual Programming LabVIEW Foundations 8

Adding Components• Clicking on a button for a sub

palette brings up that sub palette

• Get back to the previous palette using the up arrow

• right clicking on a palette button brings up the sub palette while keeping the original palette visible

Visual Programming LabVIEW Foundations 9

Adding Components• Once correct component

found click on it and drag to front panel

• Adding to front panel places corresponding terminal on the block diagram

• can alter characteristics of component by right clicking on it or

• alter font by selecting text and change Text Settings– can change label and value in

control / indicator

Visual Programming LabVIEW Foundations 10

Making Things Pretty• Components on front Panel can be aligned

and distributed

• Select components by clicking mouse and dragging box around them

align objects distribute objects resize objects

Visual Programming LabVIEW Foundations 11

Wires• Data is moved around a LabVIEW

program via wires

• Wires are placed on the block diagram

• Wires take information from controls to nodes and indicators

• Wires are color coded based on the type of data they carry

Visual Programming LabVIEW Foundations 12

Wire Color Scheme• Wires have a color and a width based on

data type and data structure

• data types– floating point numbers, integer numbers,

Booleans, Strings

• data structures– scalar (single value), array (list of values), 2D

array (table of values)

Visual Programming LabVIEW Foundations 13

Wire Color Scheme

Integer Floating Point Boolean String

Scalar

Array

2D Array

Visual Programming LabVIEW Foundations 14

Wiring Components• LabVIEW has an automatic tool selection

option. (Selected by default)

• Cursor turns into tool necessary based on position of cursor

• When cursor moved over terminal it becomes a spool of wire

• click to start wiring

• drag wire from one terminal to another

Visual Programming LabVIEW Foundations 15

Adding Wires

Wire Icon

Wire from output of controlto input of indicator

Visual Programming LabVIEW Foundations 16

Broken Wires• Errors in wiring are

shown graphically– loose ends– incorrect data

types– too many wires

Visual Programming LabVIEW Foundations 17

Help• Context Help is a feature of LabVIEW to

provide help based on the situation you are in

• enable context help by pressing control and H or by selecting the “Help” menu and selecting “Show Context Help”– Tries to explain errors– shows information about icons / controls /

indicators / data type of wire / sub VIs

Visual Programming LabVIEW Foundations 18

Nodes• Nodes are program execution elements

• Like actions in Alice or statements in text based languages

• Nodes exist for all sorts of operations, from simple to complex

• add

• transpose the elements of a table

Visual Programming LabVIEW Foundations 19

Data flow• LabVIEW programs are driven by data

flow

• operations are not performed until the data to perform them is available

• Alice (and most text based languages) use sequential flow of control– statements executed in the order they appear

in the program

Visual Programming LabVIEW Foundations 20

Example of Data Flow• Which gets executed first the add operation or the

divide operation?

• The answer is, it depends.– On which operation has the data to perform the

operation first– Sometimes when the program is run the add could be

performed first and other times it could be the multiplication

Visual Programming LabVIEW Foundations 21

Cascading Data Flow• Outputs of nodes can be feed to other nodes• (x + y) x y2• multiplication not performed until addition complete

Visual Programming LabVIEW Foundations 22

Multiple Inputs and Outputs• Operations (nodes) in LabVIEW can have

more than input and more than one output

• multiple outputs are like multiple parameters in an Alice method or function

• Alice functions had no equivalent to the multiple outputs

Visual Programming LabVIEW Foundations 23

Example of Multiple Inputs and Outputs

• In Range and Coerce

• 3 inputs, 2 outputs

• explanation of inputs and outputs available on context help

Visual Programming LabVIEW Foundations 24

sub VIs• As virtual instruments are created they can

be used like the built in components

• packaged into a sub program

• create an icon with inputs and outputs– analogous to class level methods in Alice– code reuse

• LabVIEW contains a large library of sub VIs

Visual Programming LabVIEW Foundations 25

Example• Temperature conversion

• Celsius to Fahrenheit

• Degrees Fahrenheit = (1.8 * Degrees Celsius) + 32

• Input -> degrees Celsius

• Output -> degrees Fahrenheit

Visual Programming LabVIEW Foundations 26

Conversion Formula• Two ways to handle formula

1. Use the primitive nodes and numerical constants

2. Use the formula express option

Visual Programming LabVIEW Foundations 27

First Option

1.

4.

2.

3.

Visual Programming LabVIEW Foundations 28

Bad Wires• If a wire connection is bad the wire will not

be solid, but a dashed line

Visual Programming LabVIEW Foundations 29

Incorrect Programs• A LabVIEW program that has wiring (or other format

errors) cannot be run• Clicking on the broken arrow brings up a list of errors• Clicking on an error displays more information about the

error• Edit menu has “Remove Broken Wires” option or

<Control B>

Visual Programming LabVIEW Foundations 30

Adding Components Automatically

• Some components can be added automatically instead of from a palette

• In the temperature example– after adding the multiplication node right click

on one input– from the pop up menu select “Create” and

then “Constant”

Visual Programming LabVIEW Foundations 31

Changing Labels• When component added to front panel it is given

a default name• change name to be more descriptive

• After entering text click off of control or press <shift-enter> to finish

• Changes label on corresponding componen

Visual Programming LabVIEW Foundations 32

Free Labels• Not attached to a component

• For describing things about a program

Visual Programming LabVIEW Foundations 33

Second Option

Visual Programming LabVIEW Foundations 34

Formula Editor

Visual Programming LabVIEW Foundations 35

Result of Second Option

Visual Programming LabVIEW Foundations 36

Another Exercise• Simulate rolling a pair of dice

Visual Programming LabVIEW Foundations 37

Expected Output?

• What next?

Visual Programming LabVIEW Foundations 38

Expected Output?

Visual Programming LabVIEW Foundations 39

Rounding

Visual Programming LabVIEW Foundations 40

Making Two Dice• Copy and paste many

components

Visual Programming LabVIEW Foundations 41

Finished Product

Visual Programming LabVIEW Foundations 42

Always Another Way

Visual Programming LabVIEW Foundations 43

Both Methods