コード例 #1
0
ファイル: RecordDataFile.cs プロジェクト: ywwjzsf/CANStream
        /// <summary>
        /// Add a data sample to a specific channel.
        /// </summary>
        /// <remarks>
        /// If the channel given in argument doesn't exist, it will be created
        /// </remarks>
        /// <param name="ChannelName">Destination channel name of the sample</param>
        /// <param name="TimeStamp">Time stamp value of the sample</param>
        /// <param name="DataValue">Engineering value of the sample</param>
        private void AddDataSample(string ChannelName, double TimeStamp, double DataValue)
        {
            bool bNewChannel           = false;
            RecordDataChannel oChannel = GetRecordDataChannel(ChannelName);

            if (oChannel == null)          //The channel doesn't exist yet, we create it
            {
                bNewChannel = true;

                oChannel      = new RecordDataChannel();
                oChannel.Name = ChannelName;
            }

            //Create the new sample
            RecordDataSample oSample = new RecordDataSample();

            oSample.TimeStamp   = TimeStamp;
            oSample.SampleValue = DataValue;

            //Add the new sample to the sample collection of channel
            oChannel.Samples.Add(oSample);

            //Update the channel min & max sampletime
            if (oChannel.Samples.Count > 1)          //Need 2 samples at least, to compute sample time
            {
                int    iSample    = oChannel.Samples.Count - 1;
                double SampleTime = oChannel.Samples[iSample].TimeStamp - oChannel.Samples[iSample - 1].TimeStamp;

                if (oChannel.Samples.Count == 2)              //First sample time calculation
                {
                    oChannel.MinSampleTime = SampleTime;
                    oChannel.MaxSampleTime = SampleTime;
                }
                else
                {
                    if (SampleTime < oChannel.MinSampleTime)
                    {
                        oChannel.MinSampleTime = SampleTime;
                    }

                    if (SampleTime > oChannel.MaxSampleTime)
                    {
                        oChannel.MaxSampleTime = SampleTime;
                    }
                }
            }

            if (bNewChannel)            //Add the channel to the collection if we just created it
            {
                Channels.Add(oChannel);
            }
        }
コード例 #2
0
ファイル: RecordDataFile.cs プロジェクト: ywwjzsf/CANStream
        /// <summary>
        /// Read a Record data file in ascii format
        /// </summary>
        /// <param name="FilePath">Path of the record data file</param>
        /// <returns>return false if an error occurs</returns>
        public bool ReadRecordDataFile(string FilePath)
        {
            if (!(File.Exists(FilePath)))
            {
                return(false);
            }

            StreamReader SR    = new StreamReader(FilePath);
            int          iLine = 0;

            Channels = new List <RecordDataChannel>();

            while (!(SR.EndOfStream))
            {
                string   sLine   = SR.ReadLine();
                string[] LineVal = sLine.Split(Char.Parse(";"));

                if (iLine == 0)
                {
                    for (int i = 0; i < LineVal.Length; i++)
                    {
                        if (!(i == 0))                      //First column is time
                        {
                            RecordDataChannel oChan = new RecordDataChannel();
                            oChan.Name = LineVal[i];
                            Channels.Add(oChan);
                        }
                    }
                }
                else
                {
                    double TimeStamp = 0;

                    for (int i = 0; i < LineVal.Length; i++)
                    {
                        double Value = 0;

                        if (Double.TryParse(LineVal[i], out Value))
                        {
                            if (i == 0)                          //Get timestamp value
                            {
                                TimeStamp = Value;
                            }
                            else                             //Get sample value
                            {
                                RecordDataSample oSample = new RecordDataSample();

                                oSample.TimeStamp   = TimeStamp;
                                oSample.SampleValue = Value;

                                Channels[i].Samples.Add(oSample);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }

            SR.Close();
            SR = null;

            return(true);
        }