This series references two manuals that are shipped with NI-DAQmx.
Your goal is to create an example data acquisition application that performs a finite analog input operation using the internal sample clock of the data acquisition device.
You can configure the Traditional NI-DAQ (Legacy) measurement with the following code.
i16 iDevice = 1; // specify device i16 iChan = 1; // specify channel i16 iGain = 1; // specify channel f64 dSampRate = 1000.0; // specify sample rate u32 ulCount = 100; // specify number of samples static i16 piBuffer[100] = {0}; // initialize data buffer AI_Configure (iDevice, iChan, 0, 10, 0, 0); // Configure Device Channel and Gain DAQ_Rate (dSampleRate, 0, , ); // Set Acquisition Rate |
This configuration code sets up the finite analog input operation, meeting the requirements of the example application you are trying to create. However, this configuration does not take into account the type of measurement you are making. For example, to have meaningful data when you are reading thermocouple voltages, you need to perform scaling on the data returned. You do this by creating a scaling algorithm yourself.
With NI-DAQmx, you configure every operation by creating a task and then creating the appropriate channel. The following code shows how you configure the same operation using the NI-DAQmx C API.
static TaskHandle gTaskHandle= 0; DAQmxCreateTask("",&gTaskHandle); // Create a new Task // Create an Analog Input Channel for Device 1, channel 0 in Differential mode // The measurement range is from -10.0 to +10.0 Volts /* Configure the sample clock to be the internal clock, sampling at 1000 Hz on the rising edge of the sample clock. The acquisition mode is finite and we will return 1000 samples per channel. */ DAQmxCfgSampClkTiming(gTaskHandle,"",1000,DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,1000); |
The functions are organized by group-related parameters to make using the API more intuitive. The API targets the particular type of measurement.
In the previous Traditional NI-DAQ (Legacy) example, you configure but do not scale the data. The following code shows how to configure and scale your measurement with the Traditional NI-DAQ (Legacy) API.
i16 iDevice = 1; // specify device i16 iChan = 1; // specify channel i16 iGain = 1; // specify channel f64 dSampRate = 1000.0; // specify sample rate u32 ulCount = 100; // specify number of samples static i16 piBuffer[100] = {0}; // initialize data buffer AI_Configure (iDevice, iChan, 0, 10, 0, 0); // Configure Device Channel and Gain DAQ_Rate (dSampleRate, 0, , ); // Set Acquisition Rate DAQ_VScale(iDevice, iChan, iGain, dGainAdjust, dOffset, ulCount, piBuffer, pdVoltBuffer); |
You then need to apply a scaling function to scale a voltage to a thermocouple measurement.
In the previous code, you acquire the voltage data from the thermocouple and use your own conversion functions to get the temperature data. The acquisition operation is not configured in terms of the measurement being made.
In the previous NI-DAQmx example, you configure the channel by using CreateVoltageChannel. If you need to configure an analog input operation connected to a thermocouple, you configure the channel with the following code.
static TaskHandle gTaskHandle= 0; DAQmxCreateTask("",&gTaskHandle); // Create a new Task /* Create an Thermocouple Channel for Device 1, channel 0 for a B Type Thermocoupleto read in a measurement in Celsius between 0 and 100 C */ DAQmxCreateAIThrmcplChan (gTaskHandle, "Dev1/ai0", "", 0.0, 100.0, DAQmx_Val_DegC, DAQmx_Val_B_Type_TC, DAQmx_Val_ConstVal, 25.0, ""); |
When you use the previous configuration, the data returned consists of temperature measurements because NI-DAQmx internally scales the data.
NI-DAQmx fully supports using custom scales as well. For more information about custom scaling, refer to the NI-DAQmx Core Help under NI-DAQmx Help >> Key NI-DAQmx Concepts >> Custom Scales.
In most cases, you do not need to change the configuration for your data acquisition operation at run time. The following sections explain the options available for configuring your data acquisition operation interactively.
NI-DAQmx
NI-DAQmx provides the interactive DAQ Assistant configuration tool that you can use to experiment with the operation as you configure. Use the DAQ Assistant, which is accessible from the NI LabWindows/CVI, to interactively create, edit, and run NI-DAQmx tasks. Tasks that you create and configure in Measurement & Automation Explorer (MAX) configuration software are accessible from any NI-DAQmx application on your system.
Using DAQ Assistant in MAX
Figure 1. DAQ Assistant in MAX
”
You can test your configurations using DAQ Assistant without having to write a single line of code. Also, you can view the connection diagram for your particular tasks based on the accessory that is configured for your data acquisition device.
NI-DAQmx
After you configure your task in MAX using DAQ Assistant, you can load it using the DAQmxLoadTask ("", ); function. Once you have loaded the task, you can use it or make changes to the task configuration before using it.
This particular example application does not have any special timing and triggering requirements, but understanding timing and triggering support is important for creating useful data acquisition applications.
Setting up the timing parameters for Traditional NI-DAQ (Legacy) is done programmatically. In the following code, the sampling rate is set to 1,000 samples per second using the internal clock as the sampling clock.
// sets the sample rate on device 1 to 1000 samples/second DAQ_Set_Clock (1, 0, 1000.0, 0, ); |
NI-DAQmx timing functions configure the timing for hardware-timed data acquisition operations. You use the timing functions to specify whether the operation is continuous or finite, select the number of samples to acquire or generate for finite operations, and create a buffer, when needed.
You can use DAQ Assistant to interactively configure these parameters and test the task.
Figure 2. Configuring Timing with DAQ Assistant and LabWindows/CVI
For information about the various types of timing supported by NI-DAQmx, refer to the "Timing and Triggering" section in the NI-DAQmx Core Help.
You can set an analog trigger type programmatically with the following code.
Configure_HW_Analog_Trigger(iDevice, ND_ON, lLowValue, lHighValue, ND_ABOVE_HIGH_LEVEL, ND_THE_AI_CHANNEL); /* Setup for external start trigger into PFI0. You can change the "source" to an analog input channel, if desired. */ Select_Signal(iDevice, ND_IN_START_TRIGGER, ND_PFI_0, ND_LOW_TO_HIGH); |
The NI-DAQmx trigger class configures a trigger to perform a specific action. The most commonly used actions are a start trigger and a reference trigger. NI-DAQmx also supports the following trigger configurations:
Figure 3. Configuring Triggers in DAQ Assistant
The following code shows how to configure the analog start trigger with APFI0 as the source at a 3.0 V level with 0 V hysteresis in your C code with NI-DAQmx.
//Configure APFI0 to be the analog trigger, setup the trigger to be //asserted on the Falling slope at 3.0 volts DAQmxCfgAnlgEdgeStartTrig(gtaskHandle,"APFI0", DAQmx_Val_FallingSlope,3.0); |
The triggering options are fully supported in DAQ Assistant, so you can load an existing task with these options configured or set the trigger options programmatically.
For information about the various types of timing supported by NI-DAQmx, refer to the Timing and Triggering section in the NI-DAQmx Core Help.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft Corporation in the United States and other countries.