Esempio n. 1
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;
            }
        }
Esempio n. 2
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            if (runningTask == null)
            {
                try
                {
                    btnStop.IsEnabled  = true;
                    btnStart.IsEnabled = false;

                    double rangeMinimum     = Convert.ToDouble(edminimum.Text);
                    double rangeMaximum     = Convert.ToDouble(edmaximum.Text);
                    double sampleRate       = Convert.ToDouble(edRate.Text);
                    int    samplePerChannel = Convert.ToInt32(edchannel.Text);

                    //// Create a new task
                    //myTask = new ni.Task();

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

                    //// Configure the timing parameters
                    //myTask.Timing.ConfigureSampleClock("", sampleRate,
                    //    SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, samplePerChannel * 10);

                    //// Configure the Every N Samples Event
                    //myTask.EveryNSamplesReadEventInterval = samplePerChannel;
                    //myTask.EveryNSamplesRead += new EveryNSamplesReadEventHandler(myTask_EveryNSamplesRead);


                    //// Verify the Task
                    //myTask.Control(TaskAction.Verify);

                    //// Prepare the table for Data
                    //InitializeDataTable(myTask.AIChannels, ref dataTable);

                    //runningTask = myTask;
                    //analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                    //runningTask.SynchronizeCallbacks = true;

                    //runningTask.Start();



                    // Create a new task
                    ni.Task myTask = new ni.Task();

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

                    // Configure the timing parameters
                    myTask.Timing.ConfigureSampleClock("", sampleRate,
                                                       ni.SampleClockActiveEdge.Rising, ni.SampleQuantityMode.FiniteSamples, samplePerChannel * 10);

                    myTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/Dev4/PFI12", ni.DigitalEdgeStartTriggerEdge.Rising);

                    myTask.Triggers.StartTrigger.Retriggerable = true;

                    // Configure the Every N Samples Event
                    myTask.EveryNSamplesReadEventInterval = samplePerChannel;

                    myTask.EveryNSamplesRead += new EveryNSamplesReadEventHandler(myTask_EveryNSamplesRead);

                    // Verify the Task
                    myTask.Control(TaskAction.Verify);

                    // Prepare the table for Data
                    InitializeDataTable(myTask.AIChannels, ref dataTable);

                    runningTask    = myTask;
                    analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                    runningTask.SynchronizeCallbacks = true;

                    runningTask.Start();
                }
                catch (DaqException exception)
                {
                    // Display Errors
                    MessageBox.Show(exception.Message);
                    runningTask        = null;
                    btnStop.IsEnabled  = false;
                    btnStart.IsEnabled = true;
                }
            }
        }