Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx C# threading problem?

Hi all,

 

I'm writing a program in C# (VS2008) that reads multiple analog channels from a PCI-6036E acq.board. I used the code from the ContAcqVoltageSamples_IntClk example. The ContAcqVoltageSamples_IntClk example inits the board and call an event everytime samples are ready to be read out of the acq.board buffer. I've included a simple counter that shows how many times samples have been taken.

The strange thing is that the counter textBox, a simple up counter that represents the number of samples taken, is not showing the correct number of samples taken. Instead of counting 0,1,2,3,...etc. it counts 1,3,5,7,etc. It looks like the textBox has a separate thread that is not updated in the correct manner.

Does anyone have a clue what's going on and how to solve this?

Snips of the code below.

 

 private void Form1_Load(object sender, EventArgs e)

{

  AITask =
new Task();

  AITask.AIChannels.CreateVoltageChannel("Dev1/ai0:2", "", AITerminalConfiguration.Rse, -10.0, 10.0, AIVoltageUnits.Volts);AITask.Timing.ConfigureSampleClock(

"", .5, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);analogInReader = new AnalogMultiChannelReader(AITask.Stream);

  runningTask = AITask;

  analogInReader.SynchronizeCallbacks =
true;

}

 

private void Start_Click(object sender, EventArgs e)

{

  counter = 0;

  analogInReader.BeginReadMultiSample(1, process, AITask);

}

 

void process(IAsyncResult ar)

{

  try

  {

    if (runningTask == ar.AsyncState)

    {

      jdata = analogInReader.EndReadMultiSample(ar);

     analogInReader.BeginReadMultiSample(1, process, AITask);

    textBox2.Text = jdata[2, 0].ToString();

 

    textBox1.Text = counter.ToString();

   counter++;

   }

 }

  catch (DaqException)

  {

  }

Message Edited by R.C.H. on 12-31-2008 05:19 AM
0 Kudos
Message 1 of 1
(2,752 Views)