Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Sometimes get error -200278 after stop trigger

I've implemented a self test. On a USB-6210 device I looped back a DO to a DI and a DO to an AI.  The loopback DO-DI is for generating start and stop trigger. The DO to AI is for getting some valid input on the AI.

 

I've created two tasks:

TriggerOuttask an Acquisition task.

 

The stop trigger is configured  with DAQmxCfgDigEdgeRefTrig, using 2 pretrigger samples

 

I've implemented an acquisition thread that reads samples from the AI using DAQmxReadBinaryI16, with parameter numSampsPerChan equals N.  I call DAQmxReadBinaryI16 until DAQmxIsTaskDone() indicates that the task is stopped.

 

The problem is that sometimes  DAQmxReadBinaryI16 returns error:

-200278: Measurements: Attempted to read a sample beyond the final sample acquired.

 

Could this be caused in the situation that the stoptrigger comes after the call to  DAQmxIsTaskDone() and before the next call to DAQmxReadBinaryI1(). 

How do I handle the output parameters of the failed  DAQmxReadBinaryI1() (eg nr of samples) and what do I have to do with the posttrigger samples.  Without substracting the post trigger samples, I have the number of expected samples. If I substract them, I have too view samples.

 

Thanks in advance for the response..

 

Robert

Message Edited by RMW on 11-20-2009 06:51 AM
0 Kudos
Message 1 of 11
(5,023 Views)

Dear Robert,

 

Thank you so much for your post on our webforum. First of all I want to explain to you that I'm not a .NET programmer, however I do know Labview, and since we are using the same driver I hope to give you some clues of how this works (the driver approach is the same).

I found a Labview KB about this topic. Please review this KB, it hopefully give you some valuable information. What they do in Labview (this should be the same for your programming envirorment);

- you need to add the post and pretrigger samples; this is the number of samples in the task.

- every loop iteration you read N samples

- when the task is done and the number of available samples is smaller than the N samples you read the number of available samples will be read.

- when the samples per read = 0; no read action will take place

 

Here some further documentation in the example VI;

1. Create an analog input channel to measure voltage.
2. Set the  sample clock rate  and the number of post Stop trigger samples to acquire (minimum of 2).
3. Set the buffer size.
4.  Configure the task to start filling the buffer after recieving a digital edge and stop
filling the buffer (plus the number of post trigger samples) after recieving another digital edge.
5. Set the buffer read position to "Current Read Position".

- By default this property is set to "First Pretrigger Sample" when using a reference trigger. By setting it to "Current Read Position" the DAQmx Read will be able to read samples that are being put into the buffer after the start trigger occurs, just like a normal Continuous Read. If this was not changed the DAQmx Read would wait until the reference trigger was recieved before it was allowed to get samples from the buffer.
6. Start the acquistion.
7. Read data until stop trigger is recieved and then read the remaining samples in the buffer at the same rate.

-If the task is done (Stop trigger has been recieved) then compare number of samples left in the buffer
with the number of samples to read. Send the smaller of the two to the DAQmx Read.

-If the number of samples remaining in the
buffer is greater than 0, a read will occur
and the loop will not stop. If the buffer is
empty and the task is done then no read
will be done and the loop will be stopped.


8. Clear the task and check for errors

 

I hope this will bring you further,

 

Best regards,

 

 

Martijn S
Applications Engineer
NI Netherlands
0 Kudos
Message 2 of 11
(4,990 Views)

Hi Robert,


What if you just skip the DAQmxReadBinaryI16 after the stop trigger is activated?

 

Error -200278 is described in the following Knowledge Base.

 

This Knowledge Base states that if you get this error, you're trying to acquire data from the DAQ board, but in the DAQ board itself already stopped acquiring new samples.

 

I hope this will help you completing your program!

 

Regards,

Peter S

0 Kudos
Message 3 of 11
(4,985 Views)

Thank you very much for your replies. Always good to hear that someone cares.

 

 

How do I for sure know there was a stoptrigger.  Currently I call  DAQmxIsTaskDone to check if the task is done. If the task is not done, I call DAQmxReadAnalogF64. I expect that error -200278 would never occur, because I checked, but still I sometimes DAQmxReadAnalogF64 returns error -200278.

 

Here is the loop:

 

 

            while (nDacStatus == 0 && !fDAQStopped)           

            {

                // Read the samples
                nDacStatus = DAQmxReadAnalogF64(
                    m_hDAQmxDiagTask,
                    mv_ulDiagnosticSampleRate / mv_nNIDaqReadsPerSecond, // This value must match with the parameter in DAQmxCfgSampClkTiming
                    (float64)m_unDiagnosticTime,
                    DAQmx_Val_GroupByChannel,
                    pdBuf,
                    nMaxNrSamplesToRead - ulFetchedSamples,
                    &nSamplesRead,
                    NULL);
                TraceError(__FUNCTION__ " DAQmxReadAnalogF64", nDacStatus);

                if (nDacStatus == 0)
                {
                    nDacStatus = DAQmxIsTaskDone(m_hDAQmxDiagTask, &fDAQStopped);
                }
               

                if (nDacStatus == 0)
                {
                    ulFetchedSamples += nSamplesRead;
                    pdBuf += nSamplesRead;
                   
                    if (fDAQStopped)
                    {
                        // A number of post trigger samples after the reference trigger are fetched. Correct this. See also
                        // the DAQmx manual on DAQmxCfgDigEdgeRefTrig
                        ulFetchedSamples -= nPostTriggerSamples;
                    }

                }
            }

 

