05-21-2009 03:19 PM
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
05-22-2009 04:51 PM
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
05-26-2009 10:22 AM
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
05-28-2009 12:08 AM
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
06-01-2009 05:15 PM
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!