sp1408

Untitled

May 18th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.65 KB | None | 0 0
  1. /*********************************************************************
  2. *
  3. * ANSI C Example program:
  4. *    acquire1Scan.c
  5. *
  6. * Example Category:
  7. *    AI
  8. *
  9. * Description:
  10. *    This example demonstrates how to take a single Measurement
  11. *    (Sample) from an Analog Input Channel.
  12. *
  13. * Instructions for Running:
  14. *    1. Select the Physical Channel to correspond to where your
  15. *       signal is input on the DAQ device.
  16. *    2. Enter the Minimum and Maximum Voltage Ranges.
  17. *    Note: For better accuracy try to match the Input Ranges to the
  18. *          expected voltage level of the measured signal.
  19. *    Note: Use the genVoltage example to provide a signal on
  20. *          your DAQ device to measure.
  21. *
  22. * Steps:
  23. *    1. Create a task.
  24. *    2. Create an Analog Input Voltage Channel.
  25. *    3. Use the Read function to Measure 1 Sample from 1 Channel on
  26. *       the Data Acquistion Card. Set a timeout so an error is
  27. *       returned if the sample is not returned in the specified time
  28. *       limit.
  29. *    4. Display an error if any.
  30. *
  31. * I/O Connections Overview:
  32. *    Make sure your signal input terminal matches the Physical
  33. *    Channel I/O Control.
  34. *
  35. * Recommended Use:
  36. *    Call the Read function.
  37. *
  38. *********************************************************************/
  39.  
  40. #include "NIDAQmxBase.h"
  41. #include <stdio.h>
  42.  
  43. #define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; }
  44.  
  45. }
  46.  
  47. int main(int argc, char *argv[])
  48. {
  49.     // Task parameters
  50.     int32       error = 0;
  51.     TaskHandle  taskHandle = 0;
  52.     char        errBuff[2048]={'\0'};
  53.  
  54.     // Channel parameters
  55.     char        chan[] = "Dev1/ai0";
  56.     float64     min = -10.0;
  57.     float64     max = 10.0;
  58.  
  59.     // Timing parameters
  60.     uInt64      samplesPerChan = 1;
  61.  
  62.     // Data read parameters
  63.     float64     data;
  64.     int32       pointsToRead = 1;
  65.     int32       pointsRead;
  66.     float64     timeout = 10.0;
  67.  
  68.  
  69.     DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
  70.  
  71.     DAQmxErrChk (DAQmxBaseCreateAIVoltageChan
  72.  
  73. (taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
  74.  
  75.     DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
  76.  
  77.  
  78.     DAQmxErrChk (DAQmxBaseReadAnalogF64
  79.  
  80. (taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByChannel,&data,samplesPerChan,&pointsRead,
  81.  
  82. NULL));
  83.  
  84.  
  85.     printf ("Acquired reading: %f\n", data);
  86.  
  87.  
  88. Error:
  89.     if( DAQmxFailed(error) )
  90.         DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
  91.     if( taskHandle!=0 ) {
  92.         DAQmxBaseStopTask(taskHandle);
  93.         DAQmxBaseClearTask(taskHandle);
  94.     }
  95.     if( DAQmxFailed(error) )
  96.     printf ("DAQmxBase Error %d: %s\n", error, errBuff);
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment