00001 /********************************************************************* 00002 * 00003 * ANSI C Example program: 00004 * Acq-IntClk.c 00005 * 00006 * Example Category: 00007 * AI 00008 * 00009 * Description: 00010 * This example demonstrates how to acquire a finite amount of data 00011 * using the DAQ device's internal clock. 00012 * 00013 * Instructions for Running: 00014 * 1. Select the physical channel to correspond to where your 00015 * signal is input on the DAQ device. 00016 * 2. Enter the minimum and maximum voltages. 00017 * Note: For better accuracy try to match the input range to the 00018 * expected voltage level of the measured signal. 00019 * 3. Select the number of samples to acquire. 00020 * 4. Set the rate of the acquisition. 00021 * Note: The rate should be AT LEAST twice as fast as the maximum 00022 * frequency component of the signal being acquired. 00023 * 00024 * Steps: 00025 * 1. Create a task. 00026 * 2. Create an analog input voltage channel. 00027 * 3. Set the rate for the sample clock. Additionally, define the 00028 * sample mode to be finite and set the number of samples to be 00029 * acquired per channel. 00030 * 4. Call the Start function to start the acquisition. 00031 * 5. Read all of the waveform data. 00032 * 6. Call the Clear Task function to clear the task. 00033 * 7. Display an error if any. 00034 * 00035 * I/O Connections Overview: 00036 * Make sure your signal input terminal matches the Physical 00037 * Channel I/O Control. For further connection information, refer 00038 * to your hardware reference manual. 00039 * 00040 *********************************************************************/ 00041 00042 #include <stdio.h> 00043 #include <NIDAQmx.h> 00044 00045 #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else 00046 00047 #include <iostream> 00048 00049 int daq_function(void) 00050 { 00051 int32 error=0; 00052 TaskHandle taskHandle=0; 00053 int32 read; 00054 float64 data[1000]; 00055 char errBuff[2048]={'\0'}; 00056 00057 /*********************************************/ 00058 // DAQmx Configure Code 00059 /*********************************************/ 00060 printf("Calling confug stuff\n"); 00061 00062 DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); 00063 DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL)); 00064 00065 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000)); 00066 00067 /*********************************************/ 00068 // DAQmx Start Code 00069 /*********************************************/ 00070 DAQmxErrChk (DAQmxStartTask(taskHandle)); 00071 00072 /*********************************************/ 00073 // DAQmx Read Code 00074 /*********************************************/ 00075 00076 DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL)); 00077 std::cout << " read = " << read << std::endl; 00078 00079 Error: 00080 if( DAQmxFailed(error) ) 00081 DAQmxGetExtendedErrorInfo(errBuff,2048); 00082 if( taskHandle!=0 ) { 00083 /*********************************************/ 00084 // DAQmx Stop Code 00085 /*********************************************/ 00086 DAQmxStopTask(taskHandle); 00087 DAQmxClearTask(taskHandle); 00088 } 00089 if( DAQmxFailed(error) ) 00090 std::cout << "DAQmx Error: " << errBuff << std::endl; 00091 std::cout << "End of program, enter key to quit\n" << std::endl; 00092 getchar(); 00093 return 0; 00094 }