Table Of Contents

Creating Tasks with the API

Last Modified: October 17, 2018

The following example illustrates how to create a task with the API:

Problem

Create an NI-DAQmx task to measure temperature in the range 50°C to 200°C using a J-type thermocouple that is wired to channel 0 on an M Series device configured as Device 1. Sample the temperature 10 times per second, and acquire 10,000 samples. Use LabVIEW or LabWindows/CVI to write your application.

Solution

  1. Call the AI Temp TC instance of the DAQmx Create Virtual Channel VI in LabVIEW (DAQmxCreateAIThrmcplChan function in LabWindows/CVI).
  2. Specify Dev1/ai0 as the physical channel for the device connected to the thermocouple signal.
  3. Specify myThermocoupleChannel as the name to assign to your virtual channel.
  4. Select the appropriate values for the thermocouple type and range inputs. NI-DAQmx applies these attributes to the virtual channel.
  5. Call the Sample Clock instance of DAQmx Timing VI in LabVIEW (or DAQmxCfgSampClkTiming function in LabWindows/CVI), specifying a rate of 10 Hz and a sample mode of finite.
  6. Call the DAQmx Start Task VI (DAQmxStartTask in LabWindows/CVI).
  7. Call the Analog 1D DBL 1Chan NSamp instance of DAQmx Read VI (DAQmxReadAnalogF64 in LabWindows/CVI), specifying number of samples per channel as 10,000.
  8. Call the DAQmx Stop Task VI (DAQmxStopTask function in LabWindows/CVI) after the desired number of samples have been acquired.
  9. Call the DAQmx Clear Task VI (DAQmxClearTask function in LabWindows/CVI).
You have now created a task called myTemperatureTask that uses a local virtual channel called myThermocoupleChannel.
spd-note-note
Note  

You also can use the DAQ Assistant to create the same task and generate the code to run the task.


Recently Viewed Topics