Exemplo n.º 1
0
        public PhosResultsViewModel(CamPhosResults camResults, SpectrometerPhosResults spectroResults)
        {
            base.DisplayName        = "PhosResultsViewModel";
            ShowListItemControl     = false;
            _phosImages             = camResults.Images;
            _phosFilteredImages     = camResults.FilteredImages;
            _phosSpectra            = spectroResults.Spectra;
            CurrentPhosItem         = 1;
            CurrentSpectraItem      = 1;
            SaveFolderPath          = Properties.Settings.Default.SaveFolderPath;
            _startTimeStamp         = camResults.StartTimeStamp;
            _spectrumStartTimeStamp = spectroResults.StartTimeStamp;

            CommandSetFolder           = new RelayCommand(param => SetFolder(), cc => _busy == false);
            CommandPreviousPhosItem    = new RelayCommand(param => PreviousPhosItem(), cc => _busy == false);
            CommandNextPhosItem        = new RelayCommand(param => NextPhosItem(), cc => _busy == false);
            CommandPreviousSpectraItem = new RelayCommand(param => PreviousSpectraItem(), cc => _busy == false);
            CommandNextSpectraItem     = new RelayCommand(param => NextSpectraItem(), cc => _busy == false);
            CommandSave    = new RelayCommand(param => Save(), cc => _busy == false);
            CommandSaveAll = new RelayCommand(param => Save(true), cc => _busy == false);

            CommandCalibrate = new RelayCommand(param => Calibrate());

            SpectrumData       = new ObservableDataSource <Point>();
            SmoothSpectrumData = new ObservableDataSource <Point>();
        }
Exemplo n.º 2
0
 void MeasurementCompleteCallback(object sender, object result)
 {
     if (Object.ReferenceEquals(sender.GetType(), _spectrometerVM.GetType()))
     {
         _spectrometerPhosResults = (SpectrometerPhosResults)result;
         _whMeasureControl.Set();
     }
 }
Exemplo n.º 3
0
        public PhosResultsViewModel(CamPhosResults camResults, SpectrometerPhosResults spectroResults, List <List <PeakDetectInfo> > peakInfoList, ANALYZER_RESULT diamondResult, List <Tuple <System.Windows.Shapes.Ellipse, TextBlock, Point> > markerList, CamPhosResults camResultsPre)
        {
            base.DisplayName        = "PhosResultsViewModel";
            ShowListItemControl     = false;
            _phosImages             = camResults.Images;
            _phosFilteredImages     = camResults.FilteredImages;
            _phosSpectra            = spectroResults.Spectra;
            NumSpectraItems         = _phosSpectra.Count.ToString();
            CurrentListItem         = 0;
            CurrentPhosItem         = 1;
            CurrentSpectraItem      = 1;
            SaveFolderPath          = Properties.Settings.Default.SaveFolderPath;
            _startTimeStamp         = camResults.StartTimeStamp;
            _spectrumStartTimeStamp = spectroResults.StartTimeStamp;
            PeakInfoList            = peakInfoList;
            DiamondResult           = diamondResult;
            SpectrumIntegrationTime = _phosSpectra[0].IntegrationTime.ToString();
            MarkerList    = markerList;
            CamResultsPre = camResultsPre.Images;

            Width  = CamResultsPre[0].Image.Width;
            Height = CamResultsPre[0].Image.Height;

            CommandSetFolder           = new RelayCommand(param => SetFolder(), cc => _busy == false);
            CommandPreviousPhosItem    = new RelayCommand(param => PreviousPhosItem(), cc => _busy == false);
            CommandNextPhosItem        = new RelayCommand(param => NextPhosItem(), cc => _busy == false);
            CommandPreviousSpectraItem = new RelayCommand(param => PreviousSpectraItem(), cc => _busy == false);
            CommandNextSpectraItem     = new RelayCommand(param => NextSpectraItem(), cc => _busy == false);
            CommandSave    = new RelayCommand(param => Save(), cc => _busy == false);
            CommandSaveAll = new RelayCommand(param => Save(true), cc => _busy == false);

            CommandCalibrate = new RelayCommand(param => Calibrate());

            SpectrumData       = new ObservableDataSource <Point>();
            SmoothSpectrumData = new ObservableDataSource <Point>();

            InitializeColorLegend();
        }
Exemplo n.º 4
0
 void ResetSpectroResults()
 {
     _spectroResults = new SpectrometerPhosResults();
 }
