Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

BeginReadMultiSample using code generated trigger

I'm using the code below to successfully acquire multiple channels of analog data which is triggered by positive voltage supplied by the hardware.  What I need to do for a particular state of the application (ScopeMode), is to set the trigger voltage high using code in the application.  Here's how I tried unsuccessfully to do the latter.

 

//instantiate the data reader

reader = new AnalogMultiChannelReader(slaveTask.Stream);

reader.SynchronizeCallbacks = true;

reader.BeginReadMultiSample(nChanls * Convert.ToInt32(cbxSamplesPerChannel.Text), new AsyncCallback(slaveCallBack), null);

//we will need to trigger the A/D if we're in scope mode

//we may need to delay the onset of the trigger while new thread is spawned

//Thread.Sleep(5000);

 

if (AppMode == ApplicationMode.ScopeMode)

{

awScopeMode.WriteSingleSample(true, 5.0); //Set the ScopeMode Trigger high

}

 

The voltage for the ScopeMode trigger goes high, but the BeginReadMultiSample() function is never triggered.  I tried some delays before trying to trigger and also made the trigger voltage be low then high and then low again.

 

Any suggestion on how to make this work will be appreciated.

John

 

 

0 Kudos
Message 1 of 5
(4,744 Views)

Hi John,

 

First of all, what hardware are you using for this application? Depending on what you're using could change the way we handle this situation. 

 

Just based on your description, it sounds to me that maybe you're missing a trigger. You may be starting the read task after you set  the voltage levels high, or the read task has already been running and hasn't had a chance to re-arm. If we can figure out what card you're using and a larger scope of your project, that would help figure out what is going on. 

 

Chris W
0 Kudos
Message 2 of 5
(4,729 Views)

Hi Chris. Thanks for your reply.  The NI card that I'm using is the PCI-6251.  The basic requirements specified by the person that I'm developing for are:  Build an application that acquires 16 channels of A/D when triggered by a +5 volt signal from a laboratory intrument.  If the the application is in Experiment Mode, write the data to file and display the voltage trace(s) on the virtual oscilloscopes..  If the application is in Scope Mode display the voltage trace(s) on the virtual oscilloscopes, but don't write the data to file.  Two additional requirements: 1. Read a byte from the laboratory instrument that encodes a trial type, 2. Signal the laboratory instrument that the application is busy i.e is acquiring A/D by setting a D/A line out from the card to +5 volts. Set the line to 0 volts when A/D is finished. This is termed the Ready signal.

 

Control flow is as follows: 1. btnStart_Click() invokes the function AcquireData(). AcquireData() instantiates the DAQmx objects needed for the A/D acquisition. 3. The external trigger goes high and the data is collected and displayed on the virtual oscilloscopes as specified by values in the controls on the form.  4. Repeat steps 1 - 3.  To end the acquisition loop, press the Escape key and trigger a final data collection.

 

After implementing this, the person specifying the requirements clarified that when in Scope Mode, the external trigger signal is not available.  Thus my current problem arose.  I need to supply to trigger voltage myself from within the application.  I am trying to do that using an analog out voltage and connecting it to the Trigger input.  The problem as I've stated is I can set the trigger input high in this way, but the A/D conversions are never triggered.

 

As I understand the Asychronous Programming Model, the BeginRead launches the data acquisition on a separate thread (not the thread that the form is executing on), control then returns to the thread on which the form is running. That is where I programmatically raise the trigger voltage high.  So it should trigger the A/D. Yes?

 

Thanks for your help.

John

0 Kudos
Message 3 of 5
(4,705 Views)

Hi John,

 

If we need to send a high pulse, why not use a digital output line instead of the analog output?  When configured correctly, it will work either way we set it up; I don't see the point in using one of the two analog outputs to trigger, but it will still work if configured properly.  I glanced at the file you attached; it's a bit large.  Let's narrow the code down to just the analog input task and the trigger setup we need (be it analog out or digital out).  This will make the code easier to understand.  

 

Regards,
John Sullivan
Applications Engineer
National Instruments

-John Sullivan
Problem Solver
0 Kudos
Message 4 of 5
(4,682 Views)

Hi John,

 

Just checking in to see if you were able to resolve this issue.  If not, go ahead and post up your simplified code and we'll take a look at it.  Have a great day!

-John Sullivan
Problem Solver
0 Kudos
Message 5 of 5
(4,647 Views)