Beispiel #1
0
        private FamosFileChannel PrepareChannel(FamosFileField field, ChannelDescription channelDescription, int totalLength, DateTime startDateTme, double dx)
        {
            // component
            var datasetName = $"{channelDescription.ChannelName}_{channelDescription.DatasetName.Replace(" ", "_")}";
            var calibration = new FamosFileCalibration(false, 1, 0, false, channelDescription.Unit);

            var component = new FamosFileAnalogComponent(datasetName, FamosFileDataType.Float64, totalLength, calibration)
            {
                XAxisScaling = new FamosFileXAxisScaling((decimal)dx)
                {
                    Unit = "s"
                },
                TriggerTime = new FamosFileTriggerTime(startDateTme, FamosFileTimeMode.Unknown),
            };

            // attributes
            var channel = component.Channels.First();

            channel.PropertyInfo = new FamosFilePropertyInfo(new List <FamosFileProperty>()
            {
                new FamosFileProperty("name", channelDescription.ChannelName),
                new FamosFileProperty("group", channelDescription.Group),
                new FamosFileProperty("comment", "yyyy-MM-ddTHH-mm-ssZ: Comment1"),
            });

            field.Components.Add(component);

            return(channel);
        }
Beispiel #2
0
        public static void PrepareHeader(FamosFileHeader famosFile)
        {
            var encoding = Encoding.GetEncoding(1252);

            // add language info
            famosFile.LanguageInfo = new FamosFileLanguageInfo()
            {
                CodePage = encoding.CodePage
            };

            // add data origin info
            famosFile.OriginInfo = new FamosFileOriginInfo("ImcFamosFile", FamosFileOrigin.Calculated);

            // add custom key
            var customKey = new FamosFileCustomKey("FileID", encoding.GetBytes(Guid.NewGuid().ToString()));

            famosFile.CustomKeys.Add(customKey);

            // data fields
            var length = 25; /* number of samples per channel or component, respectively. */

            /* data field with equidistant time */
            var calibrationInfo1 = new FamosFileCalibration()
            {
                ApplyTransformation = true,
                Factor = 10,
                Offset = 7,
                Unit   = "°C"
            };

            famosFile.Fields.Add(new FamosFileField(FamosFileFieldType.MultipleYToSingleEquidistantTime, new List <FamosFileComponent>()
            {
                /* generator data */
                new FamosFileAnalogComponent("GEN_TEMP_1", FamosFileDataType.Float32, length, calibrationInfo1),
                new FamosFileAnalogComponent("GEN_TEMP_2", FamosFileDataType.Float32, length, calibrationInfo1),
                new FamosFileAnalogComponent("GEN_TEMP_3", FamosFileDataType.Int32, length, calibrationInfo1),

                new FamosFileAnalogComponent("GEN_TEMP_4", FamosFileDataType.Float32, length, calibrationInfo1),

                /* no group */
                new FamosFileAnalogComponent("ENV_TEMP_1", FamosFileDataType.Int16, length, calibrationInfo1)
            })
            {
                TriggerTime  = new FamosFileTriggerTime(DateTime.Now, FamosFileTimeMode.Normal),
                XAxisScaling = new FamosFileXAxisScaling(deltaX: 0.01M)
                {
                    X0 = 985.0M, Unit = "Seconds"
                }
            });

            famosFile.Fields[0].Components[0].Channels[0].PropertyInfo = new FamosFilePropertyInfo(new List <FamosFileProperty>()
            {
                new FamosFileProperty("Sensor Location", "Below generator.")
            });

            /* data field with monotonous increasing time */
            famosFile.Fields.Add(new FamosFileField(FamosFileFieldType.MultipleYToSingleMonotonousTime, new List <FamosFileComponent>()
            {
                /* hydraulic data */
                new FamosFileAnalogComponent("HYD_TEMP_1", FamosFileDataType.Float32, length, calibrationInfo1),
                new FamosFileAnalogComponent("HYD_TEMP_2", FamosFileDataType.Float32, length, calibrationInfo1),

                /* time-axis */
                new FamosFileAnalogComponent(FamosFileDataType.UInt32, length, FamosFileComponentType.Secondary),
            })
            {
                XAxisScaling = new FamosFileXAxisScaling(deltaX: 100M)
                {
                    X0   = 0M,
                    Unit = "Milliseconds"
                }
            });

            /* data field for characteristic curves */
            var calibrationInfo2 = new FamosFileCalibration()
            {
                Unit = "kW"
            };
            var calibrationInfo3 = new FamosFileCalibration()
            {
                Unit = "-"
            };
            var calibrationInfo4 = new FamosFileCalibration()
            {
                Unit = "m/s"
            };

            famosFile.Fields.Add(new FamosFileField(FamosFileFieldType.MultipleYToSingleXOrViceVersa, new List <FamosFileComponent>()
            {
                /* power */
                new FamosFileAnalogComponent("POWER", FamosFileDataType.Float64, length, calibrationInfo2),

                /* power coefficient */
                new FamosFileAnalogComponent("POWER_COEFF", FamosFileDataType.Float64, length, calibrationInfo3),

                /* wind speed */
                new FamosFileAnalogComponent(FamosFileDataType.Float64, length, FamosFileComponentType.Secondary, calibrationInfo4),
            }));

            /* data field with complex values */
            var calibrationInfo5 = new FamosFileCalibration()
            {
                Unit = "A"
            };

            famosFile.Fields.Add(new FamosFileField(FamosFileFieldType.ComplexRealImaginary, new List <FamosFileComponent>()
            {
                /* converter data (real part) */
                new FamosFileAnalogComponent("CONV_CURRENT_L1", FamosFileDataType.Float32, length, FamosFileComponentType.Primary, calibrationInfo5),

                /* converter data (imaginary part) */
                new FamosFileAnalogComponent(FamosFileDataType.Float32, length, FamosFileComponentType.Secondary, calibrationInfo5),
            })
            {
                XAxisScaling = new FamosFileXAxisScaling(deltaX: 1 / 25000M)
                {
                    X0   = 0M,
                    Unit = "Seconds"
                },
                ZAxisScaling = new FamosFileZAxisScaling(deltaZ: 5M)
                {
                    Z0          = 0M,
                    SegmentSize = 2,
                    Unit        = "Meters"
                }
            });

            // add events to data field (not supported yet)

            //field1.EventInfos.Add(new FamosFileEventInfo(new List<FamosFileEvent>()
            //{
            //    new FamosFileEvent()
            //    {
            //        AmplificationFactor0 = 0, AmplificationFactor1 = 1,
            //        AmplitudeOffset0 = 2, AmplitudeOffset1 = 3,
            //        deltaX = 4,
            //        Index = 1,
            //        Length = 6,
            //        Offset = 7,
            //        Time = 8,
            //        x0 = 9
            //    },
            //    new FamosFileEvent()
            //    {
            //        AmplificationFactor0 = 10, AmplificationFactor1 = 11,
            //        AmplitudeOffset0 = 12, AmplitudeOffset1 = 13,
            //        deltaX = 14,
            //        Index = 2,
            //        Length = 16,
            //        Offset = 17,
            //        Time = 18,
            //        x0 = 19
            //    }
            //}));

            // property info (for hydraulic group)
            var propertyInfo2 = new FamosFilePropertyInfo(new List <FamosFileProperty>()
            {
                new FamosFileProperty("Weight", 3752.23),
                new FamosFileProperty("Start-up date", new DateTime(2019, 12, 06, 11, 41, 30, 210))
            });

            // define groups
            famosFile.Groups.AddRange(new List <FamosFileGroup>()
            {
                /* generator */
                new FamosFileGroup("Generator")
                {
                    Comment = "This group contains channels related to the generator."
                },

                /* hydraulic */
                new FamosFileGroup("Hydraulic")
                {
                    Comment      = "This group contains channels related to the hydraulic unit.",
                    PropertyInfo = propertyInfo2
                },

                /* power curve */
                new FamosFileGroup("Power curve"),

                /* converter */
                new FamosFileGroup("Converter")
                {
                    Comment = "This group contains channels related to the converter."
                }
            });

            // get group references
            var generatorGroup  = famosFile.Groups[0];
            var hydraulicGroup  = famosFile.Groups[1];
            var powerCurveGroup = famosFile.Groups[2];
            var converterGroup  = famosFile.Groups[3];

            // add elements to the generator group
            generatorGroup.SingleValues.Add(new FamosFileSingleValue <double>("GEN_TEMP_1_AVG", 40.25)
            {
                Comment = "Generator temperature 1.",
                Unit    = "°C",
                Time    = DateTime.Now,
            });

            generatorGroup.Texts.Add(new FamosFileText("Description", "In electricity generation, a generator is a device that converts motive power (mechanical energy) into electrical power for use in an external circuit. Sources of mechanical energy include steam turbines, gas turbines, water turbines, internal combustion engines, wind turbines and even hand cranks. - Wikipedia (2019)")
            {
                Comment      = "Maybe its useful.",
                PropertyInfo = new FamosFilePropertyInfo(new List <FamosFileProperty>()
                {
                    new FamosFileProperty("Length", 318)
                })
            });

            generatorGroup.Channels.AddRange(famosFile.Fields[0].GetChannels().Take(4));

            // add elements to the hydraulic group
            hydraulicGroup.Channels.AddRange(famosFile.Fields[1].GetChannels());

            // add elements to the power curve group
            powerCurveGroup.Texts.Add(new FamosFileText("Type", "E-126"));
            powerCurveGroup.Texts.Add(new FamosFileText("Source", "Enercon Product Sheet (2015)"));

            powerCurveGroup.Channels.AddRange(famosFile.Fields[2].GetChannels());

            // add elements to the converter group
            converterGroup.Channels.AddRange(famosFile.Fields[3].GetChannels());

            // add other elements to top level (no group)
            famosFile.Texts.Add(new FamosFileText("Random list of texts.", new List <string>()
            {
                "Text 1.", "Text 2?", "Text 3!"
            }));
            famosFile.Channels.Add(famosFile.Fields[0].GetChannels().Last());
        }