Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous analog acquistion without blind time and without infinite timeout

I am writting an application that needs to monitor an analog signal 100% of the time (no down time). An external analog circuit monitors the analog signal too and triggers a PFI input to start the sampling.

 

I create a task that is pending on DAQmxReadAnalogF64 and triggered by a PFI input.

 

The first issue I had with this was that to ensure 100% detection time I had to use an infinite time out i.e. a front on PFI would be detected 100% of the time. An infinite timeout was not the greatest as it prevented my application from exiting (task would never quit).

 

I added a timeout of 1s and this fixed the issue of having the task to prevent the application from exiting. However now, every 1s I need to stop the acquistion task, start it again and start a new read. My understanding of this is that now I'm not able to detect a front 100%, since part of the time I spend re-initializing the acquisition task.

 

This is the code I use - could somebody tell me if there is a way to make this code able to detect fronts on PFI 100% of the time, even just after the read has reached a timeout? (code shortened because apparently they are limitations with message length)

 

 

while(true == m_RunTask)
{
    int32 startTastStatus = DAQmxStartTask(m_TaskHandle);

    

    samplesRead = 0;
    

    int32 readAnalogStatus = DAQmxReadAnalogF64( m_TaskHandle,
                                                                             -1,
                                                                             m_ReadTimeOut,
                                                                             DAQmx_Val_GroupByScanNumber,
                                                                             readBuffer,
                                                                             m_NumSamples,
                                                                             &samplesRead,
                                                                             NULL
                                                                             );
        int32 stopTaskStatus = DAQmxStopTask(m_TaskHandle);

        switch(readAnalogStatus)
        {
            case 0:
            {
               double * p_Data = new double[samplesRead*m_NumChannels]; // OKed

               for(uint32_t i = 0; i < static_cast<uint32_t>(samplesRead)*m_NumChannels; i++)
               {
                  p_Data[i] = readBuffer[i];
               }

              NewTriggerHandle(p_Data, samplesRead);

              delete [] p_Data; // OKed

              break;
            }
           case DAQmxErrorSamplesNotYetAvailable:
           {
               TimeOutHandle();
               break;
           }
           default:
           {}
        } // switch(readAnalogStatus)
    } // while(true = m_Run)

0 Kudos
Message 1 of 2
(2,950 Views)

Hi jstoezel-

 

     The only way to accomplish the functionality that you want is to set your timeout to some reasonable value (like 1 second) and then clear the specific timeout error.  You will need to pull the error code that is generated from each iteration of the loop using an error check function and compare that to the actual timeout error code value.  If those two match, you will need to handle the error code appropriately (ignore it, pass a null value to it, etc).  Then you can continue to iterate your DAQmxRead.  If those error codes do not match, then your code will actually terminate as it should.

 

     This should work for you.  Best of luck with your application!

Gary P.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,921 Views)