Esempio n. 1
0
        void myTask_EveryNSamplesRead(object sender, EveryNSamplesReadEventArgs e)
        {
            try
            {
                int samplePerChannel = Convert.ToInt32(edchannel.Text);

                // Read the available data from the channels
                data = analogInReader.ReadWaveform(samplePerChannel);

                // Plot your data here
                dataToDataTable(data, ref dataTable);
            }
            catch (DaqException exception)
            {
                // Display Errors
                MessageBox.Show(exception.Message);
                runningTask = null;
                myTask.Dispose();
                btnStop.IsEnabled  = false;
                btnStart.IsEnabled = true;
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Start.IsEnabled = false;
            ni.Task myTask = new ni.Task();
            try
            {
                // Create a new task


                // Initialize local variables
                double sampleRate        = Convert.ToDouble(edRate.Text);
                double rangeMinimum      = Convert.ToDouble(edMin.Text);
                double rangeMaximum      = Convert.ToDouble(edMax.Text);
                int    samplesPerChannel = Convert.ToInt32(edchannel.Text);

                // Create a channel
                myTask.AIChannels.CreateVoltageChannel(physicalChannelComboBox.Text, "",
                                                       (ni.AITerminalConfiguration)(-1), rangeMinimum, rangeMaximum, ni.AIVoltageUnits.Volts);

                // Configure timing specs
                myTask.Timing.ConfigureSampleClock("", sampleRate, ni.SampleClockActiveEdge.Rising,
                                                   ni.SampleQuantityMode.FiniteSamples, samplesPerChannel);

                // Verify the task
                myTask.Control(ni.TaskAction.Verify);

                // Prepare the table for data
                InitializeDataTable(myTask.AIChannels, ref dataTable);
                //acquisitionDataGrid.DataContext = dataTable.DefaultView;
                //acquisitionDataGrid.ItemsSource = dataTable.DefaultView;

                // Read the data
                reader = new ni.AnalogMultiChannelReader(myTask.Stream);

                data = reader.ReadWaveform(samplesPerChannel);

                dataToDataTable(data, ref dataTable);

                myTask.Dispose();
            }
            catch (ni.DaqException exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                myTask.Dispose();
                Start.IsEnabled = true;
            }
        }