Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

c# example continuous acquisition error for PCI602xE

OS is WinXP SP2.
Framework 2.0 is installed
Compler is C# express (VS 2005)
I try to interface an old PCI-6025E board.
Drivers are nidqmx 8.3.1f0 and all examples are installed.
The problem is the continuous acquisition of an analog channel (both slow and high frequencies) with internal clock.
1. Making acquisition in Measurement and Automation explorer the board works properly
2. Acquisition compiling the C++ example (Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk) works
3. Acquisition compiling the C# example (Program Files\\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk") gives me the following situation:
 
In some cases I get immediatly the error in this (your) callback routine, in some other cases after 30-40 cycles.

private void AnalogInCallback(IAsyncResult ar)

{

try

{

if(taskRunning)

{

//Read the available data from the channels

data = analogInReader.EndReadMultiSample(ar);

//Plot your data here

dataToDataTable(data,ref dataTable);

analogInReader.BeginReadMultiSample(Convert.ToInt32(samplesPerChannelNumeric.Value),

analogCallback, null);

}

}

 

The 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.

Property:
NationalInstruments.DAQmx.DaqStream.ReadRelativeTo\n
Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition
Property:
NationalInstruments.DAQmx.DaqStream.ReadOffset
Corresponding Value:


Task Name: _unnamedTask<0>\n\nStatus Code: -200284

My question is:

Where is the error into the NI example? It seems that the callback routine is called but the buffer is empty or the buffer is in an overflow situation.

Best regards

Sergio garcia

 

 

0 Kudos
Message 1 of 9
(5,114 Views)
Hello Sergio.
 
Thank you for contacting National Instruments. 
 
I have been able to open the ContAcqVoltageSamples_IntClk C# project that you are working with and have a few troubleshooting suggestions for you to try.  First, when I open the MainForm.cs file, there are some helpful troubleshooting notes in the comments at the very top of the file.  They state that the rate of acquisition should be at least twice as fast as the maximum frequency component of the signal being acquired.  This will help the signal to be accurately sampled so the samples will be representative of the original waveform.  With this is mind, "it is important to make sure that the rate and the number of samples to read per iteration are set such that they don't fill the buffer too quickly.  If this error occurs (50410), try reducing the rate or increasing the number of samples to read per iteration."  This will help the buffer not fill up completely, which will prevent an overflow. 
 
In your case, it seems like the opposite is happening though.  The error message states that there are not enough samples to read and thus your acquisition is timing out.  The error message actually gives us a few things to try in order to remedy this situation.  It states that in order to prevent this error, "use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate".  I would recommend increaseing the timeout or reading faster in order to make samples available for your read operation. 
 
With these steps, we should be able to achieve the balance of acquisition and reading from the buffer to software.  Let me know if this helps and if you have any other questions, we would be happy to assist you further. 
 
Have a great day!
 
Brian F
Applications Engineer
National Instruments
 
 
0 Kudos
Message 2 of 9
(5,090 Views)
Hello Brian.
Thank you for your fast reply.
The situation is quite "strange" because, using the examples compiled with VC++, I can use a sample
frequency of 1kHz and I can read 1000 samples without any problem.
In C# case (obviously the PC and the card are always the same), using the same parameters,
I cannot obtain same results.

Suppose I use 10 Hz as frequency rate and 10 samples per reads.
I think that every about 100 ms the callback is fired and I read inside the callback 10 samples
(or I am wrong?)

I modify the code of the example to record both the samples reads and the time elapsed
with respect to the previous callback.

callback nr. samples read time elapsed from previous callback [ms]

1 10 no meaning
2 10 93
3 10 78
4 10 93
5 10 78
6 10 93
7 10 78
8 10 1578
9 10 78
10 10 1656
11 10 78
12 10 1171
13 10 3828
14 10 78
15 10 15
16 10 78
17 10 7093
18 10 93
19 10 78
20 10 93
21 10 125
22 10 93
23 10 93
24 10 78
25 ERROR: SOME OR ALL THE SAMPLES REQUESTED HAVE NOT BEEN ACQUIRED YET

Question 1:
If the samples are not yet available, why the callback has been called?

Question 2:
Time elapsed between callback are "strange",
the samples read with analogInReader.EndReadMultiSample are right.

Consideration:
The frequency is very low, but the program does not work.

In my opinion the callback function has to be called ONLY when there are 10 samples into the buffer to read.
After some cycles I have the callback, but analogInReader cannot give me the samples required.

Can I suppose that the analogInReader.synchronizeCallbacks = true
(made in a different mode with respect to Framework 1.1) has some problem and the
callback function is not synchronized properly?

Could be? Can you suggest some adjustment to this part?

Please give me your opinion

Best regards
Sergio Garcia
0 Kudos
Message 3 of 9
(5,085 Views)

Hello Sergio. 

I have attempted to replicate your issue with the ContAcqVoltageSamples_IntClk C# example, but have been unsuccessful in doing so.  I tried it in VS 2005 as well as Measurement Studio 2003 and both worked flawlessly.  I tried the default acquisition rate of 1000 Hz and I also tried 10 Hz. 

With this information, there must be something that differs in our system that is significant to the execution of the program.  One thing that I am a little concerned about is the C# express compiler.  Is there any way for you to obtain and compile the code in a basic VS 2005 compiler?  Can you try another machine with the C# express compiler to test if it is an issue specific to that computer?  Let me know how these tests go.  I will continue investigating if the express compiler is an issue. 

Have a great day!

Brian F
Applications Engineer
National Instruments

 

0 Kudos
Message 4 of 9
(5,059 Views)

Hello,

When I try to execute DigFreq-Buff-Cont-LargeRange2Ctr.c example with a PCI6602 card, I have exactly the same error message with the DAQmxReadCountF64 function.

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

      // DAQmx Configure Code

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

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

      DAQmxErrChk (DAQmxCreateCIFreqChan(taskHandle,"PCI6602_1/ctr0","",0.001,100000,DAQmx_Val_Hz,DAQmx_Val_Rising,DAQmx_Val_LargeRng2Ctr,0.001,4,""));

      DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_ContSamps,1000));

 


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

      // DAQmx Start Code

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

      DAQmxErrChk (DAQmxStartTask(taskHandle));

 


      printf("Continuously reading. Press Ctrl+C to interrupt\n");

      while( 1 ) {

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

            // DAQmx Read Code

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

            DAQmxErrChk (DAQmxReadCounterF64(taskHandle,1,10.0,data,1000,&read,0));

            printf("Acquired %d samples: %g\n",read, data[0]);

            fflush(stdout);

      }

 


