Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Application Crashes using Ni DAQmx on Red Hat with NI PCI-6025E

Hi everyone,
 
 I am using DAQmx for NI PCI-6025E multifunction DAQ cards on Red Hat.
 I want to record sound of 1 minute simultanously from 8 channels.
 when I use SampleRate= 16000 then the application not crashes but the Sound Quality is Low
 But at SampleRate= 32000 the Sound Qulaity is good but application Crashes when calling
 DAQmxReadBinaryI16 API.
 
 here is my code
 

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0:7","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",32000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,32000*60*8));

DAQmxErrChk (DAQmxStartTask(taskHandle));

while( 1 ) {    ////////  short *data =new short[32000*8*60]  buffer for storing samples

DAQmxErrChk (DAQmxReadBinaryI16(taskHandle,32000*60,32000,timeout,DAQmx_Val_GroupByScanNumber,data,32000*60*8,&read,NULL));

if( read>0 )

          {

             // here i call another thread to encode samples in data buffer using lame library

          }

  }

when I execute this code , I get 1 minute sound file correctly and then start reading for next minute so after expiring timeout the application crashes.

so what should i do to acquire data with sample rate 32000.

 thanx

0 Kudos
Message 1 of 11
(4,255 Views)
Hi amjadqau -

What happens when the application crashes?  What is the behavior?  Is there an error message returned?  If so, what are the error number and the text of the message?  The code you're showing here looks okay, so I'd like to know more about how it's "crashing".
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 2 of 11
(4,236 Views)

Hi

 Thanks for your response.

  when I call the Read API of DAQmx (DAQmxReadBinaryI16) then it works fine for the 

1st or 2nd minute  (as i record/read sound data samples of 60 seconds at one time) 

and the samples read by this API are correct. but when this API is called for 3rd time (minute)

then  this API returns the error value (-200284) and the out parameter of this API (which is the

samples read per channel) is 0(means no samples are read).

int read;  short *data=new short[32000*60*8];  while(true){

int retcode=DAQmxReadBinaryI16(taskHandle,32000*60,timeout,DAQmx_Val_GroupByScanNumber,data,32000*60*8,&read,NULL)); }

when this is called for 1st,2nd time then out parameters, data buffer=filled with samples of 8 channels

and the read =no of samples in 1 channel (1920000) and retcode is positive.

but when it is called for 3rd time then read value is 0. and retcode is -200284.

so what can be done to solve this problem.

 thanx .

0 Kudos
Message 3 of 11
(4,228 Views)
Hi amjadqau -

The text of that error is:
Some or all of the samples requested have not yet been acquired.

To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger,  make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.


In the code you've posted, your timeout is a variable name.  What is its value?  Have you tried lengthening it or changing it to -1?  (A value of -1 means 'no timeout'.  It will wait forever.)  Also, if the value is 0 then the function will only try once to read the samples.  If every one of the samples is not present in memory yet, it will return with an error.

I encourage you to narrow down the cause of the problem by running an example program out-of-the-box.  Please run the example found in this folder: C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk  It performs a continuous analog acquisition using the onboard clock, which is what you're trying to do.  If this code returns an error of its own, then there may be a problem with your driver installation or the board itself.  If the code runs without complaint, then the problem is somewhere in your own program.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 4 of 11
(4,223 Views)

Hi Sir

   I tried that example C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int     Clk.

      it works fine  but when I made diffrent changes to it as my Requirments

     - continous data acquisition from 8 channels

     - SampleRate = 32000 and Buffer size = 32000*60*8 (hold the samples in 60 seconds of 8 channels at 32000 SampleRate )

     - timeout =60 (sec)

    - change the reader API to DAQmxReadBinaryI16()   also used short type for the buffer and assign memory at heap.

      when I made these changes to this example then I see that it reads 1920000 samples in 1st minute,2nd and 3rd

 after reading for 3rd time the application didnt crashed but didnt display the samples any more (means stops at that time).

 when I used the timeout = -1 then it acquire data for 5 minutes but stops after that.

 I also tried with same buffer but high samplerate then also after 4 or 5 minutes it stoped.

 I suspect some problem with the buffer.

  So Plz help me to find out the problem.

Thanx

 

