// Created with MonoDevelop
//
//    Copyright (C) 2023 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

using Hiperscan.Common;
using Hiperscan.SGS.Benchtop.FinderSetup;
using Hiperscan.SGS.Benchtop.Transformations;
using Hiperscan.SGS.Common;
using Hiperscan.SGS.SerialInterface;
using Hiperscan.Spectroscopy;
using Hiperscan.Spectroscopy.IO;
using Hiperscan.Spectroscopy.Math;
using Hiperscan.Unix;
using Math = System.Math;


namespace Hiperscan.SGS.Benchtop
{
    public partial class Finder
    {
        public void AcquireSample(bool fluid)
        {
            this.CheckForExistingDevice();
            this.SetNewAveraging(this.SampleSet.Averaging);

            try
            {
                this.SetFinderStatus(FinderStatus.AcquireSample);
                this.SampleSet.IsFluid = fluid;
                this.Device.SetFinderPosition(FinderWheelPosition.Sample, this.idle_task_handler);
                this.SampleSet.Sample = this.Device.Single(this.auto_finder_light, this.idle_task_handler);
            }
            catch (Exception)
            {
                this.SampleSet.Sample = null;
                this.RestoreAveraging();
                throw;
            }
            finally
            {
                this.SetFinderStatus(FinderStatus.Idle);
            }
        }

        public SampleSet SampleSet { get; set; }
        public SampleSet StandardSampleSet { get; set; }
        public SampleSet InsertSampleSet { get; set; }
    }
}