void on_cmd_startNoiseDefR(object sender, RoutedEventArgs e)
        {
            if (experiment != null)
            {
                experiment.Dispose();
            }

            var calPath = string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "NoiseCalibration");
            var amplifierNoiseFilePath    = string.Format("{0}\\{1}", calPath, "AmplifierNoise.dat");
            var frequencyResponseFilePath = string.Format("{0}\\{1}", calPath, "FrequencyResponse.dat");

            var amplifierNoise    = ReadCalibrationFile(amplifierNoiseFilePath);
            var frequencyResponse = ReadCalibrationFile(frequencyResponseFilePath);


            var motorDriver           = new SerialDevice("COM5", 115200, Parity.None, 8, StopBits.One);
            IMotionController1D motor = new SA_2036U012V(motorDriver) as IMotionController1D;

            experiment = new Noise_DefinedResistance(((measurementInterface as Noise_at_DefinedResistance).DataContext as Noise_DefinedResistanceModel).ExperimentSettings.AgilentU2542AResName, motor, amplifierNoise, frequencyResponse);

            experiment.DataArrived += Noise_at_der_R_DataArrived;

            experiment.Status   += experimentStatus;
            experiment.Progress += experimentProgress;

            if (measurementInterface != null)
            {
                if (measurementInterface is Noise_at_DefinedResistance)
                {
                    experiment.Start(((measurementInterface as Noise_at_DefinedResistance).DataContext as Noise_DefinedResistanceModel).ExperimentSettings);
                }
            }
        }
        void cmdStartNoise_Click(object sender, RoutedEventArgs e)
        {
            var control  = measurementInterface as FET_Noise;
            var settings = (control.DataContext as FET_NoiseModel).ExperimentSettings;

            //control.chartFETOscilloscope.Children.RemoveAll(typeof(LineGraph));
            //control.chartFETOscilloscope.Legend.Visibility = System.Windows.Visibility.Collapsed;

            //control.graphFETNoise.Children.RemoveAll(typeof(NationalInstruments.Controls.Plot));
            //var psdPlot = new NationalInstruments.Controls.Plot();
            //control.graphFETNoise.Plots.Add(psdPlot);

            //(measurementInterface as FET_Noise).chartFETNoise.Children.RemoveAll(typeof(LineGraph));
            //(measurementInterface as FET_Noise).chartFETNoise.Legend.Visibility = System.Windows.Visibility.Collapsed;

            //var psdGraph = new LineGraph(FETNoiseDataSource);
            //psdGraph.AddToPlotter(control.chartFETNoise);
            //control.chartFETNoise.Viewport.FitToView();

            if (experiment != null)
            {
                experiment.Dispose();
            }

            var calPath = string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "NoiseCalibration");
            var amplifierNoiseFilePath    = string.Format("{0}\\{1}", calPath, "AmplifierNoise.dat");
            var frequencyResponseFilePath = string.Format("{0}\\{1}", calPath, "FrequencyResponse.dat");

            var amplifierNoise    = ReadCalibrationFile(amplifierNoiseFilePath);
            var frequencyResponse = ReadCalibrationFile(frequencyResponseFilePath);

            experiment = new FET_Noise_Experiment(settings.AgilentU2542AResName, amplifierNoise, frequencyResponse);

            experiment.ExpStarted  += onExperimentStarted;
            experiment.DataArrived += expFET_Noise_DataArrived;
            experiment.Status      += experimentStatus;
            experiment.Progress    += experimentProgress;

            if (expStartInfo != null)
            {
                if (measurementInterface is FET_Noise)
                {
                    experiment.Start(((measurementInterface as FET_Noise).DataContext as FET_NoiseModel).ExperimentSettings);
                }
            }
        }
Пример #3
0
        void run()
        {
            ToConsole("Initialising hardware.");
            exp.Initialise(parameters);

            ToConsole("Acquiring data...");
            int numberOfScans = 0;

            while (es.Equals(ExperimentState.IsRunning) || es.Equals(ExperimentState.IsPaused))
            {
                //Tell UI to clear in preparation for new data.
                Clients.All.clearPlot();

                currentDataSet = new DataSet();
                int i = 0, iterationsSinceLastDataUpdate = 0;
                while (i < parameters.ScanParams.NumberOfPoints)
                {
                    //This is to break out mid-scan
                    if (es.Equals(ExperimentState.IsRunning))
                    {
                        //Need to call this whether acquiring or not... (otherwise DDS command doesn't get sent)
                        currentDataSet.Add(exp.SetupAndAcquire(parameters.ScanParams.ScanParameterValues[i]));
                        i++;
                        iterationsSinceLastDataUpdate++;

                        //Only send to plot if acquisition happened.
                        if (parameters.ScanParams.AcquireDataDuringScan)
                        {
                            //Cheezy solution for real time plotting. Update roughly every 0.5 seconds. If I update too often, it crashes on UI side.
                            if (iterationsSinceLastDataUpdate * parameters.ScanParams.Sleep > 500)
                            {
                                //Push data down to the client like this.
                                Clients.All.pushLatestData(currentDataSet.GetSubset(i - iterationsSinceLastDataUpdate, i).ToJson());
                                iterationsSinceLastDataUpdate = 0;
                            }
                        }
                    }
                    else if (es.Equals(ExperimentState.IsPaused))
                    {
                        //Only send to plot if acquisition happened.
                        if (parameters.ScanParams.AcquireDataDuringScan)
                        {
                            //Plots any residual data points during pause, if there is anything to plot
                            if (iterationsSinceLastDataUpdate != 0)
                            {
                                Clients.All.pushLatestData(currentDataSet.GetSubset(i - iterationsSinceLastDataUpdate, i).ToJson());
                                iterationsSinceLastDataUpdate = 0;
                            }
                        }
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        break; //Somebody pressed the stop button during a scan.
                    }
                }
                if (parameters.ScanParams.AcquireDataDuringScan)
                {
                    dataArchive.Add(currentDataSet);
                    numberOfScans++;

                    //Push data down to the client like this.
                    Clients.All.pushLatestData(currentDataSet.GetSubset(i - iterationsSinceLastDataUpdate, i).ToJson());
                }
                if (parameters.ScanParams.StopOnEOS)
                {
                    es = ExperimentState.IsFinishing;
                }
            }
            ToConsole("Acquisition/Move complete.");
            ToConsole("Disposing hardware classes...");
            exp.Dispose();
            ToConsole("Disposed.");
            ToConsole("Setting ExperimentState to stopped and closing thread...");
            es = ExperimentState.IsStopped;
        }
Пример #4
0
 private void OnAppClosing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     a.Dispose();
 }