Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxGetReadAvailSampPerChan always returns zero

Hi,
 
I am trying to check the number of available samples in a continuous sampling app.  Here is my code
 
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",SampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,BuffSize));
also, in order to avoid the overwritten error frequently occured, I set the RelativeTo property as
 DAQmxErrChk (DAQmxSetReadRelativeTo(taskHandle,DAQmx_Val_MostRecentSamp));
then in a loop, I try to check the available sample number as
DAQmxErrChk(DAQmxGetReadAvailSampPerChan(taskHandle,read));
 
Now the problem is, read is always zero. Would anyone please tell me what's wrong with my code?
 
David
Message 1 of 7
(4,114 Views)
Hello David_Lin,

There are several things you want to consider when getting a buffer overwritten error. What error code number did you get?

Take a look at these resources:

How Can I Avoid Error -10846 (Overwrite Error) in LabVIEW?

Data Acquisition Errors -10845 and -10846, What Is the Difference?

With regards to your code. As I see it when you set the read relative to, you are specifying the point in the buffer at which to begin a read operation. You have selected the DAQmx_Val_MostRecentSam, it starts reading samples relative to the next sample acquired. What have you set as the offset? If you set the offset to -1,  this will read the last sample acquired.

I see that you are also using the "DAQmxGetReadAvailSampPerChan" function, which gets the status of the available samples per channel property. This property indicates the number of samples available to read per channel.

Take a look at the NI DAQmx C Reference Help, it is an awesome resource to refer to when coding with the DAQmx driver.

I'm not quite sure I understand what the issue is. Can you please clarify? Are you then doing a DAQmx read and getting "0" instead of real data?

Regards,
  Sandra T.

Applications Engineer | National Instruments
0 Kudos
Message 2 of 7
(4,099 Views)

"I see that you are also using the "DAQmxGetReadAvailSampPerChan" function, which gets the status of the available samples per channel property. This property indicates the number of samples available to read per channel."

Yeah, it is exactly where my problem is. I tried to get the available samples per channel, but it always returns zero, which means no sample is available all the time. There must be something thing wrong. Then I change the tast from continuous sampling to finite number sampling and then it worked correctly. Why didn't DAQmxGetReadAvailSampPerChan work in continous sampling mode? Is it because I set DAQmx_Val_MostRecentSam? For the offset, I didn't change it and it should be the default value.

David

0 Kudos
Message 3 of 7
(4,092 Views)
David,
 
From your posted code snippet, it would appear as though you are never starting (DAQmxStartTask) your task.  This should be done after you call DAQmxSetReadRelativeTo(...).  Without this, the hardware isn't going to start converting data, so I would expect that there would be none available.
 
Hope this helps,
Dan
0 Kudos
Message 4 of 7
(4,083 Views)

Actually, I did start the task after I configured DAQmxSetReadRelativeTo. I just forgot to paste the code.

 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",SampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,BuffSize));
 DAQmxErrChk (DAQmxSetReadRelativeTo(taskHandle,DAQmx_Val_MostRecentSamp));
 DAQmxErrChk(DAQmxStartTask(taskHandle));

Then I use DAQmxGetReadAvailSampPerChan to check the available number of samples as

DAQmxErrChk(DAQmxGetReadAvailSampPerChan(taskHandle,read));

The problem is read always returns zero.

David

0 Kudos
Message 5 of 7
(4,057 Views)
David,
 
Do you see this behavior if you don't call DAQmxSetReadRelativeTo?  The reason I ask is because I've never really had a problem reading the available samples per channel, however, it is quite rare for me to modify the read relative to attribute.
 
Dan
0 Kudos
Message 6 of 7
(4,047 Views)

Hi,

 

Turns out I am having exactly the same problem. Continuous acquisition is working fine for reading a defined number of samples (read function returns immediately) but I cannot manage to have the read all available samples working (see https://github.com/ni/nidaqmx-python/issues/49).

 

The function DAQmxGetReadAvailSampPerChan is always returning zero for me too.

 

Is there any solution for this problem?

0 Kudos
Message 7 of 7
(2,786 Views)