Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

simultaneous multichannel acquisition with NI USB-6009 (for dummies!)

Hello everybody!

I have to make a continuous 6 channel acquisition using a USB-6009 using a sampling frequency of 5000 Hz (for example for a duration of 10 seconds).

I wrote a C routine to read the 6 signals and save them in a buffer (using the CFile Open and Write functions), but I'm a programming neophyte and when I make a complete acquisition the result is not right.

The problem is that I have not completely clear the meaning of the parameters (numSampsPerChan, readArray[], sampsPerChanToAcquire) in the functions (such as "DAQmxReadAnalogF64", "DAQmxCfgInputBuffer" or "DAQmxCfgSampClkTiming") and their relationships.

Please, someone tell my how can I set the functions to read and save the 6 signals!


Thanks,
Alessandro


0 Kudos
Message 1 of 5
(3,653 Views)
Hi A P,
 
About how daqmx functions works and how use them try reading this document.
 
If you need funcions prototypes please refer to Start>>all programs>>National Instruments>>NI-DAQ>>NI-DAQmx C reference Help.
 
Have a good day,

 
FiloP
It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong.
Richard P. Feynman
0 Kudos
Message 2 of 5
(3,630 Views)
Thanks a lot for the reply, FiloP.

The problem is that I've just read the documentation, and unfortunately I'm not enough expert in C (but I had use it!), and I fear I'm making a very stupid fault or maybe I'm mistaken completely!

In the end I will have to visualize the signals with matlab (or matcad, or with a VC program), so I decided to write the samples in a binary file.
The result was good when I read from 1 to 3 channels, but it's wired using the complete system, and now I'm in a hurry to acquire this signals...
It's a problem of parameters or I used a wrong method?

Here what I wrote of importance:
-----------------------------------------
    CString campioniS;
   
    CFile salva;
    salva.Open("DatiSalvati.bin",CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
   
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]={'\0'};
    int32       i,j;
    time_t      startTime;
    bool32      done=0;

    char        chan[] = "Dev1/ai0, Dev1/ai1, Dev1/ai2, Dev1/ai3, Dev1/ai4, Dev1/ai5";
    float64     min = -10.0;
    float64     max = 10.0;

    char        clockSource[] = "OnboardClock";
    uInt64      samplesPerChan = 1000;
    float64     sampleRate = 5000.0;

    #define     bufferSize (uInt32)1000
    float64     data[bufferSize*6];
    int32       pointsToRead = bufferSize;
    int32       pointsRead;
    float64     timeout = 10.0;
    int32       totalRead = 0;

    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_RSE ,min,max,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan));
    DAQmxErrChk (DAQmxCfgInputBuffer(taskHandle,100000));
    DAQmxErrChk (DAQmxStartTask(taskHandle));

    startTime = time(NULL);
    while( time(NULL)<startTime+10)
    {
        DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*6,&pointsRead,NULL));
        totalRead += pointsRead;
        campioniS.Format("%d", totalRead);
        m_label.SetWindowText(campioniS);
        salva.Write(data,16000);
    }

    salva.Close();
-----------------------------------------

Thanks for every kind of support!

Alessandro

0 Kudos
Message 3 of 5
(3,619 Views)
Hi,

There's several options for doing data acquisition with this device directly into MATLAB.  Do a google search for "MATLAB data acquisition" for some ideas.

-Rob
-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 4 of 5
(3,589 Views)
Well I'm sure of it, but my problem remains, 'cause I anyway had to write the VC program for the acquisition of the 6 signals and the creation of the binary file (unfortunately I can't bypass it).

I also tried to use the example found in:

National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Cont Acq-Int Clk,

but I can't come through to apply it to my VC task (it's a simple Dialog Box with an 'Acquire' button): I haven't a "main()", but a function for the acquisition:

void CProgramDlg::OnAcquire(),

and I don't know how to use the examples instead of the method I used applied to my application.


Please someone tell me how I can finish this work!!!

Thank to all.
0 Kudos
Message 5 of 5
(3,571 Views)