Beispiel #1
0
        private async Task ShotSolveSync(CancellationToken token)
        {
            await Task.Run(() =>
            {
                try
                {
                    ClearResult();
                    isProcessing = true;
                    ReadSettingsFromUi();
                    string fileName = Path.Combine(
                        System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                        "temp.jpg");
                    _camera.StartExposure(_settings.Exposure, true);
                    Update("Exposure...");
                    while (!_camera.ImageReady || _camera.CameraState != ASCOM.DeviceInterface.CameraStates.cameraIdle)
                    {
                        _util.WaitForMilliseconds(300);
                        token.ThrowIfCancellationRequested();
                    }
                    Update("Reading image...");

                    var array = (Array)_camera.ImageArray;
                    var bmp   = ImageHelper.GetBitmap(array, _camera.MaxADU);
                    ImageHelper.SaveBmp(bmp, fileName);
                    Update("Solving...");
                    SolveAndSync(fileName, token);
                }
                catch (OperationCanceledException)
                {
                    Update("Aborted");
                    if (_camera.CameraState == ASCOM.DeviceInterface.CameraStates.cameraExposing)
                    {
                        _camera.AbortExposure();
                    }
                    isProcessing = false;
                }
                catch (Exception ex)
                {
                    isProcessing = false;
                    Update();
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }, token);
        }