I am trying to create a task that continuously measures the period of a signal.
here is the error:
NationalInstruments.DAQmx.DaqException: Data was overwritten before it could be read by the system.
If Data Transfer Mechanism is Interrupts, try using DMA. Otherwise, divide the input signal before taking the measurement.
Task Name: Measure Period
Status Code: -200141
at cC.c()
at dQ.a()
at bz.EndReadMultiSampleDouble(IAsyncResult asyncResult)
at NationalInstruments.DAQmx.CounterReader.EndReadMultiSampleDouble(IAsyncResult asyncResult)
and here is the code I am using to set it up:
public PacketDecoderRM_PW()
{
startTime = DateTime.Now;
Console.WriteLine (startTime);
try
{
myTask = new Task("Measure Period");
myTask.CIChannels.CreatePeriodChannel("Dev1/ctr0",
"rx input",
10E-06,
400E-06,
CIPeriodStartingEdge.Rising,
CIPeriodMeasurementMethod.LowFrequencyOneCounter,
0.00099999999999988987,
4,
CIPeriodUnits.Seconds);
myTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples);
myTask.Control(TaskAction.Verify);
myCounterReader = new CounterReader(myTask.Stream);
MyAsyncCallback = new AsyncCallback(processSamplesCallback);
myCounterReader.BeginReadMultiSampleDouble(10000, MyAsyncCallback, null);
TaskRunning = true;
}
catch(Exception ex)
{
myTask.Dispose();
Console.WriteLine(ex.ToString());
TaskRunning = false;
}
}
and the callback:
public void processSamplesCallback(IAsyncResult ar)
{
try
{
double[] Data = myCounterReader.EndReadMultiSampleDouble(ar);
for(int i=0;i < Data.Length; i++)
{
switch (pulseDecoderState)
{
case 0: // detecting SOF
if (classifyPulse(Data[i]) == 5)
pulseDecoderState = 1; // found a start pulse so advace the state to look for sync
break;
case 1: // detect SYNC
detectSync(Data[i]);
break ;
case 2: // decoding DATA
decodeData(Data[i]);
break ;
default:
// Should not reach here so reset if we do!
resetDecoder() ;
break ;
}
}
// continue to acquire and increment the cycle number
myCounterReader.BeginReadMultiSampleDouble(10000, MyAsyncCallback, null);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}