Lesson 6 - Managing Resources (CAN)

Embed Size (px)

Citation preview

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    1/34

    TOPICS

    ni.com/training

    Lesson 6

    Managing Resources

    A. Understanding File I/O

    B. Understanding High-level

    File I/O

    C. Understanding Low-level

    File I/O

    D. DAQ Programming

    E. CAN APIs

    F. CAN Programming inLabVIEW (Channel API)

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    2/34

    ni.com/training

    A. Understanding File I/O

    File I/O writes to or reads from a file

    A typical file I/O operation involves the following process:

    Open/

    Create/

    Replace File

    Read

    and/or

    Write to File

    Close

    File

    Check for

    Errors

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    3/34

    ni.com/training

    A. Understanding File I/OFile Formats

    LabVIEW can use or create the following file formats:

    BinaryUnderlying file format of all other file formats

    ASCIISpecific type of binary file that is a standard used by

    most programs LVMThe LabVIEW measurement data file (.lvm) is a tab-

    delimited text file you can open with a spreadsheetapplication or a text-editing application

    TDMSType of binary file created for NI productsconsisting of two separate files: a binary file and a binaryindex file

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    4/34

    ni.com/training

    A. Understanding File I/OFile Formats

    In this course, you learn about creating text (ASCII) files

    Use text files in the following situations:

    You want to access the file from another application

    Disk space and file I/O speed are not crucial

    You must not perform random access reads or writes

    Numeric precision is not important

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    5/34

    ni.com/training

    B. Understanding High-level File I/O

    High-level VIs

    Perform all three steps (open,read/write, close) for common file I/Ooperations

    Might not be as efficient as thefunctions configured or designed forindividual operations

    Low-level VIs

    Individual VI for each step If you are writing to a file in a loop, use

    low-level file I/O functions

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    6/34

    ni.com/training

    B. Understanding High-Level File I/O

    Write to Spreadsheet File Converts an array of double-precision numbers to a text string and

    writes the string to an ASCII file

    Read From Spreadsheet File Reads a specified number of lines or rows

    from a numeric text file and outputs a2D array of double-precision numbers

    Write to/Read from Measurement File Express VIs that write data to or read data

    from an LVM or TDMS file format

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    7/34

    ni.com/training

    C. Understanding Low-Level File I/O VIs

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    8/34GOAL

    Exercise 6-1

    Spreadsheet Example VI

    Use a high-level file I/O VI to write to a spreadsheet-readable

    file.

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    9/34GOAL

    Exercise 6-2

    Temperature Log VI

    Modify a VI to create an ASCII file using disk streaming.

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    10/34DISCUSSION

    Exercise 6-2

    Temperature Log VI

    What would happen if you used the Write to Measurement

    File Express VI inside the While loop?

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    11/34

    ni.com/training

    D. DAQ Programming

    1. Signal

    2. Terminal Block

    3. Cable

    4. DAQ Device

    5. Computer

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    12/34

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    13/34

    ni.com/training

    D. DAQ ProgrammingBasic Flow

    A basic DAQmx application involves the following process:

    Configure

    Task

    Acquire or

    GenerateData

    Clear

    Task

    Create

    Task

    Start

    Task

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    14/34

    ni.com/training

    D. DAQ ProgrammingCreate Task

    Create Virtual Channel VI

    Creates a virtual channel and adds it to a task

    Use pull-down menu to select the appropriate instance of this

    VI

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    15/34

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    16/34

    ni.com/training

    D. DAQ ProgrammingStart Task

    Starts the task after the task has been configured

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    17/34

    ni.com/training

    D. DAQ ProgrammingAcquire or Generate Data

    Acquire or generate data from the DAQ device

    Make sure pull-down menu selection is compatible with task

    configuration

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    18/34

    ni.com/training

    D. DAQ ProgrammingClear Task

    DAQmx Clear Task VI

    Stops the task

    Releases any resources the task reserved

    Clears the task

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    19/34

    ni.com/training

    D. DAQ ProgrammingExample

    Example acquisition with triggering

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    20/34

    ni.com/training

    E. CAN APIs

    Channel API

    High level

    Easy to use physical units

    Easy CAN/DAQ synchronization

    Not compatible with NI-CAN 1.6 or lower

    Frame API

    Lower-level, advanced API

    Command/response protocol Advanced CAN/DAQ synchronization

    Compatible with all versions of NI-CAN

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    21/34

    ni.com/training

    E. CAN APIs

    You can use only one API at a time per CAN port

    For most applications, use Channel API

    Use Frame API when:

    you require use of remote frames

    you have advanced requirements for synchronizing CAN and

    DAQ cards

    you are using a USB-CAN Interface

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    22/34

    ni.com/training

    F. CAN Programming in LabVIEW

    Link between the functions is the task reference

    CAN task

    Collection of CAN channels that have identical timing and the

    same communication direction read or write Can be several messages, but must all be on the same

    interface or port

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    23/34

    ni.com/training

    F. CAN Programming in LabVIEW

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    24/34

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    25/34

    GOAL

    Choose One:

    Exercise 6-3

    Using DAQmx (DAQ)

    or

    Exercise C-3

    Read and Write CAN Channels (CAN)

    6-3: Explore a DAQmx example program that continuously

    acquires data, and modify it to wait on a digital trigger.C-3: Read and write channels from the CAN card using the

    LabVIEW environment.

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    26/34

    DISCUSSION

    Choose One:

    Exercise 6-3

    Using DAQmx (DAQ)

    or

    Exercise C-3

    Read and Write CAN Channels (CAN)

    In Exercise 6-3, what types of VIs did you use outside of the

    While Loop? In Exercise C-3, how would modify the VI to acquire from an

    additional channel?

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    27/34

    ni.com/training

    SummaryQuiz

    1. Your continuously running test program logs to a single file theresults of all tests that occur in one hour as they are calculated. If

    you are concerned about the execution speed of your program,

    should you use low-level or high-level File I/O VIs?

    a) Low-level file I/O VIsb) High-level file I/O VIs

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    28/34

    ni.com/training

    SummaryQuiz Answer

    1. Your continuously running test program logs to a single file theresults of all tests that occur in one hour as they are calculated. If

    you are concerned about the execution speed of your program,

    should you use low-level or high-level File I/O VIs?

    a) Low-level file I/O VIsb) High-level file I/O VIs

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    29/34

    ni.com/training

    SummaryQuiz

    2. If you want to view data in a text editor like Notepad, what fileformat should you use to save the data?

    a) ASCII

    b) TDMS

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    30/34

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    31/34

    ni.com/training

    SummaryQuiz

    3. Which of the following conveys the basic DAQmx programmingflow?

    a) Create TaskConfigure TaskAcquire/Generate DataStart Task

    b) Acquire/Generate DataStart TaskClear Task

    c) Start TaskCreate TaskConfigure TaskAcquire/GenerateDataClear Task

    d) Create TaskConfigure TaskStart TaskAcquire/Generate

    DataClear Task

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    32/34

    ni.com/training

    SummaryQuiz Answer

    3. Which of the following conveys the basic DAQmx programmingflow?

    a) Create TaskConfigure TaskAcquire/Generate DataStart Task

    b) Acquire/Generate DataStart TaskClear Task

    c) Start TaskCreate TaskConfigure TaskAcquire/GenerateDataClear Task

    d) Create TaskConfigure TaskStart TaskAcquire/Generate

    DataClear Task

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    33/34

    ni.com/training

    SummaryQuiz

    4. Which of the following are ways to access CAN channels in yourCAN application?

    a) Specify a channel name that has been imported into MAX

    b) Specify a database file and channel name for channels not in MAX

    c) Use the CAN Get Names VI to access all channels in a database file

  • 8/13/2019 Lesson 6 - Managing Resources (CAN)

    34/34

    ni com/training

    SummaryQuiz Answers

    4. Which of the following are ways to access CAN channels in yourCAN application?

    a) Specify a channel name that has been imported into MAX

    b) Specify a database file and channel name for channels not in

    MAXc) Use the CAN Get Names VI to access all channels in a database

    file