private async Task <bool> Darvslew(IProgress <ApplicationStatus> cameraprogress, IProgress <string> slewprogress) { if (CameraInfo?.Connected == true) { cancelDARVSlewToken?.Dispose(); cancelDARVSlewToken = new CancellationTokenSource(); try { var seq = new CaptureSequence(DARVSlewDuration + 5, CaptureSequence.ImageTypes.SNAPSHOT, SnapFilter, SnapBin, 1); var prepareParameters = new PrepareImageParameters(autoStretch: true, detectStars: false); var capture = imagingMediator.CaptureAndPrepareImage(seq, prepareParameters, cancelDARVSlewToken.Token, cameraprogress); var slew = DarvTelescopeSlew(slewprogress, cancelDARVSlewToken.Token); await Task.WhenAll(capture, slew); } catch (OperationCanceledException) { } } else { Notification.ShowError(Locale.Loc.Instance["LblNoCameraConnected"]); } cameraprogress.Report(new ApplicationStatus() { Status = string.Empty }); return(true); }
private async Task <AllImageStatistics> TakeExposure(double exposureDuration) { _cts?.Dispose(); _cts = new CancellationTokenSource(); var seq = new CaptureSequence(exposureDuration, CaptureSequence.ImageTypes.SNAPSHOT, SnapFilter, new Model.MyCamera.BinningMode(1, 1), 1); seq.Gain = SnapGain; var prepareParameters = new PrepareImageParameters(autoStretch: true, detectStars: false); var capture = await _imagingMediator.CaptureAndPrepareImage(seq, prepareParameters, _cts.Token, null); //todo progress return(await AllImageStatistics.Create(capture.RawImageData)); }
public async Task <IRenderedImage> CaptureAndPrepareImage( CaptureSequence sequence, PrepareImageParameters parameters, CancellationToken token, IProgress <ApplicationStatus> progress) { var iarr = await CaptureImage(sequence, parameters, token, string.Empty); if (iarr != null) { return(await _imageProcessingTask); } else { return(null); } }
private Task <IExposureData> CaptureImage( CaptureSequence sequence, PrepareImageParameters parameters, CancellationToken token, string targetName = "", bool skipProcessing = false ) { return(Task.Run(async() => { try { IExposureData data = null; //Asynchronously wait to enter the Semaphore. If no-one has been granted access to the Semaphore, code execution will proceed, otherwise this thread waits here until the semaphore is released progress.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblWaitingForCamera"] }); await semaphoreSlim.WaitAsync(token); try { if (CameraInfo.Connected != true) { Notification.ShowWarning(Locale.Loc.Instance["LblNoCameraConnected"]); throw new CameraConnectionLostException(); } /*Change Filter*/ await ChangeFilter(sequence, token, progress); /* Start RMS Recording */ var rmsHandle = this.guiderMediator.StartRMSRecording(); /*Capture*/ var exposureStart = DateTime.Now; await cameraMediator.Capture(sequence, token, progress); /* Stop RMS Recording */ var rms = this.guiderMediator.StopRMSRecording(rmsHandle); /*Download Image */ data = await Download(token, progress); token.ThrowIfCancellationRequested(); if (data == null) { Logger.Error(new CameraDownloadFailedException(sequence)); Notification.ShowError(string.Format(Locale.Loc.Instance["LblCameraDownloadFailed"], sequence.ExposureTime, sequence.ImageType, sequence.Gain, sequence.FilterType?.Name ?? string.Empty)); return null; } AddMetaData(data.MetaData, sequence, exposureStart, rms, targetName); if (!skipProcessing) { //Wait for previous prepare image task to complete if (_imageProcessingTask != null && !_imageProcessingTask.IsCompleted) { progress.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblWaitForImageProcessing"] }); await _imageProcessingTask; } _imageProcessingTask = PrepareImage(data, parameters, token); } } catch (System.OperationCanceledException ex) { cameraMediator.AbortExposure(); throw ex; } catch (CameraConnectionLostException ex) { Logger.Error(ex); Notification.ShowError(Locale.Loc.Instance["LblCameraConnectionLost"]); throw ex; } catch (Exception ex) { Notification.ShowError(Locale.Loc.Instance["LblUnexpectedError"] + Environment.NewLine + ex.Message); Logger.Error(ex); cameraMediator.AbortExposure(); throw ex; } finally { progress.Report(new ApplicationStatus() { Status = "" }); semaphoreSlim.Release(); } return data; } finally { progress.Report(new ApplicationStatus() { Status = string.Empty }); } })); }