Creating Tasks with the API
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
- Call the AI Temp TC instance of the DAQmx Create Virtual Channel VI in LabVIEW (DAQmxCreateAIThrmcplChan function in LabWindows/CVI).
- Specify Dev1/ai0 as the physical channel for the device connected to the thermocouple signal.
- Specify myThermocoupleChannel as the name to assign to your virtual channel.
- Select the appropriate values for the thermocouple type and range inputs. NI-DAQmx applies these attributes to the virtual channel.
- 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.
- Call the DAQmx Start Task VI (DAQmxStartTask in LabWindows/CVI).
- 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.
- Call the DAQmx Stop Task VI (DAQmxStopTask function in LabWindows/CVI) after the desired number of samples have been acquired.
- 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.
Note You also can use the DAQ Assistant to create the same task and generate the code to run the task. |
See Also