53
LabVIEW Lecture 2 Ertugrul Karademir

LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

  • Upload
    hakiet

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

LabVIEW Lecture 2

Ertugrul Karademir

Page 2: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Case Structure

• Just like if...elseif...else

Page 3: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Case Structure

• Connect the case port

• Choose the condition you want to program

Page 4: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Case Structure

• You can add more cases by right clicking

Page 5: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Case Structure

• All terminals for all cases must by connected

This is empty

because, False

condition is not

wired

Page 6: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Variable Types

• There are basically three kinds of variable types:

1. Integers: One memory register is enough to store.

Bit value of the register defines the limits of

cardinality.

2. Floating point: more than one memory register is

needed (one to store base, one to store significant

digits, etc.)

3. String: Textual information. It is stored much like

Arrays. Actually a string is an array of characters

(which are integers with special meanings).

Page 7: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Variable Types

• When number 10 is stored as a String it is represented more or less like this:

x0000:DFEA

Length 2 x0000:FFAA

String “10”

Length 2

First Element x0000:FFAA

Second Element x0000:FFAB

x0000:FFAA

1

x0000:FFAB

0

Page 8: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Variable Types

• When number 10 is stored as an Integer it is represented more or less like this:

x0000:ADFF

Integer “10”

x0000:ADFF

10

Page 9: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Variable Types

• Controls we use to

communicate with

instruments need and

produce String data.produce String data.

• Numerical values need to be

converted approriately (type

casting).

Page 10: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

String Operations

•Find your way in string palette

•It’s intuitive

•Don’t forget to trim whitespace out of returned

data from the instrument

Page 11: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

More Complex Topics

• From here on we focus on more complex

topics:

– Arrays

– File Input Output– File Input Output

– Data Acquisition

Page 12: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Modern Palette

Sometimes we need more than what Express palette

offers

Page 13: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

• Arrays are created as empty shells

• In order to assign a type you should drop in a

control.

• Array casts into the dropped control’s type.• Array casts into the dropped control’s type.

Page 14: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

Array, Matrix

& Cluster

palette has

the empty the empty

array shell.

Page 15: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

ArraysCreate an empty array shell

LabVIEW creates a proxy for that array in block diagram

Page 16: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

•Invoke Numeric

Palette under

Modern

•Drop a Numeric

Control inside the Control inside the

empty box of the

Array shell

Page 17: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

ArraysNow the array has a type

So does its proxy

Page 18: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

•You can expand the array container to show more

elements at once

•Or click to the pager buttons to change the starting

index

Page 19: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

• Note that there is no array INDICATOR

• That is because you indicate that an Array is

an indicator by dropping in an indicator inside

that array shellthat array shell

It is an indicator

Page 20: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

You can also create Array constants

Programming Palette > Array Palette >

Array Constant

Drop an integer

constant inside and get

integer array

Page 21: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

•Arrays palette has many useful Array functions.

•Like getting the size of an array

Page 22: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

Get an element at a specific index.

Page 23: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

Or several indices (expand the icon)

Page 24: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

Replace some elements

Page 25: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

Concatenate

Page 26: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Arrays

You can add dimensions to an array by right clicking

onto the container

Page 27: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

ArraysOr from array properties.

Page 28: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

ArraysYou can build more dimensional arrays by using Build Array

function

Note that front panel representation has changed into row-wise

indication rather than column-wise.

0,0 0,1

1,0 1,1

Page 29: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

File I/O

•LabVIEW allows extensive use

of file stream operations

•We’ll only use Write •We’ll only use Write

Spreadsheet function

Page 30: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

File I/OAll operations are

done in Block

Diagram

Note that we’ve Note that we’ve

transposed input

data

Page 31: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

File I/O

Page 32: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

File I/O

Once saved, we can use this data in other

applications like MATLAB or Origin

Page 33: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

More

Besides Programming palette, LabVIEW has an

extensive selection of Mathematical fuctions

under Mathematics palette.

Page 34: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

More

You may need some functions under Probability &

Statistics palette.

Page 35: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Data Acquisition

• What LabVIEW does best

• There are many ways to communicate with

instruments:

– GPIB– GPIB

– RS232 / Serial Port

– LPT / Parallel Port

– USB

– TCP/IP

Page 36: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

GPIB

• Standardized as IEEE-488

• a.k.a. HP-IP; Hewlett Packard/General Purpose

Interface Bus

• Has deep similarities to parallel port• Has deep similarities to parallel port

• 15 instruments can be connected to one bus

Pics: Wikipedia

Page 37: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

GPIB

• Every instrument has it, even the very old

ones

Page 38: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Connection

• Every instrument has a different

– Command set

– Data I/O pipeline

– Response time– Response time

– Buffer size

– ...

• What to do?

– RTFM

Page 39: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Connection

• Internet is a good source for instrument

manuals, even the old ones

• Generally instrument vendor site is enough

– unless it stopped manufacturing that device or – unless it stopped manufacturing that device or

upgraded with a new model

– even then, decent vendors have an archive for old

documents

• Find a manual or you waste your time by

guessing the command set!

Page 40: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Connection• Seek for the computer interface chapter

Page 41: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Connection

• Of course understanding the command set has a prerequisite of understanding the instrument itself.instrument itself.

• Learn the instrument

• Learn what to do, without the computer

• Apply the scheme to LabVIEW

Page 42: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Connection

• You can check the status of the instrument by

employing Measurement and Automation Explorer

Page 43: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• There is a general scheme of instrument interfacing:

0) Handshake

1) Busy?1) Busy?

2) No

3) Write “FREQ?” to buffer

5) Ready

6) Read Buffer

4) Poll

Page 44: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• Seek Instrument I/O palette

• Choose an appropriate way from many

Page 45: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• All actions that are needed can be found

under that palette.

• You can do more advance stuff by invoking the

advanced palette (488.2 in this case)advanced palette (488.2 in this case)

Page 46: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• For modern instruments read and write

actions are enough

Page 47: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• To send a command to the instrument use Write action

• You need the GPIB address of the instrument

Page 48: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• To get the result of your command use Read

action

Page 49: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• There is an error in this code. Can you guess?

Page 50: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Instrument I/O

• Much better

Page 51: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Error Handling

• Simple error handling can be easily done by

employing Simple Error Handler

Page 52: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Error Handling

Page 53: LabVIEW Lecture 2 - Bilkent Universityphysics/phys580/files/LabVIEW_Lecture_2.pdf · LabVIEW Lecture 2 Ertugrul Karademir. ... LabVIEW creates a proxy for that array in block diagram

Error Handling

• You may not want to be bothered by some

timeout error