You are on page 1of 34

Lesson 6 Managing Resources

TOPICS
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 in LabVIEW (Channel API)

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

ni.com/training

A. Understanding File I/O File 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 LVM The LabVIEW measurement data file (.lvm) is a tabdelimited text file you can open with a spreadsheet application or a text-editing application TDMSType of binary file created for NI products consisting of two separate files: a binary file and a binary index file
ni.com/training

A. Understanding File I/O File 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

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/O operations Might not be as efficient as the functions configured or designed for individual 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
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 a 2D 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

ni.com/training

C. Understanding Low-Level File I/O VIs

ni.com/training

Exercise 6-1 Spreadsheet Example VI

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

Exercise 6-2 Temperature Log VI

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

Exercise 6-2 Temperature Log VI

What would happen if you used the Write to Measurement File Express VI inside the While loop?
DISCUSSION

D. DAQ Programming
1. 2. 3. 4. 5. Signal Terminal Block Cable DAQ Device Computer

ni.com/training

D. DAQ Programming Software Overview


NI-DAQmx
Driver level software Detects DAQ devices Installs NI-DAQmx functions in LabVIEW

Measurement & Automation Explorer


Configure and test DAQ device

DAQ Assistant
Configurable Express VI used to create a DAQ application

DAQmx API
Provides a set of VIs to program DAQ applications

ni.com/training

D. DAQ Programming Basic Flow


A basic DAQmx application involves the following process:
Create Task Configure Task Start Task Acquire or Generate Data Clear Task

ni.com/training

D. DAQ Programming Create 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

ni.com/training

D. DAQ Programming Configure Task


Configure timing if reading multiple samples
Sample rate, timing source, etc

Configure triggering if necessary for application


Configures the task to start or stop on a rising or falling digital edge, analog edge, or analog windows

ni.com/training

D. DAQ Programming Start Task


Starts the task after the task has been configured

ni.com/training

D. DAQ Programming Acquire or Generate Data


Acquire or generate data from the DAQ device Make sure pull-down menu selection is compatible with task configuration

ni.com/training

D. DAQ Programming Clear Task


DAQmx Clear Task VI
Stops the task Releases any resources the task reserved Clears the task

ni.com/training

D. DAQ Programming Example


Example acquisition with triggering

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
Lower-level, advanced API Command/response protocol Advanced CAN/DAQ synchronization Compatible with all versions of NI-CAN
ni.com/training

Frame API

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

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

ni.com/training

F. CAN Programming in LabVIEW

<or>

ni.com/training

F. CAN Programming in LabVIEW

ni.com/training

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

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? DISCUSSION

SummaryQuiz
1. Your continuously running test program logs to a single file the results 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 VIs b) High-level file I/O VIs

ni.com/training

SummaryQuiz Answer
1. Your continuously running test program logs to a single file the results 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 VIs b) High-level file I/O VIs

ni.com/training

SummaryQuiz
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?
a) ASCII b) TDMS

ni.com/training

SummaryQuiz Answer
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?
a) ASCII b) TDMS

ni.com/training

SummaryQuiz
3. Which of the following conveys the basic DAQmx programming flow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task b) Acquire/Generate DataStart TaskClear Task c) Start TaskCreate TaskConfigure TaskAcquire/Generate DataClear Task d) Create TaskConfigure TaskStart TaskAcquire/Generate DataClear Task

ni.com/training

SummaryQuiz Answer
3. Which of the following conveys the basic DAQmx programming flow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task b) Acquire/Generate DataStart TaskClear Task c) Start TaskCreate TaskConfigure TaskAcquire/Generate DataClear Task d) Create TaskConfigure TaskStart TaskAcquire/Generate DataClear Task

ni.com/training

SummaryQuiz
4. Which of the following are ways to access CAN channels in your CAN 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

ni.com/training

SummaryQuiz Answers
4. Which of the following are ways to access CAN channels in your CAN 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

ni.com/training

You might also like