Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Thousends of Empty Callbacks - Lower Frequenzy?

Hallo Everyone,

 

I am currently stuck at a strange problem: As soon as I start reading my Data from my USB-6210 I get tons of empty Callbacks with 0 Datasets to read. Here is my Code:

 

_frequenzy = 10000;

_clockTask = new Task();

_clockTask.COChannels.CreatePulseChannelFrequency("Dev2/freqout", "ClockPulses", COPulseFrequencyUnits.Hertz,
                COPulseIdleState.Low, 0, _frequenzy, 0.5);

_clockTask.Control(TaskAction.Verify);

_readAiChannelsTask = new Task();

_readAiChannelsTask.AIChannels.CreateVoltageChannel("Dev2/ai0", "Channel 1", AITerminalConfiguration.Differential, 0, 4,
                AIVoltageUnits.Volts);

_readAiChannelsTask.AIChannels.CreateVoltageChannel("Dev2/ai1", "Channel 2", AITerminalConfiguration.Differential, 0, 4,
                AIVoltageUnits.Volts);

_readAiChannelsTask.Timing.ConfigureSampleClock("/Dev2/PFI6", _frequenzy, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples,1000);

_readAiChannelsTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/Dev2/PFI6", DigitalEdgeStartTriggerEdge.Rising);

_readAiChannelsTask.Control(TaskAction.Verify);

_readAiChannelsTask.Start();

_readAiChannelsTask1Reader = new AnalogMultiChannelReader(_readAiChannelsTask.Stream);
_readAiChannelsTaskCallback = new AsyncCallback(AnalogInCallback);

_readAiChannelsTask1Reader.SynchronizeCallbacks = true;

_readAiChannelsTask1Reader.BeginMemoryOptimizedReadMultiSample(1000, _readAiChannelsTaskCallback, _readAiChannelsTask, _data);

_clockTask.Start();

 As you see I read 2 AI Channels with an external Clock. Problem is: I get tons of tons off Callbacks with no Data included. My CallBack looks liek this:

 

_readAiChannelsTask1Reader.EndMemoryOptimizedReadMultiSample(ar, out _numberOfDataSets);

if (_numberOfDataSets == 0)
{
    int x = 0;
}

StreamWriter sw = new StreamWriter(@"C:\AllTheData.txt", true);

for (int i = 0; i < _numberOfDataSets; i++)
{
   sw.WriteLine("#" + _totalNumber.ToString(CultureInfo.InvariantCulture) + ": " +
                      _data[0, i].ToString("0.000", CultureInfo.InvariantCulture) + "," +
                      _data[1, i].ToString("0.000", CultureInfo.InvariantCulture));
   _totalNumber++;
}

sw.Close();
sw.Dispose();

_readAiChannelsTask1Reader.BeginMemoryOptimizedReadMultiSample(-1, _readAiChannelsTaskCallback,_readAiChannelsTask, _data);

 As you see I check for empty CallBacks which accure Non-Stop and create massiv amounts of CPU-Load. Non-Empty Callbacks occure with 1k batches of data, as I configured. How do I avoid these?

 

An additional Question is: the Prescaler for the "external" Clock only reaches to 16. So the lowest available frequenzy I can measure is 6250Hz. I want to go below this (~2kHz). Is there any nice way to achive this? An internal Clock is not an option as I need to synchronize an encoder Read with the AI channels.

 

Best

Kevin

0 Kudos
Message 1 of 2
(5,475 Views)

Hi Kevin,

 

have you tried to use a standard example shipped with Measurement Studio? I would recommand the example AIContAcquisition to you. It is localed on your computer at:

C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.0\Synchronization\Multi-Device\AIContAcquisition

 

If this does not help you, please upload the complete files so I can test them here myself and debug them.

 

Regards,

Melanie

Best regards,
Melanie Eisfeld
Senior Applications Engineer, National Instruments Germany
Certified LabVIEW Developer
Certified TestStand Architect
0 Kudos
Message 2 of 2
(5,410 Views)