ni.com checkout is currently experiencing issues.
Support teams are actively working on the resolution.
ni.com checkout is currently experiencing issues.
Support teams are actively working on the resolution.
02-12-2009 11:31 AM
I want to make repeated calls to the reader in the AcqVoltageSamples_IntClkAnalogRef example code. A comment in the code says that I can do so by simply calling the reader.BeginReadMultiSample method from the Callback function. I tried this unsuccessfully using the same parameters for the reader. Can this be done from the callback function? If yes, how do I call the reader? I'm programming in C#.
Thanks,
John
Solved! Go to Solution.
02-13-2009 01:36 PM
John,
When you say you were unsuccessful what exactly do you mean, did you receive errors? Did it not compile? Or did the second acquisition just not happen?
Doug F
Applications Engineer
National Instruments
02-17-2009 03:07 PM
Hi Doug,
I placed the example code in a method on a Windows form and launch the method using a button click. If I supply a trigger pulse within a few seconds of clicking the button, all works well - the voltages are written to the data table. I can repeat the process ad infinitum with same good result. If, after clicking , I wait 5 or 10 seconds before supplying the trigger pulse I get the following exception.message "Measurements: Reading relative to the reference trigger or to the start of pretrigger samples position before the acquistion is complete. This sounds like a timeout problem but I have yet to discover where to set the timeout to infinite (if that is indeed what is needed).
The real world hardware that I'm supporting will send trigger pulses to the application at intervals which can vary from one every few seconds to intervals as long as several hours. Any help that you can offer with the programming will be much appreciated.
Thanks,
John
private void AcquireData()
//this code creates all the objects necessary to acquire and store the data for one 'sweep'
//It creates the objects and waits for the trigger pulse before executing. References to relevant DAQmx classes
//were declared at the form leveltry
{
//create a new Task
slaveTask = new Task();//Initialize local variables
double sampleRate = Convert.ToDouble(this.cbxSampleRate.Text);double minVolts = Convert.ToDouble(this.cbxMinVolts.Text);
double maxVolts = Convert.ToDouble(this.cbxMaxVolts.Text);int samplesPerChannel = Convert.ToInt32(this.cbxSamplesPerChannel.Text);
//Create a channel
slaveTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",(AITerminalConfiguration)(-1), minVolts, maxVolts, AIVoltageUnits.Volts);
//Configure Timing Specs
slaveTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising,SampleQuantityMode.FiniteSamples, samplesPerChannel);
//Configure reference trigger. We will trigger using a 1 volt level and will record 2 pre-trigger samples (the minimum)
slaveTask.Triggers.ReferenceTrigger.ConfigureAnalogEdgeTrigger("APFI0", AnalogEdgeReferenceTriggerSlope.Rising, 1.0, 2);//Verify the Task
slaveTask.Control(TaskAction.Verify);//Prepare the data structure for the data we will collect
//Prepare the table for Data
InitializeDataTable(slaveTask.AIChannels, ref dataTable);acquisitionDataGrid.DataSource = dataTable;
//instantiate the data reader
reader = new AnalogMultiChannelReader(slaveTask.Stream);
reader.SynchronizeCallbacks = true;reader.BeginReadMultiSample(Convert.ToInt32(cbxSamplesPerChannel.Text), new AsyncCallback(slaveCallBack), null);}
catch (DaqException exception){
MessageBox.Show(exception.Message);slaveTask.Dispose();
}
}
02-18-2009 02:55 PM
I believe the DAQmx read is timing out after the default 10 seconds when it does not see a trigger. I would increase this timeout to whatever the maximum period before the trigger fires could be.
Doug
Applications Engineer
National Instruments
02-18-2009 04:10 PM
Thanks again. Where do I set the timeout?
John
02-19-2009 12:37 PM
02-19-2009 02:01 PM
Doug,
No problem. I found which class the timeout property belonged to without too much difficulty. I now have a solution for the repeated calls. The two keys were the infinite timeout setting and Disposing of all DAQmx objects in the finally section of the CallBack function before calling the AcquireData() method for the next round of reading and processing the data. The user sets blQuit to false and invokes AcquireData() by clicking the Start button. Repeated calls are then made 'automatically' until the user clicks the Quit button.
Thanks for your help,
John
private void AcquireData()
//this code creates all the objects necessary to acquire and store the data for one 'sweep'
{
slaveTask = new Task(); double sampleRate = Convert.ToDouble(this.cbxSampleRate.Text);double minVolts = Convert.ToDouble(this.cbxMinVolts.Text);
double maxVolts = Convert.ToDouble(this.cbxMaxVolts.Text); int samplesPerChannel = Convert.ToInt32(this.cbxSamplesPerChannel.Text); slaveTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",(AITerminalConfiguration)(-1), minVolts, maxVolts, AIVoltageUnits.Volts);
//Configure Timing Specs
slaveTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChannel);//Configure reference trigger. We will trigger using a 1 volt level and will record 2 pre-trigger samples (the minimum)
slaveTask.Triggers.ReferenceTrigger.ConfigureAnalogEdgeTrigger("APFI0", AnalogEdgeReferenceTriggerSlope.Rising, 1.0, 2);slaveTask.Stream.Timeout = -1;
// slaveTask.WaitUntilDone();
//Verify the Task
slaveTask.Control(TaskAction.Verify); InitializeDataTable(slaveTask.AIChannels, ref dataTable);acquisitionDataGrid.DataSource = dataTable;
reader = new AnalogMultiChannelReader(slaveTask.Stream); reader.SynchronizeCallbacks = true;reader.BeginReadMultiSample(Convert.ToInt32(cbxSamplesPerChannel.Text), new AsyncCallback(slaveCallBack), null);
}
catch (DaqException exception){
MessageBox.Show(exception.Message);slaveTask.Dispose();
}
}
private void slaveCallBack(IAsyncResult ar){
try
{
//read the available data from the channel
data = reader.EndReadMultiSample(ar);
dataToDataTable(data, ref dataTable);//plot the data here, if blKeep also write it to file
}
catch (DaqException exception){
MessageBox.Show(exception.Message);}
finally
{
this.Refresh();slaveTask.Dispose();
if (!blQuit){
AcquireData();
}
}
}