Пример #1
0
        public bool StartN3Fluorescence(List <double> shutterTimesMs, double gain,
                                        Callback whenMeasurementEnds, out string error)
        {
            bool result = false;

            error = "";

            try
            {
                if (!_cameraConnected)
                {
                    throw new Exception("Camera not connected");
                }

                Ready = false;

                //stop streaming camera
                _ptGreyCamera.StopVideo();

                if (!_ptGreyCamera.SetBinning(true))
                {
                    throw new Exception("Could not enable binning");
                }

                if (!_ptGreyCamera.SetGain(gain))
                {
                    throw new Exception("Could not change gain");
                }

                //increase frame buffer count
                if (!_ptGreyCamera.SetStreamBufferCount(50))
                {
                    throw new Exception("Could not set frame buffer count");
                }

                //sequencer off
                if (!_ptGreyCamera.SetSequencerMode(false))
                {
                    throw new Exception("Could not disable sequencer");
                }
                //sequencer config on
                if (!_ptGreyCamera.SetSequencerConfigurationMode(true))
                {
                    throw new Exception("Could not enable sequencer config");
                }
                //set sequencer
                for (int sequenceNumber = 0; sequenceNumber < shutterTimesMs.Count; sequenceNumber++)
                {
                    if (!_ptGreyCamera.SetSingleSequence(sequenceNumber, shutterTimesMs.Count - 1,
                                                         shutterTimesMs[sequenceNumber] * 1000))
                    {
                        throw new Exception("Could not set sequence");
                    }
                }

                //sequencer config off
                if (!_ptGreyCamera.SetSequencerConfigurationMode(false))
                {
                    throw new Exception("Could not disable sequencer config");
                }
                //sequencer on
                if (!_ptGreyCamera.SetSequencerMode(true))
                {
                    throw new Exception("Could not enable sequencer");
                }

                //do this before we change trigger mode
                _phosStartTimestamp = _ptGreyCamera.GetImageTimeStamp();

                //empty phos image buffer
                _phosImages.Clear();

                //set phos count
                _phosImagesToCollect = (uint)shutterTimesMs.Count;

                //start backgroundworker to wait for completion
                BWArgument arg;
                arg.measurementEnd = whenMeasurementEnds;
                arg.waitTime       = (int)(5000 + (shutterTimesMs.Sum()));


                _phosMeasureCompletionEvent.Reset();
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork             += WaitForN3FluorescenceCompletion;
                bw.RunWorkerCompleted += N3FluorescenceComplete;
                bw.RunWorkerAsync(arg);

                //start video
                _ptGreyCamera.StartVideo();

                result = true;
            }
            catch (Exception ex)
            {
                error = ex.Message;
                Ready = true;
                _ptGreyCamera.StopVideo();
                _ptGreyCamera.SetSequencerConfigurationMode(false);
                _ptGreyCamera.SetSequencerMode(false);
                _ptGreyCamera.SetBinning(false);
                _phosImagesToCollect = 0;
                _phosMeasureCompletionEvent.Set();
                SetShutterTime(Properties.Settings.Default.ShutterDefault);
                SetGain(Properties.Settings.Default.GainDefault);
                _ptGreyCamera.StartVideo();
            }

            return(result);
        }