0 Kudos
Message 5 of 11
(4,208 Views)
  Hi ,  
  The Application stops means that the same error code comes (-200284)
   so can you please tell me that what can be the buffer size because I
   am confused and have problem that for the sample rate =32000 what should
   be the buffer size to acquire samples of 8 channels for 1 minute.
   
   Also I am using Lame 3.97 to encode these samples and dump into mp3 files.
 
   I am waiting for your response.
            Thanks.  
0 Kudos
Message 6 of 11
(4,196 Views)
Hi amjadqau -

Could you please post the edited example program?  I'd like to take a look at it to fully understand the changes you made.

I should also let you know that I've never used Lame before, and I won't be able to help you with that software.  However, the problem here seems to be with NI's driver API, so we should be able to solve it without having to worry about the Lame code.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 7 of 11
(4,188 Views)
Hi David
 
       what I need from this program is to always display this message after every 1 minute wait for Reading DAQ card
     The Samples Read are = 1920000
   
     (As because I need 1 minutes Samples of 8 channels from DAQ card )
 
     this program works fine from 3 to 9 minute but after that it starts showing error in Read API which shows error code (-200284).
     I also checked it for diffrent timeout values.
 
       Thanks.
 
 here is the code ..
 
#include "NIDAQmx.h"
#include <stdio.h>
#define SAMPLERATE  32000
#define BUFFERSIZE 32000*60
#define NUMCHANNEL 8
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
int main(void)
{
      TaskHandle taskHandle=0;
       int32 read,totalRead=0;
       short *data=new short[BUFFERSIZE*NUMCHANNEL]
       char errBuff[2048]={'\0'};
       DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
       DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0:7","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
       DAQmxErrCh(DAQmxCfgSampClkTiming (taskHandle,"",SAMPLERATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,BUFFERSIZE*NUMCHANNEL));                                                                                                                                                                 
       DAQmxErrChk (DAQmxStartTask(taskHandle));
       while(1)
         {
        
        DAQmxErrChk (DAQmxReadBinaryI16  (taskHandle,BUFFERSIZE,120,DAQmx_Val_GroupByScanNumber,data,BUFFERSIZE*NUMCHANNEL,&read,NULL));
                                        // I also tried timeout -1
         if(read>0) {
                         totalRead++;
                         printf("\n The Samples Read are =%d\n",read);
                        }

          }

Error:

         if( DAQmxFailed(error) )

         DAQmxGetExtendedErrorInfo(errBuff,2048);

         if( taskHandle!=0 ) {

                         printf("\n Closed the Handler\n");

                        printf("\n the Count is %d",totalRead);

                        DAQmxStopTask(taskHandle);

                       DAQmxClearTask(taskHandle);

                                 }

 return 1;

}

 

 

      
 
 
0 Kudos
Message 8 of 11
(4,182 Views)
Hi amjadqau -

Is this the actual code you built from the example program?  In addition to a few syntactical and spelling errors, it's lacking the event callbacks used to notify the driver of a Read opportunity.  (This is the standard--and recommended--method of coding a DAQmx acquisition or generation in C.)  I couldn't get it to compile and run properly, so i took the example we discussed and modified it myself to achieve your appliation.  The working code is attached, and I added comments to the header block to explain my changes step-by-step.

My suspicion is that you either had a memory leak or were allocating the data array on the stack.  Either of these situations can lead to a crash or other odd behaviors after the program has run awhile.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 9 of 11
(4,159 Views)
Hi David
 
     Thanks for your interest:
     I will talk about  that code you have sent.
     
     1.  DAQmxErrChk (DAQmxCfgSampClkTiming  (taskHandle,"",RATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,RATE*PERIOD*8*2));                       
      why the buffer size (RATE*PERIOD*8) is multiplied with 2. because when I run this code , the system was hanged
      and there is was no result.
    
      then I removed the 2 from this API and leave only (RATE*PERIOD*8) this value. and remaining code is leaved as it is.
 
      when I tested the code. 
      a)  it worked fine for 63 minutes and then application stops to show any result(means in running but not showing any thing)
      b)  it worked for 316 minutes and then application hanged.
           each time I run this code it worked for some time and then stoped. so improvement is there but the problem is same.
 
      so it means that it does not seems to be reliable, may be because of that after each minute it deletes the buffer and then create it.
 
     Thanks.
 
     
     
0 Kudos
Message 10 of 11
(4,149 Views)