LabVIEW Basics II Slides

  • Upload
    suhel

  • View
    35

  • Download
    5

Embed Size (px)

DESCRIPTION

labview

Citation preview

  • 1LabVIEW Basics II

    LabVIEW Basics II: Development

    11500 North Mopac ExpresswayAustin, Texas 78759

    ni.com/training

    What You Need To Get Started

    LabVIEW Basics II Course Manual LabVIEW Basics II Course CD Multifunction DAQ device

    ni.com/training

    Computer running LabVIEW 8.6 or later

    and Windows 2000 or later

    Multifunction DAQ device DAQ Signal Accessory, wires, and cable

    File Locations

    The course installer places the course files in the following location:

    Exercises LabVIEW

    ni.com/training

    Root Directorye c ses

    SolutionsLabVIEW Basics II

    Instructional Methods

    Lecture gives a foundation in the topic

    Instructor reinforces foundation through

    TopicLecture

    Quizzes

    Demonstrations

    Concept Exercise

    Development Exercise

    ni.com/training

    demonstrations and quizzes Use concept exercises to further explore a topic Watch a simulation, experiment with example VIs

    Use development exercises to gain hands-on experience Demonstration of a finished development exercise further

    reinforces the learning process

    Getting The Most Out Of This Course

    Experiment with hands-on exercises to understand the methods used

    Implementations explore a possible solutionyou may find a better one

    ni.com/training

    Do not come to class prepared to develop an outside application; concentrate on the exercises given to build a good foundation

    Courses

    New User

    LabVIEW Basics I

    LabVIEW Basics II

    Experienced User

    LabVIEW Intermediate I

    LabVIEW Intermediate II

    Advanced User

    LabVIEW Advanced I

    Skills learned: LabVIEW environment

    navigation Basics application creation

    using LabVIEW Basics of data acquisition and

    Skills learned: Modular application

    development Structured design and

    development practices Inter-application

    Skills learned: Large application design Advanced development

    techniques Implementing multideveloper

    projects

    ni.com/training6

    Certifications

    Certified LV Associate Developer Exam

    Skills tested: LabVIEW environment

    knowledge

    Certified LabVIEW Developer Exam

    Skills tested: LabVIEW application

    development expertise

    Certified LabVIEW Architect Exam

    Skills tested: LabVIEW application

    development mastery

    Basics of data acquisition and instrument control

    Inter-application communication and connectivity techniques

    projects

  • 2Course Learning Map

    Lesson 2

    Communicating Among Multiple Loops

    Lesson 1

    Common Design Techniques

    Lesson 6

    Advanced File I/O

    Lesson 5

    Controlling the User Interface

    ni.com/training

    Lesson 4

    Improving an Existing VI

    Lesson 3

    Event ProgrammingLesson 7

    Creating & Distributing an Executable

    Course Goals

    This course prepares you to: Design, implement and distribute stand-alone applications Apply single and multiple loop design patterns Use event programming effectively

    ni.com/training

    Use event programming effectively Programmatically control user interface objects Apply data management techniques Optimize reuse of existing code for your projects

    TOPICS

    Lesson 1Common Design Techniques

    ni.com/training

    A. Single Loop ArchitecturesB. ParallelismC. Multiple Loop ArchitecturesD. EventsE. Timing a Design Pattern

    A. Single Loop Architectures

    Simple Single VI that takes a measurement, performs calculations,

    and either displays the results or records them to disk Usually does not require a specific start or stop action from

    ni.com/training

    ythe user

    10

    A. Single Loop Architectures

    General VI Three phases: Start-up, Main Application, and Shut-down

    ni.com/training11

    A. Single Loop Architectures

    General VI

    ni.com/training12

  • 3A. Single Loop Architectures

    State Machine Usually has a start-up and shut-down state, but also

    contains other states

    ni.com/training13

    A. Single Loop Architectures

    State Machine

    ni.com/training14

    B. Parallelism

    Execute multiple tasks at the same time

    ni.com/training15

    B. Parallelism

    Passing data among parallel loops is a challengeHow do the loops stop in this example?

    ni.com/training16

    B. Parallelism

    How do the loops stop in this example?

    ni.com/training17

    B. Parallelism

    Read the Stop button from a file Each loop independently accesses the file However, reading and writing to files can consume much

    processor time

    ni.com/training

    p

    18

  • 4C. Multiple Loop Architectures

    Parallel Loop

    ni.com/training19

    C. Multiple Loop ArchitecturesProducer/Consumer

    ni.com/training20

    D. Events

    What are events? Influence block diagram execution with events Events are an asynchronous notification indicating that

    something occurred

    ni.com/training

    g Events originate from the user interface, external I/O, or

    other parts of the program

    User Actions on the Front Panel

    Sy

    D. Events

    Why use events?

    ni.com/training

    Block Diagram Execution

    ynchronize

    D. Events

    Event Programming

    ni.com/training23

    Execution

    E. Timing a Design Pattern - Execution

    Execution Timing Provides the design pattern with a function that specifically

    allows the processor time to complete other tasks In some cases, a function is not necessary

    ni.com/training

    y

    24

  • 5E. Timing a Design Pattern Execution

    ni.com/training25

    E. Timing a Design Pattern Software Control

    Software Control Timing Consider implementing a state machine design pattern for

    a data acquisition system If you must acquire data for 5 minutes, you could remain in

    ni.com/training

    y q ythe acquisition state until the 5 minutes elapses

    However, during that time you cannot process any user interface actions such as stopping the VI

    To process user interface actions, you must implement timing so that the VI continually executes for the specified time

    26

    E. Timing a Design PatternExecution Timing

    ni.com/training27

    Software Control Timing

    SummaryQuiz

    Are the following statements True or False? Software control timing allows the processor time to

    complete other tasks. Execution timing allows the processor time to complete

    ni.com/training

    gother tasks.

    You can use a wire to pass data among parallel loops.

    28

    SummaryQuiz Answers

    Are the following statements True or False? False. Software control timing is a method for monitoring a

    real-time clock. True. Execution timing allows the processor time to

    ni.com/training

    g pcomplete other tasks.

    False. If you pass data between two loops with a wire, the loops no longer run in parallel.

    29

  • 1TOPICS

    Lesson 2Communicating Among Multiple Loops

    ni.com/training

    A. VariablesB. Functional Global VariablesC. Race ConditionsD. Synchronizing Data

    A. Variables

    Cannot pass data between parallel loops with a wire Variables allow you to circumvent normal dataflow by

    passing data from one place to another without connecting the two places with a wire

    ni.com/training2

    A. Variables

    Variables are block diagram elements that allow you to access or store data in another location

    Variables can be of the following types: Local: store data in front panel controls and indicators

    ni.com/training

    Global: store data in special repositories that can be accessed from multiple VIs

    Functional Global: store data in While Loop shift registers Shared: transfers data between various distributed targets

    connected together over a network

    3

    A. Variables Using in a Single VI

    Use local variables to pass data within a single VI

    ni.com/training4

    Demo: Creating Local Variables

    ni.com/training

    GOAL

    Create and use local variables.

    5

    A. Variables Using Between VIs

    Use a global variable or a single process shared variable to share data between multiple VIs Use a global variable to share data among VIs on the same

    computer, especially if you do not use a project file

    ni.com/training

    Use a single process shared variable if you may need to share the variable information among VIs on multiple computers in the future

    6

  • 2Demo: Creating Global Variables

    ni.com/training

    GOAL

    Create and use global variables.

    7

    Demo: Creating Shared Variables

    ni.com/training

    GOAL

    Create and use single process shared variables.

    8

    A. Variables Using Carefully

    ni.com/training9

    A. Variables Using Carefully

    ni.com/training10

    A. Variables Initializing

    Verify that variables contain known data values before the VI runs

    If you do not initialize the variable before the

    ni.com/training

    VI reads it for the first time, it contains the default value of the associated front panel object

    11

    A. Variables Initializing

    ni.com/training12

  • 3B. Functional Global Variables

    The general form of a functional global variable includes an uninitialized shift register (1) with a single iteration For or While Loop

    ni.com/training13

    1

    B. Functional Global Variables

    A functional global variable usually has an action input parameter that specifies which task the VI performs

    The VI uses an uninitialized shift register in a While Loop to hold the result of the operation

    ni.com/training14

    B. Functional Global Variables Timing

    Very useful for performing customized elapsed time measurements

    ni.com/training15

    Exercise 2-1: Variables VI

    ni.com/training

    GOAL

    Use variables to write to and read from a control.

    16

    Exercise 2-2: Global Data Project

    ni.com/training

    GOAL

    OPTIONALCreate a project containing multiple VIs that share data using a single process shared variable.

    17

    C. Race Conditions

    A race condition is a situation where the timing of events or the scheduling of tasks may unintentionally affect an output or data value

    Race conditions are a common problem for programs that

    ni.com/training

    execute multiple tasks in parallel and share data between the tasks

    18

  • 4Demo: Race Conditions

    ni.com/training

    GOAL

    Watch the instructor demonstrate race conditions.

    C:/Exercises/LabVIEW Basics II/Demonstrations

    19

    C. Race Conditions

    Race conditions are very difficult to identify and debug Often, code with a race condition can return the same

    result thousands of times in testing, but still be capable of returning a different result

    ni.com/training

    Avoid race conditions by: Controlling shared resources Properly sequencing instructions Identifying and protecting critical sections within your code Reducing use of variables

    20

    C. Race Conditions Shared Resources

    ni.com/training21

    C. Race Conditions Critical Code

    A critical section of code is code that may behave inconsistently if some shared resource is altered while it is running

    If one loop interrupts another loop while it is executing

    ni.com/training

    critical code, then a race condition can occur Eliminate race conditions by identifying and protecting

    critical code with: Functional Global Variables Semaphores

    22

    C. Race Conditions Critical Code

    ni.com/training23

    C. Race Conditions Critical Code

    Functional Global Variable used to protect critical code:

    ni.com/training24

  • 5C. Race Conditions Critical Code

    ni.com/training25

    C. Race Conditions Sequencing

    What is the final value?Four possible outcomes: Value = (Value * 5) +2 Value = (Value + 2) * 5

    ni.com/training

    Value (Value 2) 5 Value = Value * 5 Value = Value +2

    26

    Exercise 2-3: Bank VI

    ni.com/training

    GOAL

    Eliminate a race condition by protecting a critical section of code.

    27

    D. Synchronizing the Transfer of Data

    Variables are one method for passing data between parallel processes

    Using variables breaks the LabVIEW dataflow paradigm, allows for race conditions, and incurs more overhead

    ni.com/training

    than passing the data by wire

    28

    D. Synchronizing the Transfer of Data

    ni.com/training29

    Demo: Notifiers

    ni.com/training

    GOAL

    Open the Master/Slave Design Pattern template in LabVIEW and explore the operation of Notifiers.

    30

  • 6D. Synchronizing the Transfer of Data

    The following benefits result from using Notifiers to transfer data between parallel loops: Both loops are synchronized to the master loopthe slave

    loop only executes when the master loop sends a

    ni.com/training

    notification You can use Notifiers to create globally available data,

    making it possible to send data with a notification Using Notifiers creates efficient codethere is no need to

    poll to determine when data is available from the master loop

    31

    D. Synchronizing the Transfer of Data

    Notifier disadvantages: A notifier does not buffer data If the master loop sends another piece of data before the

    first piece of data has been read by the slave loops, that

    ni.com/training

    p y pdata is overwritten and lost

    32

    D. Synchronizing the Transfer of Data

    Queues are similar to notifiers, except that a queue can store multiple pieces of data

    By default, queues work in a FIFO (first in, first out) manner Use a queue when you want to process all data placed in

    ni.com/training

    ythe queue

    Use a notifier if you only want to process the current data

    33

    D. Synchronizing the Transfer of Data

    ni.com/training34

    Demo: Queues

    ni.com/training

    GOAL

    Open the Producer/Consumer Design Pattern (data) template in LabVIEW and explore the operation of Queues.

    35

    Demo: Weather Station

    ni.com/training

    GOAL

    Demonstrate the use of queues for data transfer and synchronization of parallel loops.

    C:/Exercises/LabVIEW Basics II/Demonstrations/Case Study - Queue

    36

  • 7Exercise 2-4: Queues vs Local Variables VI

    ni.com/training

    GOAL

    Examine a built-in producer/consumer design pattern VI that uses queues to avoid race conditions and synchronize the data transfer between two independent parallel loops.

    37

    SummaryQuiz

    1. You should use variables in your VI where ever possible.a) True b) False

    ni.com/training38

    SummaryQuiz Answer

    1. You should use variables in your VI where ever possible.a) True b) False

    ni.com/training39

    SummaryQuiz

    2. Which cannot transfer data?a) Semaphores b) Functional global variablesc) Notifiers d) Q

    ni.com/training

    d) Queues

    40

    SummaryQuiz Answer

    2. Which cannot transfer data?a) Semaphores b) Functional global variablesc) Notifiers d) Q

    ni.com/training

    d) Queues

    41

    SummaryQuiz

    3. Which can you use only within a project?a) Local variableb) Global variable c) Functional global variable d) Si l h d i bl

    ni.com/training

    d) Single-process shared variable

    42

  • 8SummaryQuiz Answer

    3. Which can you use only within a project?a) Local variableb) Global variable c) Functional global variable d) Si l h d i bl

    ni.com/training

    d) Single-process shared variable

    43

    SummaryQuiz

    4. Which cannot be used to pass data between multiple VIs?a) Local variableb) Global variable c) Functional global variable d) Si l h d i bl

    ni.com/training

    d) Single-process shared variable

    44

    SummaryQuiz Answer

    4. Which cannot be used to pass data between multiple VIs?a) Local variableb) Global variable c) Functional global variable d) Si l h d i bl

    ni.com/training

    d) Single-process shared variable

    45

  • 1TOPICS

    Lesson 3: Event Programming

    ni.com/training

    A. Event Driven ProgrammingB. Event Based Design Patterns

    The Event Structure

    Examples of User Interface (Static) Events Pressing a button on the

    mousePressing a ke on the

    ni.com/training

    Pressing a key on the keyboard

    Value (Signaling) Property can generate a programmatic event

    Parts of an Event Structure

    Event Selector Label identifies event case viewed Timeout value in ms to wait for events; default value is 1

    (indefinite) Dynamic Event Terminals used for dynamic event registration Default Tunnel Values

    ni.com/training

    Default Tunnel Values new type of tunnel which allows unwired cases to provide default values

    Parts of an Event Structure (continued)

    Event Data Node identifies the data LabVIEW provides when the event occurs; similar to the Unbundle By Name functionEvent Filter Node identifies the subset of data available in the Event Data Node that the event case can modify

    ni.com/training

    Event Structure Basic Usage

    Normally used in a While Loop Sleeps and handles exactly one event per iteration Event Data available in terminals on structures left border Can right-click on Event

    ni.com/training

    Can right click on Event Data and show only the terminals you need

    Event Structure Configuration

    ni.com/training

    Use a dialog box to configure events byright-clicking the Event structure border and selecting Edit Events Handled by This Case from the shortcut menu

  • 2Edit Events Dialog

    1. Configured Events

    2. Event Sources

    3. Events

    1

    ni.com/training

    32

    Notify Events (green arrow)Notifies LabVIEW that a user action has already occurred; available only in the Event Data Node

    Notify and Filter Events

    ni.com/training

    Filter Events (red arrow)Validates or changes the event data before the user interface can process it; available in the Event Filter Node and Event Data Node

    Event Registration and Panel Locking

    Events are registered when a VI with an Event structure on its block diagram becomes reserved

    When a registered event occurs, it is queued until the Event structure(s) configured for it executes

    ni.com/training

    It is not possible to miss events or process them out of order

    By default, the front panel is locked until the event is handled You can turn off locking, but only for Notify Events

    Events are unregistered when the VI becomes idle

    Exercise 3-1: Experiment with Event Structures

    ni.com/training

    GOAL

    ConceptExperiment with the operation of the Event Structure in a VI.

    Event-Based Design Pattern

    Use the user interface event handler design pattern for detecting when a user changes the value of a control, moves or clicks the mouse, or presses a key

    The user interface event handler allows you to minimize

    ni.com/training

    processor use without sacrificing interactivity

    User Interface Event Handler

    1. Event StructureConfigure the Event structure to have one frame for each category of event you want to detect

    2. While Loop3. Timeout Terminalallows you to control when the Timeout event

    executes

    ni.com/training

    executes4. Event Data Node 3

    2

    1

    4

  • 3Producer/Consumer (Events)

    Benefits Efficiently

    responds asynchronously to the user

    ni.com/training

    interface Queues can

    transfer any data type

    Exercise 3-2: Experiment with Event-Based Design Patterns

    ni.com/training

    GOAL

    ConceptObserve the functionality and design of event-based LabVIEW design patterns

    SummaryQuiz

    1. True or False? Event Structures are normally used in While Loops.

    ni.com/training15

    SummaryQuiz Answer

    1. Event Structures are normally used in While Loops. True.

    ni.com/training16

    SummaryQuiz

    2. Which of the following are examples of user interface events?a) Mouse clickb) Keystroke

    ni.com/training

    ) yc) Event Filter Noded) Value change of a control

    17

    SummaryQuiz Answer

    2. Which of the following are examples of user interface events?a) Mouse clickb) Keystroke

    ni.com/training

    ) yc) Event Filter Noded) Value change of a control

    18

  • 4SummaryQuiz

    3. True or False? Using user interface events allows you to synchronize user actions on the front panel with block diagram execution.

    ni.com/training19

    SummaryQuiz Answer

    3. Using user interface events allows you to synchronize user actions on the front panel with block diagram execution. True.

    ni.com/training20

  • 1TOPICS

    Lesson 4Controlling the User Interface

    ni.com/training

    A. VI Server ArchitectureB. Property NodesC. Control ReferencesD. Invoke Nodes

    A. VI Server Architecture

    VI Server performs many functions; however, this lesson concentrates on using VI Server to control front panel objects and edit the properties of a VI

    ni.com/training2

    A. VI Server Architecture

    Terminology: An object is a member of a class A class defines what an object is able to do, what

    operations it can perform (methods), and what properties it

    ni.com/training

    ( )has

    Methods perform an operation on an object Properties are the attributes of an object

    3

    A. VI Server Architecture Example

    Control ClassProperty: VisibleMethod: Reinitialize to Default

    Array Sub-ClassBoolean S b Class

    Control

    ni.com/training4

    Array Sub ClassProperty: Number of Rows

    Boolean Sub-ClassProperty: Boolean Text

    Stop ObjectVisible: YesReinitialize to Default: NoBoolean Text: Stop

    Boolean

    Stop

    Array

    A. VI Server Architecture

    Control Classes LabVIEW front panel objects inherit properties and methods

    from a specific control class VI Class

    ni.com/training

    Your VI belongs to the VI Class and has its own properties and methods associated with it

    Example Methods: abort your VI, adjust the position of the front panel, get an image of the block diagram

    Example Properties: change the title of your front panel window, retrieve the size of the block diagram, hide the abort button

    5

    B. Property Nodes

    Property Nodes access the properties of an object In some applications, you might want to modify the

    appearance of front panel objects programmatically in response to certain inputs

    ni.com/training

    If a user enters an invalid password, you might want a red LED to start blinking

    If a data point is above a certain value, you might want to show a red trace instead of a green one

    Property Nodes allow you to make these modifications programmatically

    6

  • 2Demo: Property Nodes

    ni.com/training

    GOAL

    Create a Property Node for a front panel object, choose a property to set and choose a property to read.

    7

    B. Property Nodes Execution Order

    Property Nodes execute in order from top to bottom If an error occurs on a terminal, the node stops at that

    terminal, returns an error, and does not execute any further terminals

    ni.com/training8

    Exercise 4-1: Temperature Limit VI

    ni.com/training

    GOAL

    Use Property Nodes to change the properties of front panel objects programmatically.

    9

    C. Control References Implicit vs. Explicit

    Main VIMain VI

    Implicitly Linked Property Node Explicitly Linked Property Node

    ni.com/training

    VI VI SubVI

    C. Control References

    A control reference is a reference to a front panel object Wire control references to

    generic Property Nodes Pass control references

    ni.com/training

    to subVIs

    11

    C. Control References Create SubVI

    To create explicitly-linked Property Nodes in a subVI:1. Create your VI2. Select the portion of the block

    diagram that will be in the subVI

    ni.com/training

    g3. Select EditCreate SubVI;

    LabVIEW automatically creates the control references needed for the subVI

    4. Customize and save the subVI

    12

  • 3C. Control References Create SubVI

    S bVI F t P l S bVI Bl k Di

    ni.com/training13

    SubVI Front Panel SubVI Block Diagram

    C. Control References Create yourself

    S bVI F t P l S bVI Bl k Di

    Control Reference

    ni.com/training14

    SubVI Front Panel SubVI Block Diagram

    Ctl Refnum

    C. Control References Selecting Class

    After you place a Control Refnum on the front panel of a subVI, specify the VI Server class of the control Right-click and select VI Server Class from the shortcut

    menu

    ni.com/training

    Specifies the type of control references that the subVI accepts

    In the previous example, Control was the VI Server class Allows the VI to accept a reference to any type of front panel

    control

    15

    C. Control References Selecting Class

    Specifying a more specific class for the refnum makes the subVI more restrictive

    For example, you can select Digital as the class, and the subVI can only accept references

    ni.com/training

    to numeric controls of the class Digital Selecting a more generic class for a control refnum allow it

    to accept a wider range of objects but limits the properties available

    16

    Exercise 4-2: Set Plot Names

    Set Plots.vi

    ni.com/training

    GOAL

    Use control references to create a subVI that modifies graph or chart properties.

    17

    D. Invoke Nodes

    Invoke Nodes access the methods of an object Use the Invoke Node to perform actions, or methods, on an

    application or VI Unlike the Property Node, a single Invoke Node executes

    ni.com/training

    p y gonly a single method on an application or VI

    18

  • 4Invoke Nodes

    To create an implicitly-linked Invoke Node, right-click the control and select CreateInvoke Node and choose a method

    An example of a method that is common to all controls is

    ni.com/training

    the Reinitialize to Default method The Waveform Graph has the

    method Export Image:

    19

    Exercise 4-3: Front Panel Properties VI

    ni.com/training

    GOAL

    Learn how to affect the attributes of a VI by using Property Nodes and Invoke Nodes.

    20

    SummaryQuiz

    1. For each of the following items, determine whether they operate on a VI class or a Control class.

    a. Format and Precisionb. Blinking

    ni.com/training

    c. Reinitialize to Default Valued. Show Tool Bar

    21

    SummaryQuiz Answer

    1. For each of the following items, determine whether they operate on a VI class or a Control class.

    a. Format and Precision: Controlb. Blinking: Control

    ni.com/training

    c. Reinitialize to Default Value: Controld. Show Tool Bar: VI

    22

    SummaryQuiz

    2. You have a GraphChart control refnum in a subVI. Which control references could you wire to the control refnum terminal of the subVI? (multiple answers)a. control reference of an XY Graph

    ni.com/training

    b. control reference of a Numeric Arrayc. control reference of a Waveform Chartd. control reference of a Boolean

    23

    SummaryQuiz Answer

    2. You have a GraphChart control refnum in a subVI. Which control references could you wire to the control refnum terminal of the subVI? (multiple answers)a. control reference of an XY Graph

    ni.com/training

    b. control reference of a Numeric Arrayc. control reference of a Waveform Chartd. control reference of a Boolean

    24

  • 1TOPICS

    Lesson 5Advanced File I/O Techniques

    ni.com/training

    A. File FormatsB. Binary FilesC. TDMS Files

    A. File Formats

    At their lowest level, all files written to your computers hard drive are a series of bits

    ni.com/training2

    Binary

    TDMSASCII

    A. File FormatsASCII TDMS Direct Binary

    Numeric Precision

    Good Best Best

    Share data

    Best (Any program easily) Better (NI Programs easily)

    Good (only with detailed metadata)

    ni.com/training

    Efficiency Good Best Best

    Ideal Use Share data with other programs when file space and numeric precision are not important

    Share data with programs whenstoring simple array data and metadata

    Store numeric data compactly with ability to random access

    B. Binary Files

    Use Binary File functions to interact directly with a binary file

    ni.com/training4

    B. Binary FilesBits/Bytes?

    A bit is a single binary value Each bit is either on or off and is represented by a 1 or a 0

    A byte is a series of 8 bits

    ni.com/training

    0 bit00000000 byte

    5

    B. Binary FilesStoring Boolean Values

    LabVIEW represents Boolean values as 8-bit values in a binary file

    Eight zeroes represents False [00000000], and any other value represents True [00000001], [01000111],

    ni.com/training

    [11111111], and so on Files are divided into byte-sized chunks, making them

    much easier to read and process

    6

  • 2B. Binary FilesStoring Boolean Values

    File ContentsMethod A00000001 00000001 00000000 00000001

    ni.com/training

    00000000 00000001

    Method B00101011

    7

    B. Binary FilesStoring Integers

    Binary Value U8 Value00000000 000000001 100000010 2

    ni.com/training

    00000010 211111111 255

    8

    B. Binary FilesStoring Integers

    Multi-byte integers are broken into separate bytes and are stored in files in either little-endian or big-endian byte order

    Using the Write to Binary File functions, you can choose whether you store your data in little-endian or big-endian

    ni.com/training

    format

    9

    U32 Value Little-endian Value Big-endian Value

    1 000000010000000000000000 00000000

    00000000 0000000000000000 00000001

    B. Binary FilesStoring Other Data Types

    Strings are stored as a series of unsigned 8-bit integers, each of which has a value in the ASCII Character Code Equivalents Table This means that no difference exists between writing strings

    ith th Bi Fil F ti d iti th ith th T t

    ni.com/training

    with the Binary File Functions and writing them with the Text File Functions

    Clusters are best represented in binary files by using Datalog Files

    10

    B. Binary FilesStoring Arrays

    Arrays are represented as a sequential list of the elements Element representation depends upon the element type A header contains a 32-bit integer representing the size of

    each dimension

    ni.com/training

    Example A 2D array with a header contains: row integer, column integer, then array data

    11

    B. Binary FilesSequential/Random Access

    Two methods of accessing data: Sequential AccessRead each item in order, starting at

    the beginning of a file Random AccessAccess data at an arbitrary point within

    ni.com/training

    y pthe file

    12

  • 3B. Binary FilesSequential Access

    To sequentially access all of the data in a file, you can call the Get File Size function and use the result to calculate the number of items in the file, based upon the size of each item and the layout of the file

    ni.com/training

    You can then wire the number of items to the count terminal of the Read from Binary File function

    13

    B. Binary FilesRandom Access

    Use the Set Position VI to set the read offset to the point in the file you want to begin reading

    The offset is in bytes; therefore, you must calculate the offset based upon the layout of the file

    ni.com/training14

    B. Binary FilesDatalog

    Datalog is a specific type of binary file, designed for storing a list of records to a file

    Each record is represented by a cluster and can contain multiple pieces of data with any data type

    ni.com/training15

    B. Binary FilesDatalog Random Access

    ni.com/training16

    Exercise 5-1: Bitmap File Writer VI

    ni.com/training

    GOAL

    Use Binary File I/O to write a file with a specified format.

    17

    C. TDMS Files

    TDMS Technical Data Management Streaming

    Use TDMS files for the following purposes:

    ni.com/training18

    Use TDMS files for the following purposes: To store test or measurement data To create a structure for grouping your data To store information about your data To read and write data at high speeds

  • 4C. TDMS Files

    TDMS file format: TDMS file Binary file (.tdms) that contains data and stores properties

    about the data

    ni.com/training

    TDMS_Index file Binary index file (*.tdms_index) that provides consolidated

    information on all the attributes and pointers in the TDMS file Speeds up access to the data while reading Automatically regenerated if lost

    TDMS file format internal structure is publicly documented

    19

    C. TDMS FilesData Hierarchy

    Channel Stores measurement signals or raw data in a TDMS file Each channel can have properties describing the data The data stored in the signal is stored as binary data on disk to

    di k d i ffi i

    ni.com/training

    conserve disk space and improve efficiency Channel Group Segment of a TDMS file that contains properties and one or more

    channels Use channel groups to organize your data and to store information

    that applies to multiple channels

    20

    C. TDMS Files

    Use TDMS Files in the following ways: Use the Write to Measurement File and Read from

    Measurement File Express VIs Allow you to quickly save and retrieve data from TDMS format

    ni.com/training

    Very little control over your data grouping and properties Use the TDM Streaming API Set of functions for opening, writing to, reading from, and

    closing TDMS files Allows you to organize your data into channel groups and

    channels

    21

    C. TDMS FilesTDM Streaming API

    ni.com/training22

    C. TDMS FilesWrite Data

    Streams data to the specified TDMS file Data subset to write is determined by group name and

    channel name(s) inputs

    ni.com/training23

    C. TDMS FilesRead Data

    Reads the specified TDMS file and returns data from the specified channel and/or channel group

    ni.com/training24

  • 5C. TDMS FilesSet Properties

    Sets the properties of the TDMS file, channel group, or channel

    ni.com/training25

    C. TDMS FilesGet Properties

    Returns the properties of the TDMS file, channel group, or channel

    ni.com/training26

    C. TDMS FilesFile Viewer

    Opens TDMS file and presents the file data in the TDMS File Viewer dialog box

    ni.com/training27

    C. TDMS FilesGrouping Data

    Carefully consider the best way to group your data, because the data grouping can have a significant impact on both the execution speed and implementation complexity of writes and reads

    ni.com/training

    Things you should consider when choosing a grouping scheme include the original format of your data and how you want to process or view the data

    28

    Exercise 5-2: TDMS Reader VI

    ni.com/training

    GOAL

    Learn how to read data from a TDMS file.

    29

    SummaryQuiz

    1. You need to store test results and organize the data into descriptive groups. In the future, you need to efficiently view the test results by group. Which file storage format should you use?

    a) Tab-delimited ASCIIb) Custom binary format

    ni.com/training

    b) Custom binary formatc) TDMSd) Datalog

    30

  • 6SummaryQuiz Answer

    1. You need to store test results and organize the data into descriptive groups. In the future, you need to efficiently view the test results by group. Which file storage format should you use?

    a) Tab-delimited ASCIIb) Custom binary format

    ni.com/training

    b) Custom binary formatc) TDMSd) Datalog

    31

    SummaryQuiz

    2. You need to write a program which saves Portable Network Graphics (PNG) image files. Which file storage method should you use?

    a) Storage file VIsb) Binary file functions

    ni.com/training

    b) Binary file functionsc) ASCII file VIsd) Datalog file VIs

    32

    SummaryQuiz Answer

    2. You need to write a program which saves Portable Network Graphics (PNG) image files. Which file storage method should you use?

    a) Storage file VIsb) Binary file functions

    ni.com/training

    b) Binary file functionsc) ASCII file VIsd) Datalog file VIs

    33

    SummaryQuiz

    3. You need to store data that other engineers will later analyze with Microsoft Excel. Which file storage format should you use?

    a) Tab-delimited ASCIIb) Custom binary formatc) TDMS

    ni.com/training

    c) TDMSd) Datalog

    34

    SummaryQuiz Answer

    3. You need to store data that other engineers will later analyze with Microsoft Excel. Which file storage format should you use?

    a) Tab-delimited ASCIIb) Custom binary formatc) TDMS

    ni.com/training

    c) TDMSd) Datalog

    35

    SummaryQuiz

    a) 00001010 00000000 00000000

    c) 00001010d) 01010000

    4. Which of the following is a little-endian representation of an unsigned 32-bit integer (U32) with a value of 10?

    ni.com/training

    00000000 00000000

    b) 00000000 00000000 00000000 00001010

    00000000 00000000 00000000

  • 7SummaryQuiz Answer

    a) 00001010 00000000 00000000

    c) 00001010d) 01010000

    4. Which of the following is a little-endian representation of an unsigned 32-bit integer (U32) with a value of 10?

    ni.com/training

    00000000 00000000

    b) 00000000 00000000 00000000 00001010

    00000000 00000000 00000000

    SummaryQuiz

    5. True or False? You can use the Binary File Functions to read ASCII files.

    ni.com/training38

    SummaryQuiz Answer

    5. You can use the Binary File Functions to read ASCII files. True.

    ni.com/training39

    SummaryQuiz

    6. True or False? TDMS Files store properties only at the channel or channel group level.

    ni.com/training40

    SummaryQuiz Answer

    6. TDMS Files store properties only at the channel or channel group level. False.

    ni.com/training41

  • 1TOPICS

    Lesson 6Improving an Existing VI

    ni.com/training

    A. Refactoring Inherited CodeB. Typical Issues

    A. Refactoring Inherited Code

    Inherited VIs may be poorly designed, making it difficult to add features later in the life of the VIRefactoring: Process of redesigning software to make it more readable

    ni.com/training

    g gand maintainable so that the cost of change does not increase over time

    Changes the internal structure of a VI to make it more readable and maintainable, without changing its observable behavior

    2

    A. Refactoring Inherited Code

    ni.com/training3

    A. Refactoring Inherited Code

    ni.com/training4

    A. Refactoring vs. Performance Optimization

    Changes that optimize the performance of a VI are not the same as refactoring

    Refactoring specifically changes the internal structure of a VI to make it easier to read, understand, and maintain

    ni.com/training5

    versus

    A. When to Refactor

    When you are adding a feature to a VI or debugging it There is value in a VI that functions, even if the block

    diagram is not readable Good candidates for complete rewrites:

    ni.com/training

    p VIs that do not function VIs that satisfy only a small portion of your needs

    6

  • 2B. Typical Issues

    When you refactor to improve the block diagram, make small cosmetic changes before tackling larger issues

    Improve Block Diagram

    Test VI

    ni.com/training

    For example, it is easier to find duplicated code if the block diagram is well organized and the terminals are well labeled

    7

    Add Features or Use VI

    Is VI Acceptable?

    Yes

    No

    B. Typical Issues

    The following issues can make it difficult to work with an inherited VI: Too disorganized Uses incorrect object names and poor icons

    ni.com/training

    j p Uses unnecessary logic Has duplicated logic Does not use data flow programming Has complicated algorithms Is too big

    8

    B. Typical Issues - Disorganized

    The block diagram is too disorganized Move objects within the block diagram Create subVIs for sections of the VI that are

    disorganized

    ni.com/training

    disorganized Place comments to improve readability

    9

    B. Typical Issues

    The block diagram uses incorrect object names and poor icons

    ni.com/training

    GoodBetter

    Best

    10

    B. Typical Issues

    The block diagram uses unnecessary logic

    ni.com/training11

    B. Typical Issues

    The block diagram uses duplicate logic Refactor the VI by creating a subVI for the duplicated logic

    ni.com/training12

  • 3B. Typical Issues

    The block diagram does not use dataflow programming Replace Sequence structures with state machines if

    appropriate Delete local variables and wire directly to controls or

    ni.com/training

    yindicators if possible

    13

    B. Typical Issues

    The block diagram has complicated algorithms

    ni.com/training

    Simplify:

    14

    B. Typical Issues

    The block diagram is too big (larger than the screen size) Refactor the VI to make it smaller Create subVIs for sections of code within the block diagram

    ni.com/training15

    Exercise 6-1: Typical Issues

    ni.com/training

    GOAL

    Concept ExerciseImprove an existing VI that is poorly designed.

    16

    SummaryJob Aid

    Use the following refactoring checklist to help determine if you should refactor a VI: The block diagram is too disorganized The block diagram contains incorrect object names and poor icons Th bl k di t i l i

    ni.com/training

    The block diagram contains unnecessary logic The block diagram contains duplicated logic The block diagram does not use dataflow programming The block diagram contains complicated algorithms The block diagram is too big

    17

  • 1TOPICS

    Lesson 7Creating and Distributing Applications

    ni.com/training

    A. LabVIEW Features for Managing Project DevelopmentB. Preparing the ApplicationC. Building the Application and Installer

    1

    A. Managing Project Development

    VI History Use the History window in each VI to display the

    development history of the VI, including revision numbers The revision number starts at zero and increases

    ni.com/training

    incrementally every time you save the VI Record and track the changes you make to the VI in the

    History window as you make them Select EditVI Revision History to display You also can print the revision history

    2

    A. Managing Project Development

    VI Hierarchy Displays a graphical representation of all open LabVIEW

    projects and application instances, as well as the calling hierarchy for all VIs in memory, including type definitions

    ni.com/training

    and global variables

    3

    A. Managing Project Development

    Comparing VIs A utility to determine the differences between two VIs

    loaded into the memory

    ni.com/training4

    Exercise 7-1: LabVIEW Project Management Tools

    ni.com/training

    GOAL

    Concept ExerciseExamine some of the built-in LabVIEW features for project management.

    B. Preparing the Application

    To create a professional, stand-alone application for your VIs, you must consider several programming issues: Use of outside code Use of relative path names

    ni.com/training

    p Quit LabVIEW function

    6

  • 2C. Building the Application and Installer

    Use Build Specifications in LabVIEW to create stand-alone applications and to create installers Stand-alone applicationsUse stand-alone applications to

    provide other users with executable versions of VIs; this is

    ni.com/training

    useful when you want users to run VIs without installing the LabVIEW development system

    InstallersUse installers to distribute stand-alone applications, shared libraries, and source distributions that you create with the Application Builder; you can include the LabVIEW Run-Time Engine

    7

    C. Building the Application and Installer

    System Requirements Applications that you create with Build Specifications

    generally have the same system requirements as the LabVIEW development system used to create the VI or

    ni.com/training

    application Memory requirements vary depending on the size of the

    application created

    8

    Exercise 7-2: Creating an Application

    ni.com/training

    GOAL

    Concept ExerciseCreate a stand-alone application with LabVIEW.

    9

    Summary

    The Application Builder enables you to create stand-alone applications and installers The Application Builder is available in the LabVIEW

    Professional Development System, or as an add-on package

    ni.com/training

    Creating a professional, stand-alone application with your VIs involves four areas of understanding: The architecture of your application The programming issues particular to the application The application building process The installer building process

    Continuing Your LabVIEW Education

    Instructor Led Training LabVIEW Intermediate I: Learn about developing large

    projects and event programming Hardware courses such as Data Acquisition and Signal

    ni.com/training

    q gProcessing

    Online courses such as Machine Vision and LabVIEW Real-Time

    Self-Paced: a variety of instructional packages and tools designed to educate you at your own pace

    11

    Courses

    New User

    LabVIEW Basics I

    LabVIEW Basics II

    Experienced User

    LabVIEW Intermediate I

    LabVIEW Intermediate II

    Advanced User

    LabVIEW Advanced I

    Skills learned: LabVIEW environment

    navigation Basics application creation

    using LabVIEW Basics of data acquisition and

    Skills learned: Modular application

    development Structured design and

    development practices Inter-application

    Skills learned: Large application design Advanced development

    techniques Implementing multideveloper

    projects

    ni.com/training12

    Certifications

    Certified LV Associate Developer Exam

    Skills tested: LabVIEW environment

    knowledge

    Certified LabVIEW Developer Exam

    Skills tested: LabVIEW application

    development expertise

    Certified LabVIEW Architect Exam

    Skills tested: LabVIEW application

    development mastery

    Basics of data acquisition and instrument control

    Inter-application communication and connectivity techniques

    projects

  • 3How To Learn More Out Of The Classroom

    ni.com/support Access product manuals, KnowledgeBases, example code,

    tutorials, application notes and discussion forums Request technical support

    ni.com/training

    Info-LabVIEW: www.info-labview.org Alliance Program: ni.com/alliance Publications: ni.com/reference/books/ Practice!

    13 ni.com/training

    THANK YOU!

    Please complete the course survey and retrieve your course CD.

    Lesson 1 - Common Design TechniquesLesson 2 - Communicating btn Multiple LoopsLesson 3 - Event ProgrammingLesson 4 - Controlling the User InterfaceLesson 5 - Advanced File IO TechniquesLesson 6 - Improving an Existing VILesson 7 - Creating and Distributing Executables