0 Kudos
Message 4 of 11
(4,980 Views)

Hi RMW,

 

First of all, I need to clarify, that I do not have a lot of experience with written programming, so I'm not quite able to fully understand it, or to improve it.

 

If you just look at the error, the KB I mentioned states the following:

"Attempted to read a sample beyond the final sample acquired."

 

This suggests, that the following error occured:

For example, your sample rate is 50S/sec and the Samples to Read value is 10.

You stopped acquiring data, but by using the DAQmxIsTaskDone function, you verify if there are still samples available. But right now it is possible that there is not a multiply of 10 samples available, but just a few (let's say 8). Then the task has not completed, but you aren't able to read these 8 samples, since you need to read 10 at a time.

 

To resolve this issue, you must not only find out if the task is done, you also need to read the amount of samples in the boards' buffer (sampsPerChanToAcquire). If there are only 8 samples left, you must use this to modify the sampsPerChanToAcquire value from 10 to 8.

 

For example:

If DAQmxGetBufInputOnbrdBufSize < 10

Then sampsPerChanToAcquire == DAQmxGetBufInputOnbrdBufSize

Else sampsPerChanToAcquire == 10

 

I'm not quite sure how to implement this, but I'm quite sure that the error is caused for the above mentioned reason.

 

Hopefully this will provide you with the required information to get the application working!

 

Best regards,

Peter S

Message Edited by Peter S on 11-30-2009 02:02 PM
0 Kudos
Message 5 of 11
(4,929 Views)

Thank you Peter for your reply.

 

I don't think your suggestion is correct. It implies that I have to check the number of samples in the buffer before I read the samples. This will not work because normally DAQmxReadBinaryI16blocks untill the number of samples are available. What I do see is that DAQmxReadBinaryI16 returns less samples than requested, in case that the stop trigger occurred.

 

When I understand DAQmx correctly, the stop trigger stops the task. So when there was a stop trigger, DAQmxIsTaskDone would indicate that thetask is done. In that case I don't call DAQmxReadBinaryI16 anymore.

So I still don't understand what happens here. Could it be that when the stoptrigger occurs  after I call DAQmxIsTaskDone but before I call DAQmxReadBinaryI16 I end up withthis error?

 

 

RMW

0 Kudos
Message 6 of 11
(4,905 Views)

Hi RMW,

 

Have you read the KB, of which I posted a link (4 or 5 posts upwards)?

 

This KB states the following:

 

This error occurs when a DAQmx read function attempts to return data after the board has stopped acquiring it. One common occurrence of this error is when a DAQmx read function is used inside of a while loop when the task is configured for a finite acquisition. By configuring a finite acquisition at the ‘DAQmx Timing’ VI, the board will only acquire data for a finite period of time. Once the board has acquired the specified number of samples, it will stop acquiring data. Thus, calling the DAQmx read function at this point will return error -200278. The solution to this problem is to configure the task to perform a “continuous acquisition.” When this option is selected at the ‘DAQmx Timing’ VI, the board will continue acquiring data until the task is explicitly stopped.

 

 This describes a second possible error. Did you create a Finite Sampling task? What happens if you change the timing option to Continuous samples?

 

Regards,

Peter S

0 Kudos
Message 7 of 11
(4,880 Views)

Peter,

 

I use a reference trigger as stop trigger (that's the only way to implement a stop trigger as far as I know). A reference trigger can only be used in combination with finit sampling. Configuring a continuous  sampling results in error -200358: Measurements: An attempt has been made to configure a reference trigger when the sample mode of the sample clock has been configured for continuous sampling. Reference trigger is only applicable for finite sampling.

 

I based my code on an example from NI: "Cont Acq-Int Clk-Dig Start and Ref". So the way I use it is correct, and it works correctly most of the time...

 

 

 

RMW

0 Kudos
Message 8 of 11
(4,867 Views)

Hi RMW,

 

I'm sorry for the delay in answering your questions: I've been away for a course and also been sick for a time.

 

I've been looking at your information again, and found the following:

You say you used the "Cont Acq-Int Clk-Dig Start and Ref" example in which you have found the DAQmxIsTaskDone function. This function was carefully selected for this example because this is a function which will only work correct with the "Sampling Mode" set to "Continuous Sampling". If you want to do a finite measurement, please replace the DAQmxIsTaskDone function with the DAQmxWaitUntilDone function.

 

Please verify if this will solve your problems!

 

Regards,

Peter S

0 Kudos
Message 9 of 11
(4,779 Views)

Peter,

 

I'm getting confused and desperate now.

 

Let's go back to wher I started. I have to perform an continuous acquisition that is started via a start trigger, and must be stopped with a stop triggen. I've searched the NI documentation and internet site for how to do it. I've found the following example http://zone.ni.com/devzone/cda/epd/p/id/908 (It also contains labview code)

 

It is an example for exactly that what I want: continuous sampling with start and stop trigger. In the example timing is configured as finit sampling.  DAQmxIsTaskDone is used to chect when to stop.

I based my implementation on this example.

 

Now you tell me that  DAQmxIsTaskDonecannot be used with finit measurement.

 

 

But now I'm also starting to get another problem. In tests I see the following error:

 

DAQerrors -200279: Measurements: Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.

 

I can imagine that this error occurs because of the size of the sample buffer used must be exactly the size of the number of samples you want to retrieve via DAQmxReadBinaryI16

 

 

Can someone please tell me how to implement continuous sampling with start and stop trigger?

 

RMW

0 Kudos
Message 10 of 11
(4,766 Views)