Dynamic Signal Acquisition

cancel
Showing results for 
Search instead for 
Did you mean: 

non blocking analog input using PXI-6259 with digital output via PXI-6551

Hi All,

 

 

 

Analog waveform input via PXI-6259 and digital output via PXI-6551 have been separately verified.  I want to do the following.

 

 

 

1.  Begin an analog input (waveform) task on three channels with the 6259.(lasts 100 to 200ms).

 

2.  While this is happening a 6551 digital output task (I2C write) occurs and lasts 1ms or less).

 

3.  The analog input tasks continues and ends.

 

 

 

So I attempted

 

 

 

waveform = mreader.ReadMultiSample(blah, blah, blah)

 

myTask.Start();     // PXI-6259 task commences

 

WriteI2C(blah, blah)  // PXI-6551 task

 

 

while

 

(!myTask.IsDone)  // loop until PXI-6259 analog input task completes

 

{

 

}

 

myTask.Dispose();  // dispose off the PXI-6259 task.

 

However, I find that myTask.Start() is a blocking statement (execution does not get to the WriteI2C statement until the task is completed) which is not what I want.  How can this be remedied? 

I would like the execution to proceed as outlined in steps 1, 2, and 3.

Thanks very much in anticipation.

Anand

0 Kudos
Message 1 of 4
(6,501 Views)

Hi All,

 

This can (in principle) be performed using asynchronous threading.  NI has some nice examples that elucidate this.  Basically, the analog acquisition task is run in the background while the I2C write (which is much shorter) can be performed in the foreground. 

 

I currently have to first run the tasks in one function and then process the data (stored in a global variable called waveform) using a diferent function.

 

Once I'm more familiar with delegates, events, callbacks etc. things should be better.

 

Does anyone (especially NI C# gurus) have any tips on the above?

 

Thanks

 

Anand

0 Kudos
Message 2 of 4
(6,495 Views)

Hello All,

 

 

 

The following function call in my code

 

 

 

mreader.BeginReadMultiSample((Int32)(SampleRate * dAcquisitionTime), new AsyncCallback(myReadBack), myTask);

 

 

 

does not in some circumstances lead to call to the callback function myReadBack defined as

 

 

 

 

private void myReadBack(IAsyncResult ar)

 

 

{

 

if (runningTask == ar.AsyncState)// stores wawvform in the globally accessible array 'waveform'

 

waveform = mreader.EndReadMultiSample(ar);

 

}

 

 

 

Basically nothing happens when the mread.BeginReadMultiSample function is called.

 

Can someone at NI advise me in what situations this could be happening? 

 

I realize this is vague, but the only way we can discuss if I post my entire code here.  Any solutoins that could resolve this are welcome.

 

Thanks.

 

Anand

 

 

 

0 Kudos
Message 3 of 4
(6,483 Views)

Hello All,

 

After discussions with a colleague, it seems that the mreader.BeginMultiSampleRead(...) call with a AsyncCallback delegate might be linked with an event.  So when I run this via a from button, an event is raised.  So I am able to get this function to run. 

 

How does one call this function from within a non-button linked code?  Please advise.  Is there a way to raise an event when a function in which this mreader.BeginMultiRead) is embedded?

 

Thanks.

 

Anand

0 Kudos
Message 4 of 4
(6,481 Views)