예제 #1
0
        public void Start()
        {
            try
            {
                _loopThread?.Abort();
                SerialNumber = OrminsCcdDriverWrapper.GetSerialNum(Id);
                if (_loopThread != null)
                {
                    Thread.Sleep(100);
                }
                if (!OrminsCcdDriverWrapper.Init(ref Id))
                {
                    throw new ApplicationException(
                              $"{StringResourceProvider.Instance[StringResourceProvider.Keys.LotisSpectrometerCannotBeUsed]} ({StringResourceProvider.Instance[StringResourceProvider.Keys.OrminsCcdCantBeInitialize]})");
                }
                Id = 0;
                OrminsCcdDriverWrapper.CameraReset(Id);
                SerialNumber = OrminsCcdDriverWrapper.GetSerialNum(Id);

                if (!OrminsCcdDriverWrapper.HitTest(Id))
                {
                    throw new ApplicationException(
                              $"{StringResourceProvider.Instance[StringResourceProvider.Keys.LotisSpectrometerCannotBeUsed]} ({StringResourceProvider.Instance[StringResourceProvider.Keys.OrminsCcdHitTestFailed]})");
                }


                var @params = OrminsCcdDriverWrapper.GetParameters(Id);
                //@params = OrminsCcdDriverWrapper.GetParameters();
                if (@params.dwDigitCapacity == 0 && @params.nNumPixels == 0 && @params.nExposureTime == 0)
                {
                    throw new ApplicationException(
                              $"{StringResourceProvider.Instance[StringResourceProvider.Keys.LotisSpectrometerCannotBeUsed]} ({StringResourceProvider.Instance[StringResourceProvider.Keys.OrminsCcdHasIncorrectParams]})");
                }

                _exposTime       = @params.nExposureTime;
                _ccdLevels       = (int)Math.Pow(2, @params.dwDigitCapacity);
                _ccd_pixel_count = @params.nNumPixels;

                _intencityArray = new int[_ccd_pixel_count];
                WaveLengthArray = new double[_ccd_pixel_count];

                ReadCalibration();


                _loopThread = new Thread(DataLoop)
                {
                    IsBackground = true,
                    Priority     = ThreadPriority.Lowest
                };
                Thread.Sleep(100);

                _isSpectrometerReady = true;
                _loopThread.Start();
            }
            catch (Exception e)
            {
                LastError = e.Message + "\n" + e.InnerException?.Message + "\n" + e.StackTrace;
                _loopThread?.Abort();
                _loopThread          = null;
                _isSpectrometerReady = false;
            }
            NotifyStatusChanged(_isSpectrometerReady);
        }
예제 #2
0
        private void DataLoop()
        {
            var  errcount = 0;
            bool isNotify;

            while (true)
            {
                if (_isSpectrometerReady)
                {
                    try
                    {
                        lock (_syncObj)
                        {
                            if (OrminsCcdDriverWrapper.InitMeasuring(Id))
                            {
                                if (!OrminsCcdDriverWrapper.StartWaitMeasuring(Id))
                                {
                                    continue;
                                }
                                if (!OrminsCcdDriverWrapper.GetData(_intencityArray, Id))
                                {
                                    continue;
                                }
                                isNotify = true;
                                //Thread.Sleep(10);
                            }
                            //if (OrminsCcdDriverWrapper.InitMeasuringData(_intencityArray))
                            //{
                            //    //OrminsCcdDriverWrapper.InitMeasuring();
                            //    //OrminsCcdDriverWrapper.StartMeasuring();
                            //    OrminsCcdDriverWrapper.StartWaitMeasuring();
                            //    //OrminsCcdDriverWrapper.GetData(_intencityArray);
                            //    NotifyDataChanged(GetData());
                            //    Thread.Sleep(10);
                            //}
                            else
                            {
                                OrminsCcdDriverWrapper.CameraReset(Id);
                                OrminsCcdDriverWrapper.SetExposition(_exposTime, Id);
                                Thread.Sleep(100);
                                isNotify = false;
                            }
                        }
                        if (isNotify)
                        {
                            NotifyDataChanged(GetData());
                        }
                        //Thread.Sleep(10);
                    }
                    catch (Exception)
                    {
                        OrminsCcdDriverWrapper.CameraReset(Id);
                        OrminsCcdDriverWrapper.SetExposition(_exposTime, Id);
                        errcount++;
                        if (errcount > 5)
                        {
                            throw;
                        }
                        Thread.Sleep(100);
                    }
                }
                else
                {
                    return;
                }
            }
        }