10-02-2007 10:06 AM
private void startButton_Click(object sender, System.EventArgs e)
{
try
{
//Create a new task
myTask = new Task();
//Create a virtual channel
myTask.AIChannels.CreateVoltageChannel(physicalChannelComboBox.Text, "",
(AITerminalConfiguration)(-1), Convert.ToDouble(minimumValueNumeric.Value),
Convert.ToDouble(maximumValueNumeric.Value), AIVoltageUnits.Volts);
//Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value),
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);
//Verify the Task
myTask.Control(TaskAction.Verify);
//Prepare the table for Data
InitializeDataTable(myTask.AIChannels,ref dataTable);
acquisitionDataGrid.DataSource=dataTable;
// Create the event
myTask.SampleComplete += new SampleCompleteEventHandler(myTask_SampleComplete);
// Start the acquisition
myTask.Start();
}
catch (DaqException exception)
{
//Display Errors
MessageBox.Show(exception.Message);
myTask.Dispose();
}
}
void myTask_SampleComplete(object sender, SampleCompleteEventArgs e)
{
// Read Data
}
Solved! Go to Solution.
10-03-2007 04:10 PM
Hi rnigro,
There may be something incorrect with the way the SampleComplete
event is being used. From what I understand
from the code, you want an Analog Input task to read continuously. There are several shipping examples that come
with Measurement Studio that you may want to try. They are located in the Measurement Studio
folder under DotNET»Examples»DAQmx»Analog In»Measure Voltage. I didn't see anything in your code that you would not be able to do with the shipping example. Is there something that you plan to include where you would need to use the SampleCompleteEventHandler?
10-09-2007 04:03 PM
10-10-2007 04:52 PM
It appears that SamplesComplete occurs when each sample is acquired into the NI-DAQmx driver buffer and is ready for reading. If your sampling rate is too high, you’re going to run into problems.
You probably want to use “Every N Samples”, but it isn’t supported in Measurement Studio NI-DAQmx .NET library. Instead, you would use asynchronous reading, which is what you refer to as a “band-aid”. All of this can be found starting in the “Using NI-DAQmx Events” in the Microsoft Visual Studio 2005 Documentation.
I found other related information in the paragraph “Asynchronous I/O versus Events”, as well as by following the last link.
10-11-2007 08:13 AM
10-12-2007 04:29 PM
To make sure that your hardware is working and you get valid data, I recommend running a test panel in Measurement & Automation Explorer. This will verify that you have a valid sample clock and AI channel. If that works, then run the example I’ve written that shows that the event is firing. (You might want to turn down the rate because the box could get annoying.)
Hope this helps.
10-15-2007 07:23 AM
10-16-2007 08:55 AM
Ah yes!
Simulated devices are very similar to real hardware, but do have some considerations when it comes to timing and synchronization. There’s a Developer Zone article entitled “NI-DAQmx Simulated Devices” that describes these considerations in section 4. One of the points is that “An NI-DAQmx simulated device never issues a software event or causes a timed loop to execute.”
I hope that clarifies the behavior you are experiencing. With your actual hardware, everything should work fine with firing the event.
10-16-2007 08:58 AM
09-18-2009 07:12 AM