Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDAQmx : scanning more channels for a real time application in cpp

Hi everybody, sorry in advance if I will appear a bit trivial and dummy... I am asked     1) to scan more - at the moment just 2 - channels from the DAQ "NI USB-6251", and     2) elaborate them in a certain way. The 2nd point has been obviously done, but the 1st - which should be supposed to be easier and well known - is actually giving me more problems. What I exactly have to do is acquire Analogic Voltage Signals (2 channels) in a buffer (long enough to let the 2nd step finish) and copy it in a somewhere variable to use it in the 2nd step. Nothing more. I am using the NIDAQmx.lib. For example I want to aquire these 2 signals with a Fc=10 Hz in a window of 1s (10 samples for each signals - then 20 samples), many many times, and every window I want to have these values in a variable which will be elaborated somehow (my 2nd step...)... What changes should I need? Thank in advance!!!  Pgallir
0 Kudos
Message 1 of 6
(3,398 Views)
Hi pgallir,
 
I've made some changes at your code to fit your needs.
  • I've changed the buffer dimensions and the data array dimension to get 10 samples per channel.

 

  • To acquire and analize the data every seconds you need to use a continuous acquisition, so "DAQmx_Val_ContSamps" in the  "DAQmxCfgSampClkTiming" function.

 

  • Besides that, you have to put the "DAQmxReadAnalogF64" in a while loop, to read continuously, and set an exit condition from the loop. In the example I'm attaching I just decided to acquire for 10 seconds. The exit condition is up to you.

 

  • As a post processing analysis I've calcualted the mean of the two channels acquired.

I'm attaching the example that should help you solving your problems.

Regards,

Andrea N.

Andrea N.
Principal Applications Engineer - Semiconductor EMEA
National Instruments Italy
Certified LabVIEW Architect - Certified TestStand Architect
0 Kudos
Message 2 of 6
(3,376 Views)
Grazie mille!!!
I will let you know if I will be in trouble again or not... 😄
Pgallir
0 Kudos
Message 3 of 6
(3,357 Views)
mmm.... just a question.

suppose to have an heavier processing analysis, how does it work on line?
I mean, read_task is a line command of the loop, then I don't read them simultaneously, do I?
Thank you again.
Pgallir

0 Kudos
Message 4 of 6
(3,307 Views)
...on the other hand, I got the _possible_ solution, since it does exist a function which let the DAQ acquire while at a certain point calls another function - which might be written by our own to post process the acquired datas...

I write what I supposed in the following to have a feedback and see if I am right or not....


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
...

    while(1)
    {
                if(_kbhit()){break;} // to stop the task when I want and go on...

                ...


                DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL);

    }
...


}
...

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
    int32       error=0;
    char        errBuff[2048]={'\0'};
    static int  totalRead=0;
    int32       read=0;
    float64     data[1000];

    /*********************************************/
    // DAQmx Read Code
    /*********************************************/
    DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));
    if( read>0 ) {
        printf("Acquired %d samples. Total %d\r",read,totalRead+=read);
        fflush(stdout);
    }

////////////////////////////////////******************************************//////////////////////////////////////////////////



// HERE I THINK I SHOULD DO MY ELABORATIONS WITH THE ACQUIRED DATAS



////////////////////////////////////******************************************//////////////////////////////////////////////////



Error:
    if( DAQmxFailed(error) ) {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
        printf("DAQmx Error: %s\n",errBuff);
    }
    return 0;
}


...

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








However, I have tried with the example "ContAcq-IntClk.c" , but it doesn't work because the compiler seems not to find these two functions - both of which should be declared in "NIDAQmx.h" and defined in "NIDAQmx.lib", isn't it?



1>------ Build started: Project: VC_ContAcqSamps_IntClk, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\admin\desktop\ppp\main.cpp(65) : error C3861: 'DAQmxRegisterEveryNSamplesEvent': identifier not found
1>c:\documents and settings\admin\desktop\ppp\main.cpp(66) : error C3861: 'DAQmxRegisterDoneEvent': identifier not found
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 9.00.21022
1>Copyright (C) Microsoft Corporation. All rights reserved.



What do I do, now?  I have totally lost  the way...


Just to summerize whereas I didn't fit my problem:
I have 2 channels to acquire and make something with these signals ( like 2 filters, give them to a Neuro-Fuzzy kernel, take the output and send it to  serial data), contineusly. I am using NI USB 6251  -  which should mean to use only "NIDAQmx.h", am I right? .


THanks in advance to anybody will help me.


0 Kudos
Message 5 of 6
(3,298 Views)
I forgot to post the code which gave me the errors... sorry...

Pgallir
0 Kudos
Message 6 of 6
(3,297 Views)