| 
    
    | 
   
   
     
      
      Ch Data Acquisition Package for
NI-DAQ Demos.
     
To completely understand two demo programs below for
real-time data acquisition, you only need to read 
this on-line
        
Quick Introduction to NI-DAQ 
Example 1
 
The program daq.ch below 
illustrates how Ch Data Acquisition Package for
NI-DAQ is used.
This program can be found in the directory CHHOME/toolkit/demos/NIDAQ/ after
installation of the Ch Data Acquisition Package for
NI-DAQ, where CHHOME is the home directory 
in which Ch is installed. 
 
After NI-DAQ is installed and configured,
the program is readily to run without compilation,
which will give you a quick start on programming NI-DAQ in Ch.
The program will acquire 500 data points within 3 seconds
through channel 2. The data are displayed as a plot.
In the example below, the input signal is a sine wave
for function sin(10x) generated through a function generator
as shown in the displayed plot.
 
/*- ---------------------------------------------------------------------
This program will acquire data from channel 2 of the AT-MIO-16E-10 board.
All settings are made in the program itself, there are not any inputs for
the user.  The current settings are:
   data points 500  -  set with the COUNT
-----------------------------------------------------------------------*/
#include    /* needed for NI-DAQ */
#include      /* NI-DAQ functions */
#include      /* input/output functions */
#include     /* ploting functions */
#include    /* use linspace() */
#define COUNT 500      /* # of data points */
#define NUM_OF_SEC 3   /* amount of time to take data */
int main()
{
   short
      InDevice = 1,          /* device number of A/D card set in NI-DAQ */
      InChannel = 2,         /* channel to read from */
      InGain = 1,            /* gain to apply to the reading */
      InBuffer[COUNT] = {0}, /* buffer to hold data from A/D card */
      InStatus;              /* return value of NI-DAQ functions for error check */
   long
      InTimeOut = 360;       /* # of timer ticks to wait for data to be 
                                 acquired before assume error */
   unsigned long
      InCount = COUNT;       /* # of data points to take */
   double
      InRate = COUNT/NUM_OF_SEC,  /* frequency of data acquisition */
      GainAdjust = 1,             /* factor to adjust the gain in binary to 
                                      value conversion */
      Offset = 0,                 /* binary offset needed in binary to value 
                                     conversions */
      time[COUNT],                /* buffer to hold time stamp */
      VoltBuffer[COUNT];          /* buffer to hold converted data */
   CPlot plot;                    /* instantiate a plot class */
   /****** print a header to the screen ******/
   printf ("This program will acquire %d points from channel %d.\n", 
            InCount, InChannel);
   /****** set time for timeout and error check ******/
   if ((InStatus = Timeout_Config(InDevice, InTimeOut)) != 0)
   {
      printf ("Timeout_Config error %d\n",InStatus);
      exit(InStatus);
   }
   /****** acquire data and error check ******/
   if ((InStatus = DAQ_Op(InDevice, InChannel, InGain, InBuffer, 
                          InCount, InRate)) != 0)
   {
      printf ("DAQ_Op error %d\n",InStatus);
      exit(InStatus);
   }
   /****** convert binary data to input data type and error check ******/
   if ((InStatus = DAQ_VScale(InDevice, InChannel, InGain, GainAdjust, 
                              Offset, InCount, InBuffer, VoltBuffer)) != 0)
   {
      printf ("DAQ_VScale error %d\n",InStatus);
      exit(InStatus);
   }
   /****** plot the data ******/
   linspace(time, 0, NUM_OF_SEC);
   plotxy(time, VoltBuffer,"Data acquired through Ch DAQ Toolkit for NI-DAQ","time (sec)", 
          "Voltage (volts)",&plot);
   plot.grid(PLOT_ON);
   plot.plotting();
}
 
  
Example 2
 
The example code below is from NI-DAQ distribution.
The program can readily run in Ch Standard Edition without any modification.
 
/*********************************************************************
*
* Example program: 
*    DAQOp.c
*
* Description: 
*    Read a waveform from one analog input channel using internal
*     timing (uses high-level NI-DAQ functions)
*
* Example Category: 
*    AI
*
* Example Task Types: 
*    BUF, 1CH, BURST, IMMED, SYNC, INTTRIG
*
* List of key parameters: 
*    lTimeout, dSampRate
*
*    [Since variables are hardcoded, there is no guarantee that this
*     program will work for your setup.  This example is simply
*     presented as a code snippet of how you can use NI-DAQ functions
*     to perform a task.]
*
* List of NI-DAQ Functions used in this example: 
*    Timeout_Config, NIDAQErrorHandler, DAQ_Op, DAQ_VScale
*
*    [NOTE: For further details on each NI-DAQ function, please refer
*     to the NI-DAQ On-Line Help (NIDAQPC.HLP).]
*
* Pin Connection Information: 
*    Connect your analog signal to AI channel 1. The default analog
*     input mode for the DAQ device will be used.
*
*    [For further I/O connection details, please refer to your hardware
*     User Manual.]
*
*    [For further details on how to run this example, please refer to
*     the NI-DAQ Examples On-Line Help (NIDAQEx.HLP).]
*
*********************************************************************/
/*
 * Includes: 
 */
#include "nidaqex.h"
/*
 * Main: 
 */
void void main(void)
{
    /*
     * Local Variable Declarations: 
     */
    i16 iStatus = 0;
        i16 j = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i32 lTimeout = 180;
    i16 iChan = 2;
    i16 iGain = 1;
    f64 dSampRate = 1000.0;
    u32 ulCount = 100;
    f64 dGainAdjust = 1.0;
    f64 dOffset = 0.0;
    static i16 piBuffer[100] = {0};
    static f64 pdVoltBuffer[100] = {0.0};
    i16 iIgnoreWarning = 0;
    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the DAQ_Op call. */
    
    iStatus = Timeout_Config(iDevice, lTimeout);
    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config", iIgnoreWarning);
    /* Acquire data from a single channel. */
    /* HINT: You can easily replace this with the SCAN_Op function. */
    
    iStatus = DAQ_Op(iDevice, iChan, iGain, piBuffer, ulCount, dSampRate);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Op", iIgnoreWarning);
    
    iStatus = DAQ_VScale(iDevice, iChan, iGain, dGainAdjust, dOffset,
                         ulCount, piBuffer, pdVoltBuffer);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale", iIgnoreWarning);
    printf(" The data is available in 'pdVoltBuffer'.\n");
    for (j = 0; j < 100 ; j = j + 5)
    {
        printf ("\n%f   %f   %f   ",pdVoltBuffer[j],pdVoltBuffer[j+1],
                 pdVoltBuffer[j+2]);
        printf ("%f   %f",pdVoltBuffer[j+3],pdVoltBuffer[j+4]);
    }
}
/* End of program */
 |