Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to do a single channel DAQ using NI-DAQ driver software with a PCI-MIO-16XE-10 card

Hi,
I would like to find out how I could do a simple one channel Data Acquisition from a signal generator using the NI-DAQ driver software with a PCI-MIO-16XE-10 card.
I have written some test problem but even when the signal generator is turned on/off I get back some weird values.
Here is my code.

CString sFunctionName("");
double volt[OUTPUT_POINTS*2];
double out[OUTPUT_POINTS*2];

short timebase, ready, code, stopped;
unsigned short sampleInterval;
int i, status, count=0;
unsigned long update, points;
short* ai_buffer;
short output_ch_vector[16];

int local_ITERATIONS = 2;

SAFEARRAYBOUND bound[1];
double dataItem = 9.9;

long j;
long k;
double* pTheValues;
LPTSTR lpsz_ErrMsg;


// Initialise device
/*
status = Init_DA_Brds (deviceNumber, deviceNumberCode)
Initializes the hardware and software states of a National Instruments
DAQ device to its default state and returns a numeric device code that
corresponds to the type of device initialized
*/
Init_DA_Brds(DEVICE, &code);

// Check return code from Init_DA_Brds
/*
Code return should be 204: PCI-MIO-16XE-10.
*/
if (code < 0)
{
CString sError;
sError.Format("Code error: %d", code);
if (code == -1)
sError = sError + ": No device found";
LPTSTR lpsz = new TCHAR[sError.GetLength()+1];
_tcscpy(lpsz, sError);
AfxMessageBox(lpsz);

delete lpsz;

return S_FALSE;
}


// Allocate memory for analog output and input arrays
//ao_buffer = new short[OUTPUT_POINTS*2];
ai_buffer = new short[OUTPUT_POINTS];

// Set double-buffering
/*
status = DAQ_DB_Config (deviceNumber, DBmode)
Enables or disables double-buffered DAQ operations.
*/
status = DAQ_DB_Config(DEVICE, 1);
if (status < 0 )
{
sFunctionName = "DAQ_DB_Config";
goto TidyUp;
}

// Get the rate parameters
/*
status = DAQ_Rate (rate, units, timebase, sampleInterval)
Converts a DAQ rate into the timebase and sample-interval
values needed to produce the rate you want.
*/
status = DAQ_Rate(RATE, 0, &timebase, &sampleInterval);
if (status < 0 )
{
sFunctionName = "DAQ_Rate";
goto TidyUp;
}

// Setup scan
/*
status = SCAN_Setup (deviceNumber, numChans, chanVector, gainVector)
Initializes circuitry for a scanned data acquisition operation.
Initialization includes storing a table of the channel sequence
and gain setting for each channel to be digitized
*/
status = SCAN_Setup(DEVICE, 1, ai_channels, gain);
if (status < 0 )
{
sFunctionName = "SCAN_Setup";
goto TidyUp;
}

/*
status = SCAN_Start (deviceNumber, buffer, count, sampTimebase,
sampInterval, scanTimebase, scanInterval)
Initiates a multiple-channel scanned data acquisition operation,
with or without interval scanning, and stores its input in an array
*/
status = SCAN_Start(DEVICE, ai_buffer, OUTPUT_POINTS, timebase, sampleInterval, timebase, 1000);
if (status < 0 )
{
sFunctionName = "SCAN_Start";
goto TidyUp;
}

while(count < local_ITERATIONS)
{
// Check whether we are ready to input another half-buffer
status = DAQ_DB_HalfReady(DEVICE, &ready, &stopped);
if (status < 0 )
{
sFunctionName = "DAQ_DB_HalfReady";
goto TidyUp;
}
if (ready == 1)
{
status = DAQ_DB_Transfer(DEVICE, ai_buffer, &points, &stopped);
if (status < 0 )
{
sFunctionName = "DAQ_DB_Transfer";
goto TidyUp;
}
count++;
}
}

// Clear the analog input
/*
status = DAQ_Clear (deviceNumber)
Cancels the current DAQ operation
(both single-channel and multiple-channel scanned) and reinitializes the DAQ circuitry.
*/
status = DAQ_Clear(DEVICE);
if (status < 0 )
{
sFunctionName = "DAQ_Clear";
goto TidyUp;
}

/*
status = SCAN_Demux (buffer, count, numChans, numMuxBrds)
Rearranges, or demultiplexes, data acquired by a SCAN operation
into row-major order, that is, each row of the array holding the
data corresponds to a scanned channel
*/
/*
status = SCAN_Demux(ai_buffer, OUTPUT_POINTS * 2, 2, 0);
if (status < 0 )
{
sFunctionName = "SCAN_Demux";
goto TidyUp;
}
*/

//Convert binary values to voltages (Doesn't actually take a reading from board)
/*
status = DAQ_VScale (deviceNumber, chan, gain, gainAdjust, offset, count, binArray, voltArray)
Converts the values of an array of acquired binary data and the gain setting for that data
to actual input voltages measured.
*/
status = DAQ_VScale (1, 0, 1, 1.0, 0.0, OUTPUT_POINTS , ai_buffer, volt);
if (status < 0 )
{
sFunctionName = "DAQ_VScale";
goto TidyUp;
}
0 Kudos
Message 1 of 2
(2,387 Views)
Hello,

Please take a look at lots of examples available at :

1. www.ni.com >> NI Developer Zone >> Development Library >> Measurement Hardware

2. C:\program files\national instruments\ni-daq\examples\visualc


Sincerely,
Sastry V.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,387 Views)