public ERROR_CODES AddNewExperiment(ExperimentInitialSettings experimentSettings, out IExperimentData newExperiment, string fileName)
        {
            ERROR_CODES status = ERROR_CODES.AA_OK;
            DialogResult dlgRes = DialogResult.OK;
            newExperiment = null;

            if (string.IsNullOrEmpty(fileName))
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "Text File|*.txt";
                dlg.Title = "Select signal generator input file.";
                dlg.Multiselect = false;
                dlgRes = dlg.ShowDialog();
                if (dlgRes == DialogResult.OK)
                {
                    fileName = dlg.FileName;
                }
            }

            //DialogResult dlgRes = DialogResult.OK;
            if (dlgRes == DialogResult.OK)
            {
                string[] sgInput = System.IO.File.ReadAllLines(fileName);
                double[] signalGeneratorInput = sgInput.Select(x => double.Parse(x)).ToArray();
                status = AddNewExperiment(experimentSettings, out newExperiment, signalGeneratorInput);
            }
            return status;
        }
 public ExperimentData(double[] signalGeneratorInput, ExperimentInitialSettings initialSettings)
 {
     InitialSettings = initialSettings;
     scopeData = new ScopeData();
     SignalGeneratorData = new SignalGeneratorData(signalGeneratorInput);
     SignalGeneratorInputFileName = "";
     PointsInCycle = signalGeneratorInput.Length;
     InitializeExperimentData();
 }
 public ExperimentData(IEnumerable<double> signalGeneratorArbitraryOutput, ExperimentInitialSettings initialSettings)
 {
     scopeData = new ScopeData();
     ScopeData.SampleMode = ScopeSampleMode.Average;
     SignalGeneratorData = new SignalGeneratorData(signalGeneratorArbitraryOutput);
     SignalGeneratorInputFileName = "From array.";
     InitialSettings = initialSettings;
     PointsInCycle = signalGeneratorArbitraryOutput.Count();
     InitializeExperimentData();
 }
        public ERROR_CODES AddNewExperiment(ExperimentInitialSettings experimentSettings, out IExperimentData newExperiment, double[] signalGeneratorInput)
        {
            ERROR_CODES status = ERROR_CODES.AA_OK;
            status = applicationController.AddNewExperiment(signalGeneratorInput, experimentSettings, out newExperiment);
            //status = applicationController.AddNewExperiment(@"C:\Users\User\Documents\Dror\AOM measurements\PID control\ptMove200.txt", experimentSettings, out newExperiment);

            if (status == ERROR_CODES.AA_OK)
            {
                managedForm.AddNewExperimentData(newExperiment);
            }
            return status;
        }
        public ERROR_CODES AddNewExperiment(double[] signalGeneratorOutputData, ExperimentInitialSettings initialSettings, out IExperimentData newExperiment)
        {
            ERROR_CODES status = ERROR_CODES.AA_OK;
            newExperiment = null;
            try
            {
                newExperiment = new ExperimentData(signalGeneratorOutputData, initialSettings);
                try
                {
                    if (initialSettings.UseRunningInsturmentSettings)
                    {
                        try
                        {
                            UpdateSignalGeneratorDataFromInstrument(newExperiment.SignalGeneratorData);
                        }
                        catch (Exception ex)
                        {
                            string s = ex.Message;
                        }
                    }
                    else
                    {
                        newExperiment.SignalGeneratorData.HighVoltage = initialSettings.SignalGeneratorHighVoltage;
                        newExperiment.SignalGeneratorData.LowVoltage = initialSettings.SignalGeneratorLowVoltage;
                        newExperiment.SignalGeneratorData.OutputFrequency = initialSettings.SignalGeneratorFrequencyOutput;
                    }
                    //set scope buffer size by points in cycle, so buffer size is a multiple of cycle point count.
                    int maxPointInBuffer = Scope.MaxBufferSize;
                    int bufferSizeToUse = (maxPointInBuffer / newExperiment.PointsInCycle);
                    bufferSizeToUse *= newExperiment.PointsInCycle;
                    newExperiment.ScopeData.PointsToSave = bufferSizeToUse * newExperiment.InitialSettings.BuffersToRead;

                    Scope.BufferSize = bufferSizeToUse;
                    Scope.PointsInCycle = newExperiment.PointsInCycle;
                    Scope.SampleRate = newExperiment.InitialSettings.SampleRate;
                    newExperiment.ScopeData.SampleRate = Scope.SampleRateInHz;
                    RunExperiment(newExperiment);
                    experiments.Add(newExperiment.ID, newExperiment);

                }
                catch { status = ERROR_CODES.INSTRUMENT_READ_WRITE_FAIL; }
            }
            catch { status = ERROR_CODES.INVALID_SIGNAL_GENERATOR_INPUT_FILE; }
            return status;
        }