Ejemplo n.º 1
0
        private async Task ReadOscilligramToEndRecursive(ushort currentPageIndex, Oscillogram oscillogram,
                                                         ushort endPageIndex, IProgress <ITaskProgressReport> progress, ITaskProgressReport reportProgress,
                                                         CancellationToken cancellationToken, DeviceContext deviceContext, IOscilloscopeModel oscilloscopeModel)
        {
            cancellationToken.ThrowIfCancellationRequested();


            var res = await deviceContext.DataProviderContainer.DataProvider.OnSuccessAsync(async provider =>
            {
                IQueryResult queryResult = await RetryWrapperMethod(()
                                                                    => provider.WriteSingleRegisterAsync(
                                                                        oscilloscopeModel.OscillogramLoadingParameters.AddressOfOscillogram,
                                                                        currentPageIndex, "Write"), 3);
                return(Result <IQueryResult> .Create(queryResult, true));
            });



            await this.LoadOscPage(oscillogram, (currentPageIndex + 1) == endPageIndex, oscilloscopeModel,
                                   deviceContext);

            reportProgress.CurrentProgressAmount++;
            progress.Report(reportProgress);
            currentPageIndex++;
            if (currentPageIndex >= endPageIndex)
            {
                return;
            }
            //Если вылазим за пределы размера осцилографа - начинаем читать с нулевой страницы
            if (currentPageIndex < oscilloscopeModel.OscillogramLoadingParameters.MaxSizeOfRewritableOscillogramInMs *
                oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords() / PAGE_SIZE_IN_WORD)
            {
                await this.ReadOscilligramToEndRecursive(currentPageIndex, oscillogram, endPageIndex, progress,
                                                         reportProgress, cancellationToken, deviceContext, oscilloscopeModel);
            }
            else
            {
                await this.ReadOscilligramToEndRecursive(
                    (ushort)(currentPageIndex -
                             oscilloscopeModel.OscillogramLoadingParameters.MaxSizeOfRewritableOscillogramInMs *
                             oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords() /
                             PAGE_SIZE_IN_WORD), oscillogram,
                    endPageIndex, progress, reportProgress, cancellationToken, deviceContext, oscilloscopeModel);
            }
        }
Ejemplo n.º 2
0
        public async Task LoadOscillogramsByNumber(List <int> numberOfOscillograms,
                                                   IProgress <ITaskProgressReport> progress, CancellationToken cancellationToken,
                                                   IOscilloscopeModel oscilloscopeModel, IOscilloscopeViewModel oscilloscopeViewModel, DeviceContext deviceContext)
        {
            ITaskProgressReport progressReport = _taskProgressReportGettingFunc();
            int numberOfPages = 0;

            foreach (int numberOfOscillogram in numberOfOscillograms)
            {
                if (oscilloscopeViewModel.Oscillograms.Any((oscillogram1 => oscillogram1.OscillogramNumber == numberOfOscillogram)))
                {
                    continue;
                }
                IJournalRecord oscilligramRecord = oscilloscopeModel.OscilloscopeJournal.JournalRecords[numberOfOscillogram - 1];
                oscilloscopeModel.OscillogramLoadingParameters.Initialize(oscilligramRecord.FormattedValues,
                                                                          oscilloscopeModel.OscilloscopeJournal.RecordTemplate);
                int numberOfPoints = oscilloscopeModel.OscillogramLoadingParameters.GetOscillogramCountingsNumber() *
                                     oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords();
                numberOfPages += (int)Math.Ceiling((double)numberOfPoints / PAGE_SIZE_IN_WORD);
            }

            progressReport.TotalProgressAmount = numberOfPages;
            progress.Report(progressReport);

            foreach (int numberOfOscillogram in numberOfOscillograms)
            {
                IJournalRecord oscilligramRecord = oscilloscopeModel.OscilloscopeJournal.JournalRecords[numberOfOscillogram - 1];
                oscilloscopeModel.OscillogramLoadingParameters.Initialize(oscilligramRecord.FormattedValues,
                                                                          oscilloscopeModel.OscilloscopeJournal.RecordTemplate);
                double      oscLengthInCountings = oscilloscopeModel.OscillogramLoadingParameters.GetOscillogramCountingsNumber();
                double      sizeOfCounting       = oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords();
                double      oscLengthInWords     = oscLengthInCountings * sizeOfCounting;
                double      pointOfOscStart      = oscilloscopeModel.OscillogramLoadingParameters.GetPointOfStart();
                double      pageCount            = (int)Math.Ceiling(oscLengthInWords / PAGE_SIZE_IN_WORD);
                ushort      oscStartPageIndex    = (ushort)(pointOfOscStart / PAGE_SIZE_IN_WORD);
                double      endPage     = oscStartPageIndex + pageCount;
                Oscillogram oscillogram = new Oscillogram();
                try
                {
                    await this.ReadOscilligramToEndRecursive(oscStartPageIndex, oscillogram, (ushort)endPage, progress,
                                                             progressReport, cancellationToken, deviceContext, oscilloscopeModel);
                }
                catch
                {
                    progressReport.CurrentProgressAmount = 0;
                    progressReport.TotalProgressAmount   = 1;
                    progress.Report(progressReport);
                    return;
                }

                OscillogramHelper.InvertOscillogram(oscillogram, oscilloscopeModel.OscillogramLoadingParameters, PAGE_SIZE_IN_WORD);
                oscillogram.OscillogramNumber = numberOfOscillogram - 1;
                if (oscilloscopeViewModel.Oscillograms.Any((oscillogram1 =>
                                                            oscillogram1.OscillogramNumber == oscillogram.OscillogramNumber)))
                {
                    oscilloscopeViewModel.Oscillograms.Remove(oscilloscopeViewModel.Oscillograms.First((oscillogram1 =>
                                                                                                        oscillogram1.OscillogramNumber == oscillogram.OscillogramNumber)));
                }

                oscilloscopeViewModel.Oscillograms.Add(oscillogram);


                await OscillogramHelper.SaveOscillogram(oscillogram, GetOscillogramDirectoryPath(deviceContext),
                                                        GetOscillogramSignature(oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName),
                                                        oscilloscopeModel.CountingTemplate, oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName, deviceContext);

                oscillogram.OscillogramPath = Path.Combine(GetOscillogramDirectoryPath(deviceContext),
                                                           GetOscillogramSignature(oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName));
            }
        }
Ejemplo n.º 3
0
 private void OnProgressChanged(ITaskProgressReport taskProgressReport)
 {
     this.MaxLoadingProgress     = taskProgressReport.TotalProgressAmount;
     this.CurrentLoadingProgress = taskProgressReport.CurrentProgressAmount;
 }