Esempio n. 1
0
        public OscilloscopeEditorViewModel(ICountingTemplate countingTemplate, IOscilloscopeModel oscilloscopeModel,
                                           IUniconJournalEditorViewModel uniconJournalEditorViewModel, IFragmentEditorViewModelFactory fragmentEditorViewModelFactory,
                                           IOscillogramLoadingParametersEditorViewModel oscillogramLoadingParametersEditorViewModel, IRecordTemplateEditorViewModel recordTemplateEditorViewModel)
        {
            this._oscilloscopeModel = oscilloscopeModel;
            this._countingTemplate  = countingTemplate;
            this._fragmentEditorViewModelFactory    = fragmentEditorViewModelFactory;
            this.OscilloscopeJournalEditorViewModel = uniconJournalEditorViewModel;

            this.OscillogramLoadingParametersEditorViewModel = oscillogramLoadingParametersEditorViewModel;
            this.CountingTemplateEditorViewModel             = recordTemplateEditorViewModel;
        }
Esempio n. 2
0
        public static async Task SaveOscillogram(Oscillogram oscillogram, string directoryPath,
                                                 string oscillogramSignature, ICountingTemplate countingTemplate, IOscillogramLoadingParameters oscillogramLoadingParameters, string parentDeviceName, DeviceContext deviceContext)
        {
            var journalRecordFactory = StaticContainer.Container.Resolve <IJournalRecordFactory>();

            List <int[]> countingArraysToFile = new List <int[]>();

            foreach (IJournalParameter journalParameter in countingTemplate.RecordTemplate.JournalParameters)
            {
                if (journalParameter.UshortsFormatter is ILoadable)
                {
                    await(journalParameter.UshortsFormatter as ILoadable).Load();
                }
            }
            for (int i = 0; i < oscillogramLoadingParameters.GetOscillogramCountingsNumber(); i++)
            {
                int[] countingArray = new int[countingTemplate.GetAllChannels()];

                ushort[] countingUshortsFromDevice = oscillogram.OscillogramResultUshorts
                                                     .Skip(oscillogramLoadingParameters.GetSizeOfCountingInWords() * i)
                                                     .Take(oscillogramLoadingParameters.GetSizeOfCountingInWords()).ToArray();

                int indexIfValueInCounting = 0;

                foreach (IJournalParameter journalParameter in countingTemplate.RecordTemplate.JournalParameters)
                {
                    List <IFormattedValue> formattedValues =
                        await journalRecordFactory.GetValuesForRecord(journalParameter, countingUshortsFromDevice,
                                                                      deviceContext);

                    foreach (IFormattedValue formattedValue in formattedValues)
                    {
                        if (formattedValue is INumericValue)
                        {
                            countingArray[indexIfValueInCounting++] =
                                (int)Math.Ceiling((formattedValue as INumericValue).NumValue * 1000);
                        }
                        if (formattedValue is IBitMaskValue)
                        {
                            foreach (bool bit in (formattedValue as IBitMaskValue).GetAllBits())
                            {
                                if (countingArray.Length == indexIfValueInCounting)
                                {
                                    break;
                                }
                                countingArray[indexIfValueInCounting++] = (short)(bit ? 1 : 0);
                            }
                        }
                    }
                }
                countingArraysToFile.Add(countingArray);
            }

            string hdrPath = Path.ChangeExtension(Path.Combine(directoryPath, oscillogramSignature), "hdr");

            using (StreamWriter hdrFile = new StreamWriter(hdrPath))
            {
                hdrFile.WriteLine(
                    $"{parentDeviceName} {oscillogramLoadingParameters.GetDateTime()}  ступень - {oscillogramLoadingParameters.GetAlarm()}");
                hdrFile.WriteLine("Size, ms = {0}", oscillogramLoadingParameters.GetOscillogramCountingsNumber());
                hdrFile.WriteLine(
                    $"Alarm = {oscillogramLoadingParameters.GetOscillogramCountingsNumber() - oscillogramLoadingParameters.GetSizeAfter()}");
            }
            //todo encoding oscillogram switched to utf-8 from 1251
            string cgfPath = Path.ChangeExtension(Path.Combine(directoryPath, oscillogramSignature), "cfg");

            using (StreamWriter cgfFile = new StreamWriter(cgfPath, false, Encoding.GetEncoding("UTF-8")))
            {
                cgfFile.WriteLine($"{parentDeviceName}");

                cgfFile.WriteLine(
                    $"{countingTemplate.GetAllChannels()},{countingTemplate.GetNumberOfAnalogs()}A,{countingTemplate.GetNumberOfDiscrets()}D");
                int           index       = 1;
                List <string> analogNames = countingTemplate.GetAnalogsNames();
                for (int i = 0; i < countingTemplate.GetNumberOfAnalogs(); i++)
                {
                    NumberFormatInfo format = new NumberFormatInfo {
                        NumberDecimalSeparator = "."
                    };

                    double factorA = 0.001;
                    cgfFile.WriteLine(
                        $"{index},{analogNames[i]},,,{countingTemplate.GetMeasureUnit(i)},{factorA.ToString(format)},0,0,{int.MinValue},{int.MaxValue}");
                    index++;
                }
                List <string> discretNames = countingTemplate.GetDiscretsNames();
                if (discretNames.Count < countingTemplate.GetNumberOfDiscrets())
                {
                    discretNames = new List <string>();
                    for (int i = 0; i < countingTemplate.GetNumberOfDiscrets(); i++)
                    {
                        discretNames.Add($"D {i + 1}");
                    }
                }
                for (int i = 0; i < countingTemplate.GetNumberOfDiscrets(); i++)
                {
                    cgfFile.WriteLine("{0},{1},0", i + 1, discretNames[i]);
                }
                cgfFile.WriteLine("50");
                cgfFile.WriteLine("1");
                cgfFile.WriteLine("1000,{0}", oscillogramLoadingParameters.GetOscillogramCountingsNumber());

                cgfFile.WriteLine(oscillogramLoadingParameters.GetDateTime());
                cgfFile.WriteLine(oscillogramLoadingParameters.GetDataTimeofAlarm());
                cgfFile.WriteLine("1251");
            }

            string datPath = Path.ChangeExtension(Path.Combine(directoryPath, oscillogramSignature), "dat");

            using (StreamWriter datFile = new StreamWriter(datPath))
            {
                for (int i = 0; i < oscillogramLoadingParameters.GetOscillogramCountingsNumber(); i++)
                {
                    datFile.Write("{0:D6},{1:D6}", i, i * 1000);

                    foreach (int value in countingArraysToFile[i])
                    {
                        datFile.Write(",{0}", value);
                    }
                    datFile.WriteLine();
                }
            }
        }
Esempio n. 3
0
 public OscilloscopeModel(IUniconJournal uniconJournal,
                          ICountingTemplate countingTemplate)
 {
     this.OscilloscopeJournal = uniconJournal;
     this.CountingTemplate    = countingTemplate;
 }