Exemplo n.º 5
0
        void BwMeasure(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker bw = sender as BackgroundWorker;
                int progress        = 0;
                int step            = 25;
                bw.ReportProgress(step / 2);
                _statusVM.IsBusy = true;

                _measurementType = MeasurementType.MEASURE;
                // 0. capture image before measurement
                _cameraVM.StartEnqueue();
                if (!_whMeasureControl.WaitOne(2000))
                {
                    // todo: error in capture image
                    e.Result = new Result(ResultStatus.ERROR, "Failed to enqueue image");
                    return;
                }
                // camera reset to continue mode for display
                _cameraVM.StopEnqueue();
                ulong timeStamp = (ulong)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
                _camResultsPre = new CamPhosResults(timeStamp, _cameraVM.GetImageQueue().ToList());
                Thread.Sleep(200);

                // 1. turn on laser
                if (!_xyzAxesVM.SetLaserOnOff(true))
                {
                    e.Result = new Result(ResultStatus.ERROR, "Failed to turn on the laser");
                    return;
                }
                bw.ReportProgress(progress += step);
                Thread.Sleep(1000);

                // 1.5 capture image
                _cameraVM.StartEnqueue();
                if (!_whMeasureControl.WaitOne(2000))
                {
                    // todo: error in capture image
                    e.Result = new Result(ResultStatus.ERROR, "Failed to enqueue image");
                    return;
                }
                // camera reset to continue mode for display
                _cameraVM.StopEnqueue();
                timeStamp       = (ulong)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
                _camPhosResults = new CamPhosResults(timeStamp, _cameraVM.GetImageQueue().ToList());
                Thread.Sleep(200);

                bw.ReportProgress(progress += step);
                // 2. spectrometer measure
                Stopwatch watch  = Stopwatch.StartNew();
                int       factor = 0;
                int       index  = 2;
                _peakInfoList.Clear();
                ResetSpectroResults();
                while (index >= 0 && index <= 4)
                {
                    Console.WriteLine("spectrum parameter index: {0}", index);
                    double integrationTime = SpectrumParameters[index].Item1;
                    uint   numAverages     = SpectrumParameters[index].Item2;

                    Callback MeasurementEnd = MeasurementCompleteCallback;
                    if (!_spectrometerVM.StartPhosphorescenceMeasurement(GlobalVariables.spectrometerSettings.Delay, GlobalVariables.spectrometerSettings.Counts, integrationTime, numAverages, MeasurementEnd, out string error))
                    {
                        e.Result = new Result(ResultStatus.ERROR, "Failed in start phosphorescence measurement");
                        return;
                    }
                    if (!_whMeasureControl.WaitOne(15000))
                    {
                        // todo: error in getting spectrometer data
                        e.Result = new Result(ResultStatus.ERROR, "Failed in phosphorescence measurement");
                        return;
                    }

                    // save spectrum data to _spectroResults
                    for (int i = 0; i < _spectrometerPhosResults.Spectra.Count; i++)
                    {
                        _spectroResults.Spectra.Add(_spectrometerPhosResults.Spectra[i]);
                    }

                    // analyze spectrum data
                    List <double>         wl       = _spectrometerPhosResults.Spectra[0].Spectrum.Select(p => p.X).ToList();
                    List <double>         counts   = _spectrometerPhosResults.Spectra[0].Spectrum.Select(p => p.Y).ToList();
                    List <PeakDetectInfo> peakInfo = new List <PeakDetectInfo>();
                    _diamondResult = RamanAnalyzer.Analysis(wl, counts, out peakInfo);

                    if (_diamondResult == ANALYZER_RESULT.ERROR || _diamondResult == ANALYZER_RESULT.ERROR_SPIKE)
                    {
                        break;
                    }

                    if (_diamondResult == ANALYZER_RESULT.NONE)
                    {
                        _peakInfoList.Add(peakInfo);
                        if (factor == 0 || factor == 1)
                        {
                            index++;
                            factor = 1;
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else if (_diamondResult == ANALYZER_RESULT.SATURATED)
                    {
                        _peakInfoList.Add(peakInfo);
                        if (factor == 0 || factor == -1)
                        {
                            index--;
                            factor = -1;
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else if (_diamondResult == ANALYZER_RESULT.NON_DIAMOND)
                    {
                        if (index >= 2)
                        {
                            _peakInfoList.Clear();
                        }
                        _peakInfoList.Add(peakInfo);
                        break;
                    }
                    else
                    {
                        _peakInfoList.Clear();
                        break;
                    }
                }

                if (_peakInfoList.Count >= 2)
                {
                    _diamondResult = SpectrumAnalyzer.TestAggregate(_peakInfoList);
                }
                _spectrometerPhosResults = _spectroResults;

                watch.Stop();
                long ms = watch.ElapsedMilliseconds;
                Console.WriteLine("spectrum measurement spend: {0}", ms);
                Thread.Sleep(200);

                bw.ReportProgress(progress += step);
                // 3. turn off laser
                if (!_xyzAxesVM.SetLaserOnOff(false))
                {
                    e.Result = new Result(ResultStatus.ERROR, "Failed to turn off the laser");
                    return;
                }

                bw.ReportProgress(progress += step);
                e.Result = new Result(ResultStatus.SUCCESS, null);
            } catch (Exception ex)
            {
                Console.WriteLine("measurementvm exception: " + ex.Message);
                e.Result = new Result(ResultStatus.ERROR, ex.Message);
            }
        }