예제 #1
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            try
            {
                // create the task and channel
                myTask.AOChannels.CreateVoltageChannel(physicalChannelComboBox.Text,
                                                       "",
                                                       Convert.ToDouble(minimumTextBox.Text),
                                                       Convert.ToDouble(maximumTextBox.Text),
                                                       ni.AOVoltageUnits.Volts);

                // verify the task before doing the waveform calculations
                myTask.Control(ni.TaskAction.Verify);

                // calculate some waveform parameters and generate data
                FunctionGenerator fGen = new FunctionGenerator(
                    myTask.Timing,
                    edfrequency.Text,
                    edsamplesPerBuffer.Text,
                    edcyclesPerBuffer.Text,
                    signalTypeComboBox.Text,
                    edamplitude.Text);

                // configure the sample clock with the calculated rate
                myTask.Timing.ConfigureSampleClock("",
                                                   fGen.ResultingSampleClockRate,
                                                   ni.SampleClockActiveEdge.Rising,
                                                   ni.SampleQuantityMode.ContinuousSamples, 1000);


                ni.AnalogSingleChannelWriter writer =
                    new ni.AnalogSingleChannelWriter(myTask.Stream);

                //write data to buffer
                writer.WriteMultiSample(false, fGen.Data);

                profilechart.SetData(fGen.Data);

                //start writing out data
                myTask.Start();

                btnStart.IsEnabled = false;
                btnStop.IsEnabled  = true;


                timer.IsEnabled = true;
            }
            catch (ni.DaqException err)
            {
                timer.IsEnabled = false;
                MessageBox.Show(err.Message);
                myTask.Dispose();
            }
            Mouse.OverrideCursor = Cursors.Arrow;
        }
예제 #2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         using (ni.Task myTask = new ni.Task())
         {
             myTask.AOChannels.CreateVoltageChannel(physicalChannelComboBox.Text, "aoChannel",
                                                    Convert.ToDouble(minimumValue.Text), Convert.ToDouble(maximumValue.Text),
                                                    ni.AOVoltageUnits.Volts);
             ni.AnalogSingleChannelWriter writer = new ni.AnalogSingleChannelWriter(myTask.Stream);
             writer.WriteSingleSample(true, Convert.ToDouble(voltageOutput.Text));
         }
     }
     catch (ni.DaqException ex)
     {
         MessageBox.Show(ex.Message);
     }
     Mouse.OverrideCursor = Cursors.Arrow;
 }