This is my first work with DAQmx, so I don’t understand what’s wrong with my system (initialisation,…).

 

Thanks’ for help.



(English is not my native language so excuse me for language mistakes)

 

Best Regards

0 Kudos
Message 5 of 9
(4,901 Views)
teetra,

Are you using a C# compiler or VC++?  Seems that the last post indicated that they had different results depending upon which of the two they used.
Elijah Kerry
NI Director, Software Community
0 Kudos
Message 6 of 9
(4,878 Views)

Hello,

I'm working on Linux and use GCC compiler.

Yersterday, I found that if I comment the line :
DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_ContSamps,1000)); the error disappears. Now, I have just a problem of time out with this exemple.


I try the following code and have the same error :

    DAQmxErrChk(DAQmxCreateTask("Event1",&taskHandle));
    DAQmxErrChk(DAQmxCreateCICountEdgesChan(taskHandle,"PCI6602_1/ctr0","Event1",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));
    DAQmxErrChk(DAQmxSetCICountEdgesTerm(taskHandle,"PCI6602_1/ctr0","20MHzTimebase"));

    DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"/PCI6602_1/PFI38",1000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,100));

    //
    // DAQmx Start Code
    //
    DAQmxErrChk (DAQmxStartTask(taskHandle));
  
    //
    // DAQmx Read Code
    //
    DAQmxErrChk (DAQmxReadCounterF64(taskHandle,1.0,10.0,&data[0],1,&read,0));
    printf("Acquired %d samples : %.2f\n",read,data[0]);


If I comment the line with the fonction DAQmxCfgSampClkTiming, samples are acquired even if the measurement is different each time and wrong (the value is around 4000 Hz each time : 3597, 4707...).

I don't understand what's wrong, thanks for help.

0 Kudos
Message 7 of 9
(4,865 Views)
teetra,

For future reference, this question would probably get more views and more replies if it were posted on the DAQ forums since it doesn't really pertain to measurement studio in .NET. 

Is the error that you're receiving still "Some or all of the samples requested have not yet been acquired." ?  This could mean that you're never triggering the acquisition and so when you go to read there are no available samples.  Have you tried any of the examples that are included with the driver? 
Elijah Kerry
NI Director, Software Community
0 Kudos
Message 8 of 9
(4,843 Views)
It seems that my problem was my generator -_-' . I changed it and now there is no problem with the example DigFreq-Buff-Cont-LargeRange2Ctr.c, the measurement is ok. My developpement is now ok. Thanks Elijah for answer.
0 Kudos
Message 9 of 9
(4,829 Views)