05-06-2021 04:49 AM
Hi,
So we are using DAQmx with .net 4.5.
NI version: 17.0.0.49152
Device used USB-6211
We have 3 tasks running, one for DIO, one for AIO lines, and now one for Counter.
Counter task below
private string channelName = "/Dev2/ctr0";
private string edgeSource = "/Dev2/PFI0";
private CounterSingleChannelReader myCounterReader;
private int referenceCounterValue = 0;
private int counterValue = 0;
private double sampleRate = 200000;
private int samplesPerChannel = 1;
public void InitTask()
{
try
{
referenceCounterValue = 0;
counterValue = 0;
counterReadTask = new Task();
isRunning = true;
referenceCounterValue = 0;
counterValue = 0;
counterReadTask.CIChannels.CreateCountEdgesChannel(channelName,
"counterTaskRead", edgeType, 0, countDirection);
counterReadTask.Timing.ConfigureSampleClock(
edgeSource,
sampleRate,
SampleClockActiveEdge.Falling,
SampleQuantityMode.ContinuousSamples,
samplesPerChannel);
counterReadTask.Control(TaskAction.Verify);
counterReadTask.Start();
runningTask = counterReadTask;
counterReadTask.Stream.Timeout = 100;
myCounterReader = new CounterSingleChannelReader(counterReadTask.Stream);
inputCallback = new AsyncCallback(CounterReadCallback);
myCounterReader.SynchronizeCallbacks = true;
myCounterReader.BeginReadSingleSampleDouble(inputCallback, counterReadTask);
}
catch (DaqException e)
{
counterReadTask.Dispose();
runningTask = null;
isRunning = false;
Log.Info(string.Format("CounterInputHelper exception: {0}", e));
}
}
private void CounterReadCallback(IAsyncResult ar)
{
try
{
if (runningTask != null && runningTask == ar.AsyncState)
{
counterValue = (int)myCounterReader.EndReadSingleSampleDouble(ar);
if (isRunning)
{
myCounterReader.BeginReadSingleSampleDouble(inputCallback, counterReadTask);
}
}
}
catch (DaqException e)
{
if (isRunning)
{
myCounterReader.BeginReadSingleSampleDouble(inputCallback, counterReadTask);
return;
}
}
}
We receive these exceptions repeatedly.
- CounterInputHelper exception: NationalInstruments.DAQmx.DaqException: 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
Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition
Property: NationalInstruments.DAQmx.DaqStream.ReadOffset
Corresponding Value: 0
Task Name: _unnamedTask<0>
Status Code: -200284
vid NationalInstruments.DAQmx.Internal.CounterSingleChannelReaderImpl.EndReadSingleSampleDouble(IAsyncResult asyncResult)
vid NationalInstruments.DAQmx.CounterSingleChannelReader.EndReadSingleSampleDouble(IAsyncResult asyncResult)
vid
Have tried adjusting the sample rate, and timeout with no improvements.
Any tips & ideas?
07-01-2021 05:09 AM
Hi,
Are you using an external clock?
Best regards
07-19-2021 04:51 AM
While investigating, I noticed that if SqlConnection
is instantiated while providing a connection string and the ConnectionString
setter is subsequently called, the exception will be thrown. The exception will also be thrown by simply invoking the setter twice.